2to3 (compiles, not tested)
[tag_parser.git] / tests / stand_alone / elephant.py
blob626c216250eaeef98565527bec66c1bd21aad47c
1 # This Python file uses the following encoding: utf-8
2 '''
3 Created on May 19, 2011
5 @author: mjacob
6 '''
7 from mjacob.nltk.grammar.TreeAdjoiningGrammar import TreeAdjoiningGrammar
8 from mjacob.nltk.parse.tag.TagChartParser import TagChartParser
9 from mjacob.nltk.parse.tag.prefix_valid_earley.rules import TAG_PREFIX_VALID_EARLEY_STRATEGY
11 grammar = TreeAdjoiningGrammar(filename="../integration/tag_chart/elephant/grammar.yaml")
12 parser = TagChartParser(grammar, strategy=TAG_PREFIX_VALID_EARLEY_STRATEGY)
14 for s in ["I shot an elephant in my pajamas"]:
15 tokens = s.split(' ')
16 chart = parser.chart_parse(tokens)
17 # for goal_edge, deduction in chart.deduction_paths(grammar.start().symbol(), TAG_EARLEY_STRATEGY):
18 # print "GOAL: %s" % (goal_edge)
19 # i = 1
20 # for x,y,z in deduction:
21 # print "% 6i %s <- %s" % (i, x, y)
22 # for tree in z:
23 # print " %s" % (z,)
24 # i += 1
26 print(" %s" % ("\n ".join(tree.pprint(margin=10000) for tree in chart.parses(grammar.start().symbol(), TAG_PREFIX_VALID_EARLEY_STRATEGY))))
27 #print parser.nbest_parse(tokens)
28 #print parser.parse(tokens)