nltk.ccg package¶
Submodules¶
nltk.ccg.api module¶
- class nltk.ccg.api.AbstractCCGCategory[source]¶
Bases: builtins.object
Interface for categories in combinatory grammars.
- class nltk.ccg.api.CCGVar(prim_only=False)[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).
- substitute(substitutions)[source]¶
If there is a substitution corresponding to this variable, return the substituted category.
- unicode_repr None¶
x.__repr__() <==> repr(x)
- class nltk.ccg.api.Direction(dir, restrictions)[source]¶
Bases: builtins.object
Class representing the direction of a function application. Also contains maintains information as to which combinators may be used with the category.
- 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)
- unicode_repr None¶
x.__repr__() <==> repr(x)
- class nltk.ccg.api.FunctionalCategory(res, arg, dir)[source]¶
Bases: nltk.ccg.api.AbstractCCGCategory
Class that represents a function application category. Consists of argument and result categories, together with an application direction.
- unicode_repr None¶
x.__repr__() <==> repr(x)
- class nltk.ccg.api.PrimitiveCategory(categ, restrictions=[])[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.
- unicode_repr None¶
x.__repr__() <==> repr(x)
nltk.ccg.chart module¶
The lexicon is constructed by calling lexicon.parseLexicon(<lexicon string>).
In order to construct a parser, you also need a rule set. The standard English rules are provided in chart as chart.DefaultRuleSet.
The parser can then be constructed by calling, for example: parser = chart.CCGChartParser(<lexicon>, <ruleset>)
Parsing is then performed by running parser.nbest_parse(<sentence>.split()).
While this returns a list of trees, the default representation of the produced trees is not very enlightening, particularly given that it uses the same tree class as the CFG parsers. It is probably better to call: chart.printCCGDerivation(<parse tree extracted from list>) which should print a nice representation of the derivation.
This entire process is shown far more clearly in the demonstration: python chart.py
- class nltk.ccg.chart.BackwardTypeRaiseRule[source]¶
Bases: nltk.parse.chart.AbstractChartRule
Class for applying backward type raising.
- NUMEDGES = 2¶
- unicode_repr None¶
x.__repr__() <==> repr(x)
- class nltk.ccg.chart.BinaryCombinatorRule(combinator)[source]¶
Bases: nltk.parse.chart.AbstractChartRule
Class implementing application of a binary combinator to a chart. Takes the directed combinator to apply.
- NUMEDGES = 2¶
- unicode_repr None¶
x.__repr__() <==> repr(x)
- class nltk.ccg.chart.CCGChart(tokens)[source]¶
Bases: nltk.parse.chart.Chart
- class nltk.ccg.chart.CCGChartParser(lexicon, rules, trace=0)[source]¶
Bases: nltk.parse.api.ParserI
Chart parser for CCGs. Based largely on the ChartParser class from NLTK.
- class nltk.ccg.chart.CCGEdge(span, categ, rule)[source]¶
Bases: nltk.parse.chart.EdgeI
- class nltk.ccg.chart.CCGLeafEdge(pos, categ, leaf)[source]¶
Bases: nltk.parse.chart.EdgeI
Class representing leaf edges in a CCG derivation.
- class nltk.ccg.chart.ForwardTypeRaiseRule[source]¶
Bases: nltk.parse.chart.AbstractChartRule
Class for applying forward type raising
- NUMEDGES = 2¶
- unicode_repr None¶
x.__repr__() <==> repr(x)
nltk.ccg.combinator module¶
- class nltk.ccg.combinator.BackwardCombinator(combinator, predicate, suffix='')[source]¶
Bases: nltk.ccg.combinator.DirectedBinaryCombinator
The backward equivalent of the ForwardCombinator class.
- unicode_repr None¶
x.__repr__() <==> repr(x)
- class nltk.ccg.combinator.DirectedBinaryCombinator[source]¶
Bases: builtins.object
Wrapper for the undirected binary combinator. It takes left and right categories, and decides which is to be the function, and which the argument. It then decides whether or not they can be combined.
- class nltk.ccg.combinator.ForwardCombinator(combinator, predicate, suffix='')[source]¶
Bases: nltk.ccg.combinator.DirectedBinaryCombinator
Class representing combinators where the primary functor is on the left.
Takes an undirected combinator, and a predicate which adds constraints restricting the cases in which it may apply.
- unicode_repr None¶
x.__repr__() <==> repr(x)
- class nltk.ccg.combinator.UndirectedBinaryCombinator[source]¶
Bases: builtins.object
Abstract class for representing a binary combinator. Merely defines functions for checking if the function and argument are able to be combined, and what the resulting category is.
Note that as no assumptions are made as to direction, the unrestricted combinators can perform all backward, forward and crossed variations of the combinators; these restrictions must be added in the rule class.
- class nltk.ccg.combinator.UndirectedComposition[source]¶
Bases: nltk.ccg.combinator.UndirectedBinaryCombinator
Functional composition (harmonic) combinator. Implements rules of the form X/Y Y/Z -> X/Z (B>) And the corresponding backwards and crossed variations.
- unicode_repr None¶
x.__repr__() <==> repr(x)
- class nltk.ccg.combinator.UndirectedFunctionApplication[source]¶
Bases: nltk.ccg.combinator.UndirectedBinaryCombinator
Class representing function application. Implements rules of the form: X/Y Y -> X (>) And the corresponding backwards application rule
- unicode_repr None¶
x.__repr__() <==> repr(x)
- class nltk.ccg.combinator.UndirectedSubstitution[source]¶
Bases: nltk.ccg.combinator.UndirectedBinaryCombinator
Substitution (permutation) combinator. Implements rules of the form Y/Z (XY)/Z -> X/Z (<Sx) And other variations.
- unicode_repr None¶
x.__repr__() <==> repr(x)
- class nltk.ccg.combinator.UndirectedTypeRaise[source]¶
Bases: nltk.ccg.combinator.UndirectedBinaryCombinator
Undirected combinator for type raising.
- unicode_repr None¶
x.__repr__() <==> repr(x)
nltk.ccg.lexicon module¶
- class nltk.ccg.lexicon.CCGLexicon(start, primitives, families, entries)[source]¶
Bases: builtins.object
Class representing a lexicon for CCG grammars. primitives - The list of primitive categories for the lexicon families - Families of categories entries - A mapping of words to possible categories
- unicode_repr None¶
x.__repr__() <==> repr(x)
Module contents¶
Combinatory Categorial Grammar.
For more information see nltk/doc/contrib/ccg/ccg.pdf