concepts.language.ccg.grammar.CCGNode#

class CCGNode[source]#

Bases: object

A node in the 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.

Attributes

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.

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

Construct a CCG node.

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

  • syntax (CCGSyntaxType | None) – the syntax type.

  • semantics (CCGSemantics | None) – the semantics.

  • composition_type (CCGCompositionType) – the composition type.

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

  • lhs (CCGNode | None) – the left child of the node (for other types of composition).

  • rhs (CCGNode | None) – the right child of the node (for other types of composition).

  • weight (float | None) – the weight. If not given, it will be computed automatically (lhs + rhs + composition weight).

__new__(**kwargs)#
as_nltk_str()[source]#

Convert the node to a string in nltk format.

Return type:

str

compose(rhs, composition_type=None)[source]#

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 (CCGNode) – the right node.

Returns:

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

Return type:

Tuple[CCGCompositionType] | None

format_nltk_tree()[source]#

Format the node as a nltk tree.

Return type:

str

linearize_lexicons()[source]#

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()[source]#

Print the node as a nltk tree.

composition_system: CCGCompositionSystem#

The composition system.

composition_type: CCGCompositionType#

The composition type of the node.

lexicon: Lexicon | None#

The lexicon (if the composition type is LEXICON).

lhs: CCGNode | None#

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

rhs: CCGNode | None#

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

semantics: CCGSemantics | None#

The semantics of the node.

syntax: CCGSyntaxType | None#

The syntax type of the node.

weight: float#

The weight of the node.