Coverage for nltk.ccg.api : 86%
![](keybd_closed.png)
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# Natural Language Toolkit: CCG Categories # # Copyright (C) 2001-2012 NLTK Project # Author: Graeme Gange <ggange@csse.unimelb.edu.au> # URL: <http://www.nltk.org/> # For license information, see LICENSE.TXT
''' Interface for categories in combinatory grammars. '''
# Returns true if the category is primitive raise NotImplementedError()
# Returns true if the category is a function application raise NotImplementedError()
# Returns true if the category is a variable raise NotImplementedError()
# Takes a set of (var, category) substitutions, and replaces every # occurrence of the variable with the corresponding category raise NotImplementedError()
# Determines whether two categories can be unified. # - Returns None if they cannot be unified # - Returns a list of necessary substitutions if they can.''' raise NotImplementedError()
# Utility functions: comparison, strings and hashing. raise NotImplementedError()
raise NotImplementedError()
raise NotImplementedError()
''' Class representing a variable CCG category. Used for conjunctions (and possibly type-raising, if implemented as a unary rule). '''
"""Initialize a variable (selects a new identifier)
:param prim_only: a boolean that determines whether the variable is restricted to primitives :type prim_only: bool """
def new_id(cls): """A class method allowing generation of unique variable identifiers."""
return False
return True
"""If there is a substitution corresponding to this variable, return the substituted category. """ return self
""" If the variable can be replaced with other a substitution is returned. """ return None
return -1
''' Class representing the direction of a function application. Also contains maintains information as to which combinators may be used with the category. '''
# Testing the application direction
"""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) """
# Unification and substitution of variable directions. # Used only if type-raising is implemented as a unary rule, as it # must inherit restrictions from the argument category. return [('_',self.restrs())] return [('_',other.restrs())] else:
for (var, restrs) in subs: if var is '_': return Direction(self._dir,restrs) return self
# Testing permitted combinators
return res
# The negation operator reverses the direction of the application return Direction('\\',self._restrs) else:
''' Class representing primitive categories. Takes a string representation of the category, and a list of strings specifying the morphological subcategories. '''
# Substitution does nothing to a primitive category
# A primitive can be unified with a class of the same # base category, given that the other category shares all # of its subclasses, or with a variable. return [(other,self)]
(other.categ(),other.restrs()))
''' Class that represents a function application category. Consists of argument and result categories, together with an application direction. '''
# Substitution returns the category consisting of the # substitution applied to each of its constituents.
# A function can unify with another function, so long as its # constituents can unify, or with an unrestricted variable. return [(other,self)]
# Constituent accessors
return -1 (other.arg(),other.dir(),other.res()))
|