nltk.ccg.api module

class nltk.ccg.api.AbstractCCGCategory[source]

Bases: object

Interface for categories in combinatory grammars.

abstract can_unify(other)[source]
Determines whether two categories can be unified.
  • Returns None if they cannot be unified

  • Returns a list of necessary substitutions if they can.

abstract is_function()[source]

Returns true if the category is a function application.

abstract is_primitive()[source]

Returns true if the category is primitive.

abstract is_var()[source]

Returns true if the category is a variable.

abstract substitute(substitutions)[source]

Takes a set of (var, category) substitutions, and replaces every occurrence of the variable with the corresponding category.

class nltk.ccg.api.CCGVar[source]

Bases: AbstractCCGCategory

Class representing a variable CCG category. Used for conjunctions (and possibly type-raising, if implemented as a unary rule).

__init__(prim_only=False)[source]

Initialize a variable (selects a new identifier)

Parameters

prim_only (bool) – a boolean that determines whether the variable is restricted to primitives

can_unify(other)[source]

If the variable can be replaced with other a substitution is returned.

id()[source]
is_function()[source]

Returns true if the category is a function application.

is_primitive()[source]

Returns true if the category is primitive.

is_var()[source]

Returns true if the category is a variable.

classmethod new_id()[source]

A class method allowing generation of unique variable identifiers.

classmethod reset_id()[source]
substitute(substitutions)[source]

If there is a substitution corresponding to this variable, return the substituted category.

class nltk.ccg.api.Direction[source]

Bases: object

Class representing the direction of a function application. Also contains maintains information as to which combinators may be used with the category.

__init__(dir, restrictions)[source]
can_compose()[source]
can_cross()[source]
can_unify(other)[source]
dir()[source]
is_backward()[source]
is_forward()[source]
is_variable()[source]
restrs()[source]

A list of restrictions on the combinators. ‘.’ denotes that permuting operations are disallowed ‘,’ denotes that function composition is disallowed ‘_’ denotes that the direction has variable restrictions. (This is redundant in the current implementation of type-raising)

substitute(subs)[source]
class nltk.ccg.api.FunctionalCategory[source]

Bases: AbstractCCGCategory

Class that represents a function application category. Consists of argument and result categories, together with an application direction.

__init__(res, arg, dir)[source]
arg()[source]
can_unify(other)[source]
Determines whether two categories can be unified.
  • Returns None if they cannot be unified

  • Returns a list of necessary substitutions if they can.

dir()[source]
is_function()[source]

Returns true if the category is a function application.

is_primitive()[source]

Returns true if the category is primitive.

is_var()[source]

Returns true if the category is a variable.

res()[source]
substitute(subs)[source]

Takes a set of (var, category) substitutions, and replaces every occurrence of the variable with the corresponding category.

class nltk.ccg.api.PrimitiveCategory[source]

Bases: AbstractCCGCategory

Class representing primitive categories. Takes a string representation of the category, and a list of strings specifying the morphological subcategories.

__init__(categ, restrictions=[])[source]
can_unify(other)[source]
Determines whether two categories can be unified.
  • Returns None if they cannot be unified

  • Returns a list of necessary substitutions if they can.

categ()[source]
is_function()[source]

Returns true if the category is a function application.

is_primitive()[source]

Returns true if the category is primitive.

is_var()[source]

Returns true if the category is a variable.

restrs()[source]
substitute(subs)[source]

Takes a set of (var, category) substitutions, and replaces every occurrence of the variable with the corresponding category.