node module

class py_amr2fred.node.Node(var: str, relation: str, status: NodeStatus = NodeStatus.AMR, visibility=True)

Bases: object

Represents a node in a directed graph structure, used for hierarchical and semantic representations.

Parameters:
  • var – The variable name (identifier) of the node.

  • relation – The relation that links this node to its parent (default is an empty string).

  • status – The status of the node, defaulting to Glossary.NodeStatus.AMR.

  • visibility – Whether the node is visible in the graphic representation of the graph (default is True).

Each node encapsulates a unique identifier (var), a relation (relation) connecting it to its parent, a list of child nodes (node_list), and additional metadata such as visibility, type, and status.

Nodes can form tree-like structures where each node may have multiple child nodes. The status attribute represents the current processing state of the node, while node_type helps classify the node within the graph.

Attributes:
  • unique_id (int): A class-level counter for uniquely identifying nodes.

  • level (int): Represents the depth of the node in the graph hierarchy.

  • endless (int): A flag used to track circular references or recursive processing.

  • endless2 (int): Additional flag for handling cyclic structures.

Instance Attributes:
  • var (str): The variable name (identifier) of the node.

  • relation (str): The relation linking this node to its parent.

  • label (str): A human-readable label for the node.

  • node_list (list[Node]): A list of child nodes connected to this node.

  • parent (Node | None): The parent node in the hierarchy (if any).

  • parent_list (list[Node]): A list of all parent nodes (for non-tree structures).

  • visibility (bool): Whether the node is visible in the graphical representation.

  • prefix (bool): Determines whether the node has a prefix in its identifier.

  • status (Glossary.NodeStatus): The current processing status of the node.

  • node_type (Glossary.NodeType): The type classification of the node.

  • __node_id (int): A unique identifier assigned to each node instance.

  • verb (str): The main verb or identifier associated with the node.

  • malformed (bool): Indicates if the node contains malformed or inconsistent data.

add(node)

Adds a node to the node list and sets its parent to the current node.

This method appends the given node to the node_list and sets the current node as the parent of the given node.

Parameters:

node (Node) – The node to be added.

add_all(node_list)

Adds a list of nodes to the current node.

This method appends all nodes from the given node_list to the node_list of the current node and sets the current node as their parent.

Parameters:

node_list (list[Node]) – A list of nodes to add.

get_args()

Retrieves all argument nodes from the node list.

This method searches through the node_list for nodes whose relation matches the Glossary.AMR_ARG pattern and returns them as a list.

Return type:

list[Node]

Returns:

A list of argument nodes.

get_child(relation: str)

Retrieves a child node with a specific relation from the node list.

This method searches the node_list for a node whose relation matches the given string relation. If found, it returns the node, otherwise, it returns None.

Parameters:

relation (str) – The relation to search for in the node list.

Return type:

Node

Returns:

The node with the matching relation or None if no such node is found.

get_children(relation)

Retrieves all child nodes with a specific relation.

This method searches through the node_list and returns all nodes whose relation matches the given relation.

Parameters:

relation (str) – The relation to search for in the node list.

Return type:

list[Node]

Returns:

A list of child nodes with the given relation.

get_copy(node=None, relation=None, parser_nodes_copy=None)

Creates and returns a copy of the current node, or a copy of the provided node, based on the specified parameters.

If no node is provided, a copy of the current node is created. If a specific node is provided, it will create a new node with the specified relation, or copy the provided node’s properties and children. If parser_nodes_copy is provided, the new node is appended to this list.

Parameters:
  • node – The node to copy, if specified. If not provided, the current node is copied.

  • relation – The relation for the new node if specified. If not provided, the current relation is used.

  • parser_nodes_copy – A list of nodes to which the new node is added if specified.

Returns:

A new Node that is a copy of the current node or the provided node, based on the given parameters.

Return type:

Node

get_instance()

Retrieves the node representing an instance from the node list.

This method searches through the node_list for a node with a relation matching the Glossary.INSTANCE value. If found, it returns the node, otherwise, it returns None.

Return type:

Node

Returns:

The node representing an instance or None if no such node is found.

get_inverse()

Retrieves a node with an inverse relation from the node list.

This method searches the node_list for a node whose relation matches the Glossary.AMR_INVERSE pattern, excluding certain relations. If such a node is found, it is returned; otherwise, None is returned.

Return type:

Node

Returns:

A node with an inverse relation or None if no such node is found.

get_inverses(nodes=None, visited=None)

Retrieves all nodes with inverse relations from the node list.

This method searches through the node_list for nodes whose relations match the Glossary.AMR_INVERSE pattern, excluding certain relations. The nodes are returned as a list. If the nodes parameter is provided, the method recursively adds inverse nodes to the given list.

Parameters:
  • visited – The list of the visited nodes

  • nodes (list[Node], optional) – A list to accumulate inverse nodes (optional).

Return type:

list[Node]

Returns:

A list of nodes with inverse relations.

get_node_id() int

Retrieves the node’s ID.

This method returns the unique identifier of the node.

Return type:

int

Returns:

The node’s ID.

get_nodes_with_parent_list_not_empty() list

Retrieves nodes that have a non-empty parent list.

This method searches through the node_list and returns all nodes whose parent_list is not empty.

Return type:

list[Node]

Returns:

A list of nodes with a non-empty parent list.

get_ops()

Retrieves all ‘operator’ nodes from the node list.

This method searches through the node_list for nodes whose relation matches the Glossary.AMR_OP pattern and returns them as a list.

Return type:

list[Node]

Returns:

A list of ‘operator’ nodes.

get_poss()

Retrieves the ‘possession’ node from the node list.

This method searches through the node_list for a node whose relation matches the Glossary.AMR_POSS pattern. If found, the node is returned.

Return type:

Node

Returns:

The ‘possession’ node or None if not found.

get_snt()

Retrieves all nodes related to sentences from the node list.

This method searches through the node_list for nodes whose relation matches the Glossary.AMR_SENTENCE pattern and returns them as a list. The method recursively collects sentence nodes from all child nodes.

Return type:

list[Node]

Returns:

A list of nodes related to sentences.

get_tree_status()

Retrieves the status of the entire node tree.

This method calculates the cumulative status value of the node tree, starting from the current node and recursively including all child nodes.

Return type:

int

Returns:

The cumulative status value of the node tree.

make_equals(node=None, node_id=None)

Sets the __node_id to be equal to that of the given node or node_id.

This method sets the __node_id of the current object to either the __node_id of the provided node or the given node_id. Only one of the parameters can be specified.

Parameters:
  • node (Node, optional) – The node whose __node_id to copy.

  • node_id (int, optional) – The __node_id value to set.

set_status(status: NodeStatus)

Sets the status of the node.

This method sets the status of the current node to the specified status.

Parameters:

status (Glossary.NodeStatus) – The status to set for the node.

substitute(node)

Substitutes the current node with another node.

This method copies the properties of the given node to the current node, including its var, relation, __node_id, and node_list. The parent and other attributes are also updated accordingly.

Parameters:

node (Node) – The node to substitute.