concepts.language.neural_ccg.grammar.NeuralCCGNode#

class NeuralCCGNode[source]#

Bases: CCGNode

A node in the Neural CCG parsing tree.

Methods

as_nltk_str()

Convert the node to a string in nltk format.

compose(rhs[, composition_type])

Compose the current node with another node.

compose_check(rhs, composition_type)

Check if the current node can be composed with another node.

compose_guess(rhs)

Guess the composition type of the current node with another node.

format_nltk_tree()

Format the node as a nltk tree.

linearize_lexicons()

Linearize the lexicons of the node.

print_nltk_tree()

Print the node as a nltk tree.

set_used_lexicon_entries(used_lexicon_entries)

Set the used lexicon entries.

Attributes

execution_result

The execution result of the node.

is_none

Whether the node is a None node.

used_lexicon_entries

A set of lexicon entries used in the derivation.

composition_system

The composition system.

syntax

The syntax type of the node.

semantics

The semantics of the node.

composition_type

The composition type of the node.

lexicon

The lexicon (if the composition type is LEXICON).

lhs

The left child of the node (for other types of composition).

rhs

The right child of the node (for other types of composition).

weight

The weight of the node.

composition_str

A string representation of the composition inside the tree.

__init__(composition_system, syntax, semantics, composition_type, lexicon=None, lhs=None, rhs=None, weight=None, composition_str=None)[source]#

Initialize a CCG node.

Parameters:
  • composition_system (CCGCompositionSystem) – the composition system.

  • syntax (NeuralCCGSyntaxType) – the syntax of the node.

  • semantics (NeuralCCGSemantics) – the semantics of the node.

  • composition_type (CCGCompositionType) – the composition type of the node.

  • lexicon (Lexicon | None) – the lexicon of the node (only if the composition type is LEXICON).

  • lhs (NeuralCCGNode | None) – the left child of the node (when available).

  • rhs (NeuralCCGNode | None) – the right child of the node (when available).

  • weight (float | Tensor | None) – the weight of the node.

  • composition_str (str) – a string representation of the composition, which can be used to remove duplicated trees.

__new__(**kwargs)#
as_nltk_str()#

Convert the node to a string in nltk format.

Return type:

str

compose(rhs, composition_type=None)#

Compose the current node with another node. This function will automatically guess the composition type.

Parameters:
  • rhs (CCGNode) – the right node.

  • composition_type (CCGCompositionType | None) – the composition type. If not given, it will be guessed automatically.

Returns:

The composition result. When the composition type is not given, it will be a CCGCompositionResult object.

Return type:

CCGCompositionResult | CCGNode

compose_check(rhs, composition_type)[source]#

Check if the current node can be composed with another node. If the check fails, a CCGCompositionError will be raised.

Parameters:
Raises:

CCGCompositionError – if the check fails.

compose_guess(rhs)[source]#

Guess the composition type of the current node with another node.

Parameters:

rhs (NeuralCCGNode) – the right node.

Returns:

The guessed composition type. If None, all composition types are allowed.

Return type:

Tuple[CCGCompositionType]

format_nltk_tree()#

Format the node as a nltk tree.

Return type:

str

linearize_lexicons()#

Linearize the lexicons of the node. It return a list of lexicons corresponding to the leaves of parsing tree.

Returns:

The list of lexicons.

Return type:

List[Lexicon]

print_nltk_tree()#

Print the node as a nltk tree.

set_used_lexicon_entries(used_lexicon_entries)[source]#

Set the used lexicon entries.

Parameters:

used_lexicon_entries (Dict[str, Set[Lexicon]])

composition_str: str#

A string representation of the composition inside the tree.

composition_system: CCGCompositionSystem#

The composition system.

composition_type: CCGCompositionType#

The composition type of the node.

property execution_result#

The execution result of the node.

property is_none#

Whether the node is a None node.

lexicon: Lexicon | None#

The lexicon (if the composition type is LEXICON).

lhs: NeuralCCGNode | None#

The left child of the node (for other types of composition).

rhs: NeuralCCGNode | None#

The right child of the node (for other types of composition).

semantics: NeuralCCGSemantics | None#

The semantics of the node.

syntax: NeuralCCGSyntaxType | None#

The syntax type of the node.

property used_lexicon_entries: Dict[str, Set[Lexicon]]#

A set of lexicon entries used in the derivation.

weight: float | Tensor#

The weight of the node.