concepts.language.neural_ccg.grammar.NeuralCCGSyntaxType#

class NeuralCCGSyntaxType[source]#

Bases: CCGComposable

Data structure for neural CCG syntax types. NeuralCCGSyntaxType implements a different version of the syntax type than the CCGSyntaxType.

Specifically, the NeuralCCGSyntaxType define syntaxes based on the signature of its meaning. It has two parts:

  1. the signature of the semantic form, including the argument types and the return type.

  2. the linearization of the semantics.

IMPORTANT: Arguments are combined from right to left. Thus, argument_types[-1] is the first argument. There is one possible confusion about linearization:

Although LinearizationTuple has two fields: index and direction, only type will be used during computation. LinearizationTuple.index is used to record the mapping from the original “function” definition, most likely produced by iter_from_function.

Example: Suppose we have a function definition def func(string, int) -> string. Running iter_from_function(func) will get you six possible syntax types:

string/0:string/1:int, string0:string/1:int, string0:string1:int, string/1:int/0:string, string1:int/0:string, string1:int0:string

Consider a specifc type string0:int/1:string. It has the following fields:

  • return_type: string

  • argument_types: [int, string]

  • linearization: [LinearizationTuple(0, CCGCompositionDirection.LEFT), LinearizationTuple(1, CCGCompositionDirection.RIGHT)]

Here, the first argument should come from fapp, of type string. The second argument should come from bapp, of type int. The linearization[i].index is never used in the computation. However, it does record the argument order mapping from the original “func(string, int) -> string”.

See also NeuralCCGSyntaxType.iter_from_function().

See also concepts.language.neural_ccg.search.NeuralCCGLexiconSearcher.gen_lexicons().

Methods

bapp(lhs)

Backward application composition.

compose(rhs, composition_type)

Compose this element with another element.

coord(other)

Coordination composition.

coord3(lhs, rhs)

Coordination composition with three elements.

derive_lang_syntax_type(lang_syntax_type)

Create a new syntax type that has an associated standard linguistic syntax type.

fapp(rhs)

Forward application composition.

iter_from_function(function[, nr_used_arguments])

Create all possible linearization of the corresponding function.

none(rhs)

None composition (composition with a None element).

Attributes

arity

The arity of the syntax type.

is_conj

Whether this element is a conjunction.

is_function

Whether the syntax type is a function type.

is_none

Whether this element is None.

is_value

Whether the syntax type is a value type.

typename

return_type

The return type of the syntax.

argument_types

The argument types of the syntax.

linearization

The linearization of arguments.

lang_syntax_type

Optionally, a CCGSyntaxType can be associated with the NeuralCCGSyntaxType.

__init__(return_type, argument_types=None, linearization=None, lang_syntax_type=None, function_typename=None)[source]#
Parameters:
__new__(**kwargs)#
bapp(lhs)#

Backward application composition.

Parameters:

lhs (CCGComposable)

Return type:

CCGComposable

compose(rhs, composition_type)#

Compose this element with another element. This function will call the corresponding composition function according to the composition type. Note that since the coordination composition has three arguments, this function will return a CCGCoordinationImmNode for the first two arguments in coordination composition.

Parameters:
Returns:

The composed element.

Return type:

CCGComposable | CCGCoordinationImmNode

coord(other)#

Coordination composition.

Parameters:

other (CCGComposable | CCGCoordinationImmNode)

Return type:

CCGComposable | CCGCoordinationImmNode

coord3(lhs, rhs)#

Coordination composition with three elements.

Parameters:
Return type:

CCGComposable

derive_lang_syntax_type(lang_syntax_type)[source]#

Create a new syntax type that has an associated standard linguistic syntax type.

Parameters:

lang_syntax_type (CCGSyntaxType) – the syntax type.

Returns:

A new NeuralCCGSyntaxType with the same signature and linearization, but with an associated standard linguistic syntax type.

Return type:

NeuralCCGSyntaxType

fapp(rhs)#

Forward application composition.

Parameters:

rhs (CCGComposable)

Return type:

CCGComposable

classmethod iter_from_function(function, nr_used_arguments=None)[source]#

Create all possible linearization of the corresponding function.

Parameters:
  • function (Function) – the function.

  • nr_used_arguments (int | None) – do enumeration only for the first N arguments. Useful when the function has constant arguments that will be bound with word types.

Yields:

all possible NeuralCCGSyntaxType derived from the given function signature.

Return type:

Iterable[Tuple[NeuralCCGSyntaxType, Function]]

none(rhs)#

None composition (composition with a None element).

Parameters:

rhs (CCGComposable)

Return type:

CCGComposable

argument_types: Tuple[ObjectType | ValueType | FunctionType, ...]#

The argument types of the syntax.

property arity: int#

The arity of the syntax type. That is, the number of arguments it needs to combine before it becomes a primitive syntax type.

property is_conj: bool#

Whether this element is a conjunction.

property is_function: bool#

Whether the syntax type is a function type. That is, whether it can do function application with another syntax type.

property is_none: bool#

Whether this element is None.

property is_value: bool#

Whether the syntax type is a value type. That is, whether it is a primitive syntax type.

lang_syntax_type: CCGSyntaxType | None#

Optionally, a CCGSyntaxType can be associated with the NeuralCCGSyntaxType.

linearization: Tuple[LinearizationTuple, ...]#

The linearization of arguments. See the docstring for details.

return_type: None | str | ObjectType | ValueType#

The return type of the syntax.

property typename#