concepts.language.ccg.grammar.CCGNode#
- class CCGNode[source]#
Bases:
object
A node in the CCG parsing tree.
Methods
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 the node as a nltk tree.
Linearize the lexicons of the node.
Print the node as a nltk tree.
Attributes
The composition system.
The syntax type of the node.
The semantics of the node.
The composition type of the node.
The lexicon (if the composition type is LEXICON).
The left child of the node (for other types of composition).
The right child of the node (for other types of composition).
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)#
- 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:
- 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:
rhs (CCGNode) – the right node.
composition_type (CCGCompositionType) – the composition type.
- 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
- linearize_lexicons()[source]#
Linearize the lexicons of the node. It return a list of lexicons corresponding to the leaves of parsing tree.
- composition_system: CCGCompositionSystem#
The composition system.
- composition_type: CCGCompositionType#
The composition type of the node.
- semantics: CCGSemantics | None#
The semantics of the node.
- syntax: CCGSyntaxType | None#
The syntax type of the node.