segram.grammar.graph module
- class segram.grammar.graph.Graph(data: Mapping[Any, tuple[Any, ...]])[source]
Bases:
MutableMapping,SegramABCGraph object.
This class provides concrete generic implementations of all methods except for __getitem__, __setitem__, __delitem__, __iter__, and __len__.
This is a mutable mapping with several additional methods
for reversing the key-value pairing or testing whether a graph is a directed acyclic graph (DAG).
- property data: dict[Any, tuple[Any, ...]]
Dictionary mapping names and values for main slots.
- toposort(*, reversed: bool = False) TopologicalSorter[source]
Get topological sorter.
- Parameters:
reversed – Should reversed topological sorter be returned.
- class segram.grammar.graph.PhraseGraph(data: Mapping[Any, tuple[Any, ...]])[source]
Bases:
GraphPhraseGraph.
This class provides concrete generic implementations of all methods except for __getitem__, __setitem__, __delitem__, __iter__, and __len__.
This is a mutable mapping with several additional methods
for reversing the key-value pairing or testing whether a graph is a directed acyclic graph (DAG).
- classmethod from_data(sent: Span, data: dict[int, tuple[int, int]]) Self[source]
Construct from data dictionary.
- Parameters:
sent – Sentence object.
data – Data dictionary.
cdict – Mapping from ordinal numbers to nodes.
- to_data() dict[int, tuple[int, int]][source]
Dump to data dictionary.
- Parameters:
odict – Mapping from nodes to their ordinal numbers within the node sequence.
- Returns:
Mapping from node ordinal numbers of nodes to lists of t riples with two integers giving the index of the target node, index of subordinating conjunction token and the name of a dependency symbol.
- Return type:
data