Syntax tree utilities
These are the classes that are useful for manipulating or plotting parse trees directly.
- class python_mg.syntax.ParseTree(G: PyDiGraph[MGNode, MGEdge], root: int, structure: SyntacticStructure)
A class used for ParseTree that is generated by
python_mg.SyntacticStructure.to_tree(). It can be used to get a GraphViz representation of the tree or to investigate the ParseTree as a graph.- G: PyDiGraph[MGNode, MGEdge]
A RustworkX PyDiGraph which contains the syntactice structure of a sentence
- base_string() list[str | Mover | Trace]
A richer representation of the parsed string, with traces where movement had occurred, and
python_mg.Mover()objects to indicated moved phrases.- Returns:
the parsed sentence
- Return type:
str
- normal_string() str
The string used by a ParseTree
- Returns:
the parsed sentence
- Return type:
str
- to_dot() str | None
Converts a tree to GraphViz DOT format
- Returns:
The dot file for this tree
- Return type:
str
- to_image() Image
Converts a tree to a PIL Image
- Returns:
An image representation of the tree
- Return type:
Image
- class python_mg.syntax.Mover(s: list[str | Mover | Trace], trace: int)
A list of words used to indicate where movement has occurred. See
python_mg.ParseTree.base_string()- trace: int
the trace ID
- class python_mg.syntax.Trace(trace: int)
A representation of a trace index left by movement
- trace: int
the trace ID
- class python_mg.syntax.MGNode
- is_stolen()
Checks if the node is a head that has been stolen by head-movement.
- Returns:
Trueif the node is a stolen head,Falseotherwise.- Return type:
bool
- is_trace()
Whether the node is a trace or not.
- Returns:
Trueif the node is a trace.- Return type:
bool
- lemma_string()
Get the lemma string of a node, will be
"Ɛ"if the lemma is empty and""if the node does not have a lemma.- Returns:
the string of the lemma of this node.
- Return type:
str
- trace_id()
Get the trace ID of a trace, if it is one. Otherwise raise a ValueError
- Returns:
trace ID
- Return type:
int