to_plantri_notation#

to_plantri_notation(g)#

Convert a planar diagram to plantri notation (alphabetical form).

Plantri’s alphabetical notation lists each node’s neighbors in CW order. Our diagrams store endpoints CCW, so we iterate the diagram’s stored order directly and rely on the fact that the notation consumer understands CW. (If your internal storage differs, you may need to reverse per node.)

The output looks like: "5 bcde,aedc,abd,acbe,adb" (node count + space + CSV).

Parameters:

g (PlanarDiagram) – Planar diagram to serialize.

Returns:

str – Plantri alphabetical notation.

Raises:

ValueError – If the diagram has more than 52 nodes (a–zA–Z).

Return type:

str

Examples

>>> from knotpy.classes.planardiagram import PlanarDiagram
>>> d = PlanarDiagram()
>>> d.add_vertices_from(["a", "b", "c"])
>>> d.set_arc((("a", 0), ("b", 0)))
>>> d.set_arc((("b", 1), ("c", 0)))
>>> to_plantri_notation(d).split()[0].isdigit()
True