Syntax

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 for ParseTree 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 <https://github.com/Qiskit/rustworkx> _ PyDiGraph which contains the syntactice structure of a sentence

Type:

PyDiGraph[MGNode, MGEdge]

base_string() list[str | Mover | Trace]

Get a richer representation of the parsed string.

This representation has traces where movement had occurred, and python_mg.Mover() objects to indicated moved phrases.

Returns:

the parsed sentence

Return type:

list[str | Mover | trace]

normal_string() str

Get the string used by a ParseTree.

Returns:

the parsed sentence

Return type:

str

to_dot() str | None

Convert a tree to GraphViz DOT format.

Returns:

The dot file for this tree

Return type:

str

to_image() Image

Convert 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().

s: list[str | Mover | Trace]

The moved words

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

A node on a tree.

is_stolen()

Checks if the node is a head that has been stolen by head-movement.

Returns:

True if the node is a stolen head, False otherwise.

Return type:

bool

is_trace()

Whether the node is a trace or not.

Returns:

True if 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

class python_mg.syntax.MGEdge

A node representing the edge in a tree, whether in merging or movement.

is_head_move()

Check if the edge is a head-movement edge.

Returns:

Whether it’s a head-movement edge.

Return type:

bool

is_merge()

Check if the edge is a merge edge.

Returns:

Whether it’s a merge edge.

Return type:

bool

is_move()

Check if the edge is a movement edge.

Returns:

Whether it’s a movement edge.

Return type:

bool