Package nltk :: Package ccg :: Module chart
[hide private]
[frames] | no frames]

Module chart

source code


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

Classes [hide private]
CCGEdge
CCGLeafEdge
Class representing leaf edges in a CCG derivation.
BinaryCombinatorRule
Class implementing application of a binary combinator to a chart.
ForwardTypeRaiseRule
Class for applying forward type raising
BackwardTypeRaiseRule
Class for applying backward type raising.
CCGChartParser
Chart parser for CCGs.
CCGChart
Functions [hide private]
 
printCCGDerivation(tree) source code
 
printCCGTree(lwidth, tree) source code
 
demo() source code
Variables [hide private]
  ApplicationRuleSet = [BinaryCombinatorRule(ForwardApplication)...
  CompositionRuleSet = [BinaryCombinatorRule(ForwardComposition)...
  SubstitutionRuleSet = [BinaryCombinatorRule(ForwardSubstitutio...
  TypeRaiseRuleSet = [ForwardTypeRaiseRule(), BackwardTypeRaiseR...
  DefaultRuleSet = ApplicationRuleSet+ CompositionRuleSet+ Subst...
  lex = lexicon.parseLexicon(...
Variables Details [hide private]

ApplicationRuleSet

Value:
[BinaryCombinatorRule(ForwardApplication), BinaryCombinatorRule(Backwa\
rdApplication)]

CompositionRuleSet

Value:
[BinaryCombinatorRule(ForwardComposition), BinaryCombinatorRule(Backwa\
rdComposition), BinaryCombinatorRule(BackwardBx)]

SubstitutionRuleSet

Value:
[BinaryCombinatorRule(ForwardSubstitution), BinaryCombinatorRule(Backw\
ardSx)]

TypeRaiseRuleSet

Value:
[ForwardTypeRaiseRule(), BackwardTypeRaiseRule()]

DefaultRuleSet

Value:
ApplicationRuleSet+ CompositionRuleSet+ SubstitutionRuleSet+ TypeRaise\
RuleSet

lex

Value:
lexicon.parseLexicon('''
    :- S, NP, N, VP    # Primitive categories, S is the target primiti\
ve

    Det :: NP/N         # Family of words
    Pro :: NP
    TV :: VP/NP
    Modal :: (S\\NP)/VP # Backslashes need to be escaped
...