em#
Functions
|
Parse condensed EM notation into a planar diagram. |
|
Create a planar diagram from EM dict (or stringified dict) notation. |
|
Return condensed EM notation for diagrams with single-letter node labels. |
Return EM dict notation of a planar diagram. |
- to_em_notation(g)#
Return EM dict notation of a planar diagram.
For each node, returns a CCW-ordered list of
(neighbor, neighbor_pos)
tuples. This uses the diagram’s endpoint “twin” relation to find the adjacent endpoint.- Parameters:
g (PlanarDiagram) – Planar diagram.
- Returns:
dict – Mapping
node -> [(neighbor, neighbor_pos), ...]
.- Return type:
Dict[Any, list[tuple[Any, int]]]
Examples
>>> from knotpy.classes.planardiagram import PlanarDiagram >>> d = PlanarDiagram() >>> d.add_vertices_from(["a", "b"]) >>> d.set_arc((("a", 0), ("b", 0))) >>> em = to_em_notation(d) >>> em["a"] == [("b", 0)] True
- from_em_notation(data, oriented=False)#
Create a planar diagram from EM dict (or stringified dict) notation.
The input should map each node to a CCW-ordered list of
(neighbor, neighbor_position)
pairs.- Parameters:
data (Mapping[Any, Iterable[tuple[Any, int]]] | str) – EM dict, or a string that safely evaluates to such a dict.
oriented (bool) – Whether to construct an oriented diagram (not implemented).
- Returns:
PlanarDiagram – Parsed diagram.
- Raises:
NotImplementedError – If
oriented=True
.ValueError – On malformed inputs.
- Return type:
- to_condensed_em_notation(g, separator=',')#
Return condensed EM notation for diagrams with single-letter node labels.
- Constraints:
Nodes must be sortable and of the same type (e.g., all strings or all ints).
At most 52 nodes (a–zA–Z).
- Parameters:
g (PlanarDiagram) – Diagram to serialize.
separator (str) – Token separator (default: comma).
- Returns:
str – Condensed EM string (alphabetical node order).
- Raises:
ValueError – If node count exceeds 52.
TypeError – If nodes are not mutually comparable for sorting.
- Return type:
str
- from_condensed_em_notation(data, separator=',', oriented=False)#
Parse condensed EM notation into a planar diagram.
Token format per node (CCW):
<neighbor-letter><neighbor-position>...
. Nodes are assigned in alphabetical order: a, b, c, …- Parameters:
data (str) – Condensed EM string.
separator (str) – Token separator used in the string (default: comma).
oriented (bool) – Whether to construct an oriented diagram (not implemented).
- Returns:
PlanarDiagram – Parsed diagram.
- Raises:
NotImplementedError – If
oriented=True
.ValueError – For malformed tokens.
- Return type: