nltk.ccg.chart module¶
The lexicon is constructed by calling
lexicon.fromstring(<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.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:
AbstractChartRule
Class for applying backward type raising.
- NUMEDGES = 2¶
- class nltk.ccg.chart.BinaryCombinatorRule[source]¶
Bases:
AbstractChartRule
Class implementing application of a binary combinator to a chart. Takes the directed combinator to apply.
- NUMEDGES = 2¶
- class nltk.ccg.chart.CCGChartParser[source]¶
Bases:
ParserI
Chart parser for CCGs. Based largely on the ChartParser class from NLTK.
- class nltk.ccg.chart.CCGEdge[source]¶
Bases:
EdgeI
- dot()[source]¶
Return this edge’s dot position, which indicates how much of the hypothesized structure is consistent with the sentence. In particular,
self.rhs[:dot]
is consistent withtokens[self.start():self.end()]
.- Return type:
int
- is_complete()[source]¶
Return True if this edge’s structure is fully consistent with the text.
- Return type:
bool
- is_incomplete()[source]¶
Return True if this edge’s structure is partially consistent with the text.
- Return type:
bool
- lhs()[source]¶
Return this edge’s left-hand side, which specifies what kind of structure is hypothesized by this edge.
- See:
TreeEdge
andLeafEdge
for a description of the left-hand side values for each edge type.
- nextsym()[source]¶
Return the element of this edge’s right-hand side that immediately follows its dot.
- Return type:
Nonterminal or terminal or None
- rhs()[source]¶
Return this edge’s right-hand side, which specifies the content of the structure hypothesized by this edge.
- See:
TreeEdge
andLeafEdge
for a description of the right-hand side values for each edge type.
- class nltk.ccg.chart.CCGLeafEdge[source]¶
Bases:
EdgeI
Class representing leaf edges in a CCG derivation.
- dot()[source]¶
Return this edge’s dot position, which indicates how much of the hypothesized structure is consistent with the sentence. In particular,
self.rhs[:dot]
is consistent withtokens[self.start():self.end()]
.- Return type:
int
- is_complete()[source]¶
Return True if this edge’s structure is fully consistent with the text.
- Return type:
bool
- is_incomplete()[source]¶
Return True if this edge’s structure is partially consistent with the text.
- Return type:
bool
- lhs()[source]¶
Return this edge’s left-hand side, which specifies what kind of structure is hypothesized by this edge.
- See:
TreeEdge
andLeafEdge
for a description of the left-hand side values for each edge type.
- nextsym()[source]¶
Return the element of this edge’s right-hand side that immediately follows its dot.
- Return type:
Nonterminal or terminal or None
- rhs()[source]¶
Return this edge’s right-hand side, which specifies the content of the structure hypothesized by this edge.
- See:
TreeEdge
andLeafEdge
for a description of the right-hand side values for each edge type.
- class nltk.ccg.chart.ForwardTypeRaiseRule[source]¶
Bases:
AbstractChartRule
Class for applying forward type raising
- NUMEDGES = 2¶