nltk.ccg.api module

class nltk.ccg.api.AbstractCCGCategory[source]

Bases: object

Interface for categories in combinatory grammars.

abstract is_primitive()[source]

Returns true if the category is primitive.

abstract is_function()[source]

Returns true if the category is a function application.

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.

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.

class nltk.ccg.api.CCGVar[source]

Bases: nltk.ccg.api.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

classmethod new_id()[source]

A class method allowing generation of unique variable identifiers.

classmethod reset_id()[source]
is_primitive()[source]

Returns true if the category is primitive.

is_function()[source]

Returns true if the category is a function application.

is_var()[source]

Returns true if the category is a variable.

substitute(substitutions)[source]

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

can_unify(other)[source]

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

id()[source]
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]
is_forward()[source]
is_backward()[source]
dir()[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)

is_variable()[source]
can_unify(other)[source]
substitute(subs)[source]
can_compose()[source]
can_cross()[source]
class nltk.ccg.api.PrimitiveCategory[source]

Bases: nltk.ccg.api.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]
is_primitive()[source]

Returns true if the category is primitive.

is_function()[source]

Returns true if the category is a function application.

is_var()[source]

Returns true if the category is a variable.

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

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

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.

class nltk.ccg.api.FunctionalCategory[source]

Bases: nltk.ccg.api.AbstractCCGCategory

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

__init__(res, arg, dir)[source]
is_primitive()[source]

Returns true if the category is primitive.

is_function()[source]

Returns true if the category is a function application.

is_var()[source]

Returns true if the category is a variable.

substitute(subs)[source]

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

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.

arg()[source]
res()[source]
dir()[source]