Constituent-based Syntactic Parsing with NLTK

NLTK contains classes to work with PCFGs. This document reviews existing building blocks in NLTK 3.0.

  1. Treebank
  2. Trees
  3. CFG
  4. PCFG
  5. Parsers

Treebank

NLTK includes a 5% fragment of the Penn Treebank corpus (about 1,600 sentences). You can observe the parsed trees using the treebank corpus reader:

In [1]:
import nltk
print(nltk.corpus.treebank.parsed_sents('wsj_0001.mrg')[0])
(S
  (NP-SBJ
    (NP (NNP Pierre) (NNP Vinken))
    (, ,)
    (ADJP (NP (CD 61) (NNS years)) (JJ old))
    (, ,))
  (VP
    (MD will)
    (VP
      (VB join)
      (NP (DT the) (NN board))
      (PP-CLR (IN as) (NP (DT a) (JJ nonexecutive) (NN director)))
      (NP-TMP (NNP Nov.) (CD 29))))
  (. .))

The draw() method produces a graphical rendering of the trees:

In [2]:
nltk.corpus.treebank.parsed_sents('wsj_0001.mrg')[0].draw()

Trees

NLTK includes a tree class.

The class has accessors for root and children, parsers to read a parenthesized representation of trees, mutators to change nodes within a tree, and tree transformations to turn a tree into a Chomsky-Normal-Form (CNF) tree. There is also a method to draw trees in a graphical manner. The code in nltk.tree.demo() demonstrates how this class can be used.

In [3]:
from nltk import Tree

# Parse a tree from a string with parentheses.
s = '(S (NP (DT the) (NN cat)) (VP (VBD ate) (NP (DT a) (NN cookie))))'
t = Tree.fromstring(s)
print("Convert bracketed string into tree:")
print(t)
print(t.__repr__())
Convert bracketed string into tree:
(S (NP (DT the) (NN cat)) (VP (VBD ate) (NP (DT a) (NN cookie))))
Tree('S', [Tree('NP', [Tree('DT', ['the']), Tree('NN', ['cat'])]), Tree('VP', [Tree('VBD', ['ate']), Tree('NP', [Tree('DT', ['a']), Tree('NN', ['cookie'])])])])

Tree Accessors

In [4]:
print("Display tree properties:")
print(t.label())   # tree's constituent type
print(t[0]) # tree's first child
print(t[1]) # tree's second child
Display tree properties:
S
(NP (DT the) (NN cat))
(VP (VBD ate) (NP (DT a) (NN cookie)))
In [5]:
print(t.height())
5
In [6]:
print(t.leaves())
['the', 'cat', 'ate', 'a', 'cookie']
In [7]:
print(t[1])
print(t[1,1])
print(t[1,1,0])
(VP (VBD ate) (NP (DT a) (NN cookie)))
(NP (DT a) (NN cookie))
(DT a)

Tree Mutators

In [8]:
# Demonstrate tree modification.
the_cat = t[0]
the_cat.insert(1, Tree.fromstring('(JJ big)'))
print("Tree modification:")
print(t)
t[1,1,1] = Tree.fromstring('(NN cake)')
print(t)
Tree modification:
(S
  (NP (DT the) (JJ big) (NN cat))
  (VP (VBD ate) (NP (DT a) (NN cookie))))
(S
  (NP (DT the) (JJ big) (NN cat))
  (VP (VBD ate) (NP (DT a) (NN cake))))

Tree Transformations

In [9]:
# Tree transforms
print("Collapse unary:")
t.collapse_unary()
print(t)
print("Chomsky normal form:")
t.chomsky_normal_form()
print(t)
Collapse unary:
(S
  (NP (DT the) (JJ big) (NN cat))
  (VP (VBD ate) (NP (DT a) (NN cake))))
Chomsky normal form:
(S
  (NP (DT the) (NP|<JJ-NN> (JJ big) (NN cat)))
  (VP (VBD ate) (NP (DT a) (NN cake))))

Probabilistic Trees

In [10]:
# Demonstrate probabilistic trees.
pt = nltk.tree.ProbabilisticTree('x', ['y', 'z'], prob=0.5)
print("Probabilistic Tree:")
print(pt)
Probabilistic Tree:
(x y z) (p=0.5)
In [11]:
# Demonstrate LaTeX output
print("LaTeX output:")
print(t.pformat_latex_qtree())
LaTeX output:
\Tree [.S
        [.NP [.DT the ] [.NP|<JJ-NN> [.JJ big ] [.NN cat ] ] ]
        [.VP [.VBD ate ] [.NP [.DT a ] [.NN cake ] ] ] ]
In [12]:
print(t)

# Demonstrate Productions
print("Production output:")
print(t.productions())
(S
  (NP (DT the) (NP|<JJ-NN> (JJ big) (NN cat)))
  (VP (VBD ate) (NP (DT a) (NN cake))))
Production output:
[S -> NP VP, NP -> DT NP|<JJ-NN>, DT -> 'the', NP|<JJ-NN> -> JJ NN, JJ -> 'big', NN -> 'cat', VP -> VBD NP, VBD -> 'ate', NP -> DT NN, DT -> 'a', NN -> 'cake']
In [13]:
# Demonstrate tree nodes containing objects other than strings
t.set_label(('test', 3))
print(t)
(('test', 3)
  (NP (DT the) (NP|<JJ-NN> (JJ big) (NN cat)))
  (VP (VBD ate) (NP (DT a) (NN cake))))

CFG

NLTK includes several classes to encode CFG and PCFG grammars in the nltk.grammar module:

  1. Nonterminal
  2. Production (for rules)
  3. WeightedProduction (for rules in a PCFG)
  4. ContextFreeGrammar
  5. PCFG

The classes include convenient parsers to convert strings into grammars. The method grammar.check_coverage(ws) determines whether the words that appear in ws can ever be parsed by the grammar.

The function nltk.grammar.cfg_demo() illustrates how these classes are used.

In [14]:
from nltk import nonterminals, Nonterminal, Production

# Create some nonterminals
S, NP, VP, PP = nonterminals('S, NP, VP, PP')
N, V, P, Det = nonterminals('N, V, P, Det')
VP_slash_NP = Nonterminal('VP/NP')

print('Some nonterminals:', [S, NP, VP, PP, N, V, P, Det, VP_slash_NP])
print('S.symbol() =>', S.symbol())
Some nonterminals: [S, NP, VP, PP, N, V, P, Det, VP/NP]
S.symbol() => S
In [15]:
print(Production(S, [NP]))
S -> NP
In [16]:
# Create some Grammar Productions
from nltk import CFG

grammar = CFG.fromstring("""
  S -> NP VP
  PP -> P NP
  NP -> Det N | NP PP
  VP -> V NP | VP PP
  Det -> 'a' | 'the'
  N -> 'dog' | 'cat'
  V -> 'chased' | 'sat'
  P -> 'on' | 'in'
""")

print('A Grammar:', grammar)
print('grammar.start()   =>', grammar.start())
print('grammar.productions() =>')
# Use string.replace(...) is to line-wrap the output.
print(grammar.productions())
A Grammar: Grammar with 14 productions (start state = S)
    S -> NP VP
    PP -> P NP
    NP -> Det N
    NP -> NP PP
    VP -> V NP
    VP -> VP PP
    Det -> 'a'
    Det -> 'the'
    N -> 'dog'
    N -> 'cat'
    V -> 'chased'
    V -> 'sat'
    P -> 'on'
    P -> 'in'
grammar.start()   => S
grammar.productions() =>
[S -> NP VP, PP -> P NP, NP -> Det N, NP -> NP PP, VP -> V NP, VP -> VP PP, Det -> 'a', Det -> 'the', N -> 'dog', N -> 'cat', V -> 'chased', V -> 'sat', P -> 'on', P -> 'in']
In [17]:
print('Coverage of input words by a grammar:')
try:
    grammar.check_coverage(['a','dog'])
    print("All words covered")
except:
    print("Strange")
try:
    print(grammar.check_coverage(['a','toy']))
except:
    print("Some words not covered")
Coverage of input words by a grammar:
All words covered
Some words not covered

PCFG

PCFGs are very similar to CFGs - they just have an additional probability for each production. For a given left-hand-side non-terminal, the sum of the probabilities must be 1.0.

In [18]:
from nltk import PCFG
toy_pcfg1 = PCFG.fromstring("""
    S -> NP VP [1.0]
    NP -> Det N [0.5] | NP PP [0.25] | 'John' [0.1] | 'I' [0.15]
    Det -> 'the' [0.8] | 'my' [0.2]
    N -> 'man' [0.5] | 'telescope' [0.5]
    VP -> VP PP [0.1] | V NP [0.7] | V [0.2]
    V -> 'ate' [0.35] | 'saw' [0.65]
    PP -> P NP [1.0]
    P -> 'with' [0.61] | 'under' [0.39]
""")

The function nltk.grammar.pcfg_demo() illustrates how PCFGs can be constructed and manipulated. The most important method consists of inducing a PCFG from trees in a treebank (induce_pcfg()). Before we induce the PCFG, we take care of transforming the trees into CNF. Note how tree.productions() returns the list of CFG rules that "explain" the tree: for each non-terminal node in the tree, tree.productions() will return a production with the parent node as LHS and the children as RHS.

In [19]:
from nltk.corpus import treebank
from nltk import treetransforms
from nltk import induce_pcfg
from nltk.parse import pchart

pcfg_prods = toy_pcfg1.productions()

pcfg_prod = pcfg_prods[2]
print('A PCFG production:', pcfg_prod)
print('pcfg_prod.lhs()  =>', pcfg_prod.lhs())
print('pcfg_prod.rhs()  =>', pcfg_prod.rhs())
print('pcfg_prod.prob() =>', pcfg_prod.prob())
A PCFG production: NP -> NP PP [0.25]
pcfg_prod.lhs()  => NP
pcfg_prod.rhs()  => (NP, PP)
pcfg_prod.prob() => 0.25
In [20]:
# extract productions from three trees and induce the PCFG
print("Induce PCFG grammar from treebank data:")

productions = []
for item in treebank.fileids()[:2]:
  for tree in treebank.parsed_sents(item):
    # perform optional tree transformations, e.g.:
    tree.collapse_unary(collapsePOS = False)# Remove branches A-B-C into A-B+C
    tree.chomsky_normal_form(horzMarkov = 2)# Remove A->(B,C,D) into A->B,C+D->D
    productions += tree.productions()
Induce PCFG grammar from treebank data:
In [21]:
from nltk import Nonterminal
S = Nonterminal('S')
grammar = induce_pcfg(S, productions)
print(grammar)
Grammar with 86 productions (start state = S)
    VP -> VB VP|<NP-PP-CLR> [0.2]
    NP -> DT NP|<JJ-NN> [0.133333]
    . -> '.' [1.0]
    NP -> NP PP [0.0666667]
    NP -> CD NNS [0.133333]
    VP|<PP-CLR-NP-TMP> -> PP-CLR NP-TMP [1.0]
    NP-SBJ|<ADJP-,> -> ADJP , [1.0]
    NP-SBJ -> NNP NNP [0.333333]
    NN -> 'group' [0.142857]
    DT -> 'the' [0.4]
    NNP -> 'Rudolph' [0.0714286]
    NP-TMP -> NNP CD [1.0]
    S -> NP-SBJ-1 S|<VP-.> [0.25]
    NNP -> 'Nov.' [0.0714286]
    NNP -> 'Pierre' [0.0714286]
    NP -> DT NP|<NNP-VBG> [0.0666667]
    , -> ',' [1.0]
    NN -> 'chairman' [0.285714]
    NNS -> 'years' [1.0]
    VBD -> 'was' [1.0]
    JJ -> 'British' [0.142857]
    NNP -> 'Gold' [0.0714286]
    S -> NP-SBJ S|<VP-.> [0.5]
    JJ -> 'industrial' [0.142857]
    NNP -> 'Consolidated' [0.0714286]
    JJ -> 'old' [0.285714]
    CD -> '61' [0.333333]
    VP -> VBD VP [0.2]
    NNP -> 'Dutch' [0.0714286]
    NP-SBJ -> -NONE- [0.333333]
    S -> NP-SBJ NP-PRD [0.25]
    NP -> NNP NP|<NNP-NNP> [0.0666667]
    NNP -> 'PLC' [0.0714286]
    UCP|<CC-NP> -> CC NP [1.0]
    -NONE- -> '*-1' [1.0]
    IN -> 'of' [0.75]
    IN -> 'as' [0.25]
    NP|<NNP-NNP> -> NNP NNP [0.5]
    NNP -> 'N.V.' [0.0714286]
    CC -> 'and' [1.0]
    NN -> 'director' [0.285714]
    UCP -> ADJP UCP|<CC-NP> [1.0]
    JJ -> 'former' [0.142857]
    VP|<NP-PP-CLR> -> NP VP|<PP-CLR-NP-TMP> [1.0]
    NP|<NNP-NNP> -> NNP NP|<NNP-NNP> [0.5]
    NP-SBJ -> NP NP-SBJ|<,-ADJP> [0.333333]
    ADJP -> NP JJ [1.0]
    NN -> 'conglomerate' [0.142857]
    VBN -> 'named' [1.0]
    S|<VP-.> -> VP . [1.0]
    PP-CLR -> IN NP [1.0]
    MD -> 'will' [1.0]
    NP -> DT NP|<JJ-JJ> [0.0666667]
    VP -> MD VP [0.2]
    NP-SBJ-1|<,-UCP> -> , NP-SBJ-1|<UCP-,> [1.0]
    NP-PRD -> NP PP [1.0]
    NP|<VBG-NN> -> VBG NN [1.0]
    NP-SBJ-1|<UCP-,> -> UCP , [1.0]
    NNP -> 'Agnew' [0.0714286]
    NN -> 'board' [0.142857]
    NP -> NN [0.0666667]
    NP -> DT NN [0.0666667]
    CD -> '55' [0.333333]
    JJ -> 'nonexecutive' [0.285714]
    VB -> 'join' [1.0]
    NP|<JJ-JJ> -> JJ NP|<JJ-NN> [1.0]
    CD -> '29' [0.333333]
    NP -> NNP NNP [0.2]
    NP-SBJ|<,-ADJP> -> , NP-SBJ|<ADJP-,> [1.0]
    NNP -> 'Elsevier' [0.0714286]
    PP -> IN NP [1.0]
    NP -> JJ NN [0.0666667]
    NNP -> 'Vinken' [0.142857]
    DT -> 'a' [0.4]
    VP -> VBZ NP-PRD [0.2]
    NNP -> 'Mr.' [0.0714286]
    NP|<,-NP> -> , NP [1.0]
    VBZ -> 'is' [1.0]
    NP|<JJ-NN> -> JJ NN [1.0]
    NP -> NP NP|<,-NP> [0.0666667]
    VBG -> 'publishing' [1.0]
    NNP -> 'Fields' [0.0714286]
    NP-SBJ-1 -> NP NP-SBJ-1|<,-UCP> [1.0]
    VP -> VBN S [0.2]
    DT -> 'this' [0.2]
    NP|<NNP-VBG> -> NNP NP|<VBG-NN> [1.0]

Parsers

There are different types of parsers implemented in NLTK. One that implements the Viterbi CKY n-best parses over a PCFG is available in the parse.viterbi module.

In [22]:
print("Parse sentence using induced grammar:")

parser = pchart.InsideChartParser(grammar)
parser.trace(3)

sent = treebank.parsed_sents('wsj_0001.mrg')[0].leaves()
print(sent)

for parse in parser.parse(sent):
  print(parse)
Parse sentence using induced grammar:
['Pierre', 'Vinken', ',', '61', 'years', 'old', ',', 'will', 'join', 'the', 'board', 'as', 'a', 'nonexecutive', 'director', 'Nov.', '29', '.']
  |[-] . . . . . . . . . . . . . . . . .| [0:1] 'Pierre' [1.0]
  |. [-] . . . . . . . . . . . . . . . .| [1:2] 'Vinken' [1.0]
  |. . [-] . . . . . . . . . . . . . . .| [2:3] ','  [1.0]
  |. . . [-] . . . . . . . . . . . . . .| [3:4] '61' [1.0]
  |. . . . [-] . . . . . . . . . . . . .| [4:5] 'years' [1.0]
  |. . . . . [-] . . . . . . . . . . . .| [5:6] 'old' [1.0]
  |. . . . . . [-] . . . . . . . . . . .| [6:7] ','  [1.0]
  |. . . . . . . [-] . . . . . . . . . .| [7:8] 'will' [1.0]
  |. . . . . . . . [-] . . . . . . . . .| [8:9] 'join' [1.0]
  |. . . . . . . . . [-] . . . . . . . .| [9:10] 'the' [1.0]
  |. . . . . . . . . . [-] . . . . . . .| [10:11] 'board' [1.0]
  |. . . . . . . . . . . [-] . . . . . .| [11:12] 'as' [1.0]
  |. . . . . . . . . . . . [-] . . . . .| [12:13] 'a' [1.0]
  |. . . . . . . . . . . . . [-] . . . .| [13:14] 'nonexecutive' [1.0]
  |. . . . . . . . . . . . . . [-] . . .| [14:15] 'director' [1.0]
  |. . . . . . . . . . . . . . . [-] . .| [15:16] 'Nov.' [1.0]
  |. . . . . . . . . . . . . . . . [-] .| [16:17] '29' [1.0]
  |. . . . . . . . . . . . . . . . . [-]| [17:18] '.' [1.0]
  |. . . . . . . . . . . . . . . . . [-]| [17:18] '.' [1.0]
  |. . . . . . . . . . . . . . . . . [-]| [17:18] .  -> '.' * [1.0]
  |. . . . . . . . . . . . . . . . . > .| [17:17] .  -> * '.' [1.0]
  |. . . . . . . . . . . . . . . . [-] .| [16:17] '29' [1.0]
  |. . . . . . . . . . . . . . . [-] . .| [15:16] 'Nov.' [1.0]
  |. . . . . . . . . . . . . . [-] . . .| [14:15] 'director' [1.0]
  |. . . . . . . . . . . . . [-] . . . .| [13:14] 'nonexecutive' [1.0]
  |. . . . . . . . . . . . [-] . . . . .| [12:13] 'a' [1.0]
  |. . . . . . . . . . . [-] . . . . . .| [11:12] 'as' [1.0]
  |. . . . . . . . . . [-] . . . . . . .| [10:11] 'board' [1.0]
  |. . . . . . . . . [-] . . . . . . . .| [9:10] 'the' [1.0]
  |. . . . . . . . [-] . . . . . . . . .| [8:9] 'join' [1.0]
  |. . . . . . . . [-] . . . . . . . . .| [8:9] VB -> 'join' * [1.0]
  |. . . . . . . . > . . . . . . . . . .| [8:8] VB -> * 'join' [1.0]
  |. . . . . . . [-] . . . . . . . . . .| [7:8] 'will' [1.0]
  |. . . . . . . [-] . . . . . . . . . .| [7:8] MD -> 'will' * [1.0]
  |. . . . . . . > . . . . . . . . . . .| [7:7] MD -> * 'will' [1.0]
  |. . . . . . [-] . . . . . . . . . . .| [6:7] ','  [1.0]
  |. . . . . . [-] . . . . . . . . . . .| [6:7] ,  -> ',' * [1.0]
  |. . . . . . [-> . . . . . . . . . . .| [6:7] NP|<,-NP> -> , * NP [1.0]
  |. . . . . . [-> . . . . . . . . . . .| [6:7] NP-SBJ|<,-ADJP> -> , * NP-SBJ|<ADJP-,> [1.0]
  |. . . . . . [-> . . . . . . . . . . .| [6:7] NP-SBJ-1|<,-UCP> -> , * NP-SBJ-1|<UCP-,> [1.0]
  |. . . . . . > . . . . . . . . . . . .| [6:6] NP|<,-NP> -> * , NP [1.0]
  |. . . . . . > . . . . . . . . . . . .| [6:6] NP-SBJ|<,-ADJP> -> * , NP-SBJ|<ADJP-,> [1.0]
  |. . . . . . > . . . . . . . . . . . .| [6:6] NP-SBJ-1|<,-UCP> -> * , NP-SBJ-1|<UCP-,> [1.0]
  |. . . . . . > . . . . . . . . . . . .| [6:6] ,  -> * ',' [1.0]
  |. . . . . [-] . . . . . . . . . . . .| [5:6] 'old' [1.0]
  |. . . . [-] . . . . . . . . . . . . .| [4:5] 'years' [1.0]
  |. . . . [-] . . . . . . . . . . . . .| [4:5] NNS -> 'years' * [1.0]
  |. . . . > . . . . . . . . . . . . . .| [4:4] NNS -> * 'years' [1.0]
  |. . . [-] . . . . . . . . . . . . . .| [3:4] '61' [1.0]
  |. . [-] . . . . . . . . . . . . . . .| [2:3] ','  [1.0]
  |. . [-] . . . . . . . . . . . . . . .| [2:3] ,  -> ',' * [1.0]
  |. . [-> . . . . . . . . . . . . . . .| [2:3] NP|<,-NP> -> , * NP [1.0]
  |. . [-> . . . . . . . . . . . . . . .| [2:3] NP-SBJ|<,-ADJP> -> , * NP-SBJ|<ADJP-,> [1.0]
  |. . [-> . . . . . . . . . . . . . . .| [2:3] NP-SBJ-1|<,-UCP> -> , * NP-SBJ-1|<UCP-,> [1.0]
  |. . > . . . . . . . . . . . . . . . .| [2:2] NP|<,-NP> -> * , NP [1.0]
  |. . > . . . . . . . . . . . . . . . .| [2:2] NP-SBJ|<,-ADJP> -> * , NP-SBJ|<ADJP-,> [1.0]
  |. . > . . . . . . . . . . . . . . . .| [2:2] NP-SBJ-1|<,-UCP> -> * , NP-SBJ-1|<UCP-,> [1.0]
  |. . > . . . . . . . . . . . . . . . .| [2:2] ,  -> * ',' [1.0]
  |. [-] . . . . . . . . . . . . . . . .| [1:2] 'Vinken' [1.0]
  |[-] . . . . . . . . . . . . . . . . .| [0:1] 'Pierre' [1.0]
  |. . . . . . . . . [-] . . . . . . . .| [9:10] DT -> 'the' * [0.4]
  |. . . . . . . . . > . . . . . . . . .| [9:9] DT -> * 'the' [0.4]
  |. . . . . . . . . . . . [-] . . . . .| [12:13] DT -> 'a' * [0.4]
  |. . . . . . . . . . . . > . . . . . .| [12:12] DT -> * 'a' [0.4]
  |. . . [-] . . . . . . . . . . . . . .| [3:4] CD -> '61' * [0.3333333333333333]
  |. . . > . . . . . . . . . . . . . . .| [3:3] CD -> * '61' [0.3333333333333333]
  |. . . . . . . . . . . . . . . . [-] .| [16:17] CD -> '29' * [0.3333333333333333]
  |. . . . . . . . . . . . . . . . > . .| [16:16] CD -> * '29' [0.3333333333333333]
  |. . . . . [-] . . . . . . . . . . . .| [5:6] JJ -> 'old' * [0.2857142857142857]
  |. . . . . > . . . . . . . . . . . . .| [5:5] NP|<JJ-NN> -> * JJ NN [1.0]
  |. . . . . > . . . . . . . . . . . . .| [5:5] NP|<JJ-JJ> -> * JJ NP|<JJ-NN> [1.0]
  |. . . . . [-> . . . . . . . . . . . .| [5:6] NP|<JJ-NN> -> JJ * NN [0.2857142857142857]
  |. . . . . [-> . . . . . . . . . . . .| [5:6] NP|<JJ-JJ> -> JJ * NP|<JJ-NN> [0.2857142857142857]
  |. . . . . > . . . . . . . . . . . . .| [5:5] JJ -> * 'old' [0.2857142857142857]
  |. . . . . . . . . . . . . [-] . . . .| [13:14] JJ -> 'nonexecutive' * [0.2857142857142857]
  |. . . . . . . . . . . . . > . . . . .| [13:13] NP|<JJ-NN> -> * JJ NN [1.0]
  |. . . . . . . . . . . . . > . . . . .| [13:13] NP|<JJ-JJ> -> * JJ NP|<JJ-NN> [1.0]
  |. . . . . . . . . . . . . [-> . . . .| [13:14] NP|<JJ-NN> -> JJ * NN [0.2857142857142857]
  |. . . . . . . . . . . . . [-> . . . .| [13:14] NP|<JJ-JJ> -> JJ * NP|<JJ-NN> [0.2857142857142857]
  |. . . . . . . . . . . . . > . . . . .| [13:13] JJ -> * 'nonexecutive' [0.2857142857142857]
  |. . . . . . . . . . . . . . [-] . . .| [14:15] NN -> 'director' * [0.2857142857142857]
  |. . . . . . . . . . . . . . > . . . .| [14:14] NN -> * 'director' [0.2857142857142857]
  |. . . . . . . . . . . [-] . . . . . .| [11:12] IN -> 'as' * [0.25]
  |. . . . . . . . . . . > . . . . . . .| [11:11] PP -> * IN NP [1.0]
  |. . . . . . . . . . . > . . . . . . .| [11:11] PP-CLR -> * IN NP [1.0]
  |. . . . . . . . . . . [-> . . . . . .| [11:12] PP -> IN * NP [0.25]
  |. . . . . . . . . . . [-> . . . . . .| [11:12] PP-CLR -> IN * NP [0.25]
  |. . . . . . . . . . . > . . . . . . .| [11:11] IN -> * 'as' [0.25]
  |. . . . . . . [-> . . . . . . . . . .| [7:8] VP -> MD * VP [0.2]
  |. . . . . . . > . . . . . . . . . . .| [7:7] VP -> * MD VP [0.2]
  |. . . . . . . . [-> . . . . . . . . .| [8:9] VP -> VB * VP|<NP-PP-CLR> [0.2]
  |. . . . . . . . > . . . . . . . . . .| [8:8] VP -> * VB VP|<NP-PP-CLR> [0.2]
  |. [-] . . . . . . . . . . . . . . . .| [1:2] NNP -> 'Vinken' * [0.14285714285714285]
  |. > . . . . . . . . . . . . . . . . .| [1:1] NP|<NNP-VBG> -> * NNP NP|<VBG-NN> [1.0]
  |. > . . . . . . . . . . . . . . . . .| [1:1] NP-TMP -> * NNP CD [1.0]
  |. > . . . . . . . . . . . . . . . . .| [1:1] NP|<NNP-NNP> -> * NNP NP|<NNP-NNP> [0.5]
  |. > . . . . . . . . . . . . . . . . .| [1:1] NP|<NNP-NNP> -> * NNP NNP [0.5]
  |. > . . . . . . . . . . . . . . . . .| [1:1] NP-SBJ -> * NNP NNP [0.3333333333333333]
  |. > . . . . . . . . . . . . . . . . .| [1:1] NP -> * NNP NNP [0.2]
  |. [-> . . . . . . . . . . . . . . . .| [1:2] NP|<NNP-VBG> -> NNP * NP|<VBG-NN> [0.14285714285714285]
  |. [-> . . . . . . . . . . . . . . . .| [1:2] NP-TMP -> NNP * CD [0.14285714285714285]
  |. > . . . . . . . . . . . . . . . . .| [1:1] NNP -> * 'Vinken' [0.14285714285714285]
  |. . . . . . . . . . [-] . . . . . . .| [10:11] NN -> 'board' * [0.14285714285714285]
  |. . . . . . . . . . > . . . . . . . .| [10:10] NN -> * 'board' [0.14285714285714285]
  |. . . . . . . . . . . . . . . . > . .| [16:16] NP -> * CD NNS [0.13333333333333333]
  |. . . > . . . . . . . . . . . . . . .| [3:3] NP -> * CD NNS [0.13333333333333333]
  |. . . . . . . . . . . . > . . . . . .| [12:12] NP -> * DT NP|<JJ-NN> [0.13333333333333333]
  |. . . . . . . . . > . . . . . . . . .| [9:9] NP -> * DT NP|<JJ-NN> [0.13333333333333333]
  |. . . . . . . . . . . . . [---] . . .| [13:15] NP|<JJ-NN> -> JJ NN * [0.08163265306122448]
  |. [-> . . . . . . . . . . . . . . . .| [1:2] NP|<NNP-NNP> -> NNP * NP|<NNP-NNP> [0.07142857142857142]
  |. [-> . . . . . . . . . . . . . . . .| [1:2] NP|<NNP-NNP> -> NNP * NNP [0.07142857142857142]
  |[-] . . . . . . . . . . . . . . . . .| [0:1] NNP -> 'Pierre' * [0.07142857142857142]
  |> . . . . . . . . . . . . . . . . . .| [0:0] NP|<NNP-VBG> -> * NNP NP|<VBG-NN> [1.0]
  |> . . . . . . . . . . . . . . . . . .| [0:0] NP-TMP -> * NNP CD [1.0]
  |> . . . . . . . . . . . . . . . . . .| [0:0] NP|<NNP-NNP> -> * NNP NP|<NNP-NNP> [0.5]
  |> . . . . . . . . . . . . . . . . . .| [0:0] NP|<NNP-NNP> -> * NNP NNP [0.5]
  |> . . . . . . . . . . . . . . . . . .| [0:0] NP-SBJ -> * NNP NNP [0.3333333333333333]
  |> . . . . . . . . . . . . . . . . . .| [0:0] NP -> * NNP NNP [0.2]
  |[-> . . . . . . . . . . . . . . . . .| [0:1] NP|<NNP-VBG> -> NNP * NP|<VBG-NN> [0.07142857142857142]
  |[-> . . . . . . . . . . . . . . . . .| [0:1] NP-TMP -> NNP * CD [0.07142857142857142]
  |> . . . . . . . . . . . . . . . . . .| [0:0] NNP -> * 'Pierre' [0.07142857142857142]
  |. . . . . . . . . . . . . . . [-] . .| [15:16] NNP -> 'Nov.' * [0.07142857142857142]
  |. . . . . . . . . . . . . . . > . . .| [15:15] NP|<NNP-VBG> -> * NNP NP|<VBG-NN> [1.0]
  |. . . . . . . . . . . . . . . > . . .| [15:15] NP-TMP -> * NNP CD [1.0]
  |. . . . . . . . . . . . . . . > . . .| [15:15] NP|<NNP-NNP> -> * NNP NP|<NNP-NNP> [0.5]
  |. . . . . . . . . . . . . . . > . . .| [15:15] NP|<NNP-NNP> -> * NNP NNP [0.5]
  |. . . . . . . . . . . . . . . > . . .| [15:15] NP-SBJ -> * NNP NNP [0.3333333333333333]
  |. . . . . . . . . . . . . . . > . . .| [15:15] NP -> * NNP NNP [0.2]
  |. . . . . . . . . . . . . . . [-> . .| [15:16] NP|<NNP-VBG> -> NNP * NP|<VBG-NN> [0.07142857142857142]
  |. . . . . . . . . . . . . . . [-> . .| [15:16] NP-TMP -> NNP * CD [0.07142857142857142]
  |. . . . . . . . . . . . . . . > . . .| [15:15] NNP -> * 'Nov.' [0.07142857142857142]
  |. . . . . . . . . . . . . . . > . . .| [15:15] NP -> * NNP NP|<NNP-NNP> [0.06666666666666667]
  |> . . . . . . . . . . . . . . . . . .| [0:0] NP -> * NNP NP|<NNP-NNP> [0.06666666666666667]
  |. . . . . . . . . . > . . . . . . . .| [10:10] NP -> * NN [0.06666666666666667]
  |. > . . . . . . . . . . . . . . . . .| [1:1] NP -> * NNP NP|<NNP-NNP> [0.06666666666666667]
  |. . . . . . . . . . . . . . > . . . .| [14:14] NP -> * NN [0.06666666666666667]
  |. . . . . . . . . . . . . > . . . . .| [13:13] NP -> * JJ NN [0.06666666666666667]
  |. . . . . > . . . . . . . . . . . . .| [5:5] NP -> * JJ NN [0.06666666666666667]
  |. . . . . . . . . . . . > . . . . . .| [12:12] NP -> * DT NN [0.06666666666666667]
  |. . . . . . . . . . . . > . . . . . .| [12:12] NP -> * DT NP|<JJ-JJ> [0.06666666666666667]
  |. . . . . . . . . . . . > . . . . . .| [12:12] NP -> * DT NP|<NNP-VBG> [0.06666666666666667]
  |. . . . . . . . . > . . . . . . . . .| [9:9] NP -> * DT NN [0.06666666666666667]
  |. . . . . . . . . > . . . . . . . . .| [9:9] NP -> * DT NP|<JJ-JJ> [0.06666666666666667]
  |. . . . . . . . . > . . . . . . . . .| [9:9] NP -> * DT NP|<NNP-VBG> [0.06666666666666667]
  |. . . . . . . . . . . . [-> . . . . .| [12:13] NP -> DT * NP|<JJ-NN> [0.05333333333333334]
  |. . . . . . . . . [-> . . . . . . . .| [9:10] NP -> DT * NP|<JJ-NN> [0.05333333333333334]
  |. [-> . . . . . . . . . . . . . . . .| [1:2] NP-SBJ -> NNP * NNP [0.047619047619047616]
  |. . . . . . . . . . . . . . . . [-> .| [16:17] NP -> CD * NNS [0.04444444444444444]
  |. . . [-> . . . . . . . . . . . . . .| [3:4] NP -> CD * NNS [0.04444444444444444]
  |. . . [---] . . . . . . . . . . . . .| [3:5] NP -> CD NNS * [0.04444444444444444]
  |. . . > . . . . . . . . . . . . . . .| [3:3] NP-SBJ-1 -> * NP NP-SBJ-1|<,-UCP> [1.0]
  |. . . > . . . . . . . . . . . . . . .| [3:3] NP-PRD -> * NP PP [1.0]
  |. . . > . . . . . . . . . . . . . . .| [3:3] ADJP -> * NP JJ [1.0]
  |. . . > . . . . . . . . . . . . . . .| [3:3] VP|<NP-PP-CLR> -> * NP VP|<PP-CLR-NP-TMP> [1.0]
  |. . . > . . . . . . . . . . . . . . .| [3:3] NP-SBJ -> * NP NP-SBJ|<,-ADJP> [0.3333333333333333]
  |. . . > . . . . . . . . . . . . . . .| [3:3] NP -> * NP NP|<,-NP> [0.06666666666666667]
  |. . . > . . . . . . . . . . . . . . .| [3:3] NP -> * NP PP [0.06666666666666667]
  |. . . [---> . . . . . . . . . . . . .| [3:5] NP-SBJ-1 -> NP * NP-SBJ-1|<,-UCP> [0.04444444444444444]
  |. . . [---> . . . . . . . . . . . . .| [3:5] NP-PRD -> NP * PP [0.04444444444444444]
  |. . . [---> . . . . . . . . . . . . .| [3:5] ADJP -> NP * JJ [0.04444444444444444]
  |. . . [---> . . . . . . . . . . . . .| [3:5] VP|<NP-PP-CLR> -> NP * VP|<PP-CLR-NP-TMP> [0.04444444444444444]
  |. . [-----] . . . . . . . . . . . . .| [2:5] NP|<,-NP> -> , NP * [0.04444444444444444]
  |. . . . . . . . . . . . . . . [-> . .| [15:16] NP|<NNP-NNP> -> NNP * NP|<NNP-NNP> [0.03571428571428571]
  |. . . . . . . . . . . . . . . [-> . .| [15:16] NP|<NNP-NNP> -> NNP * NNP [0.03571428571428571]
  |[-> . . . . . . . . . . . . . . . . .| [0:1] NP|<NNP-NNP> -> NNP * NP|<NNP-NNP> [0.03571428571428571]
  |[-> . . . . . . . . . . . . . . . . .| [0:1] NP|<NNP-NNP> -> NNP * NNP [0.03571428571428571]
  |. [-> . . . . . . . . . . . . . . . .| [1:2] NP -> NNP * NNP [0.02857142857142857]
  |. . . . . . . . . . . . [-> . . . . .| [12:13] NP -> DT * NN [0.02666666666666667]
  |. . . . . . . . . . . . [-> . . . . .| [12:13] NP -> DT * NP|<JJ-JJ> [0.02666666666666667]
  |. . . . . . . . . . . . [-> . . . . .| [12:13] NP -> DT * NP|<NNP-VBG> [0.02666666666666667]
  |. . . . . . . . . [-> . . . . . . . .| [9:10] NP -> DT * NN [0.02666666666666667]
  |. . . . . . . . . [-> . . . . . . . .| [9:10] NP -> DT * NP|<JJ-JJ> [0.02666666666666667]
  |. . . . . . . . . [-> . . . . . . . .| [9:10] NP -> DT * NP|<NNP-VBG> [0.02666666666666667]
  |. . . . . . . . . . . . . . . [---] .| [15:17] NP-TMP -> NNP CD * [0.023809523809523808]
  |. . . . . . . . . . . . . . . [-> . .| [15:16] NP-SBJ -> NNP * NNP [0.023809523809523808]
  |[-> . . . . . . . . . . . . . . . . .| [0:1] NP-SBJ -> NNP * NNP [0.023809523809523808]
  |. . . . . . . . . . . . . . [-] . . .| [14:15] NP -> NN * [0.019047619047619046]
  |. . . . . . . . . . . . . . > . . . .| [14:14] NP-SBJ-1 -> * NP NP-SBJ-1|<,-UCP> [1.0]
  |. . . . . . . . . . . . . . > . . . .| [14:14] NP-PRD -> * NP PP [1.0]
  |. . . . . . . . . . . . . . > . . . .| [14:14] ADJP -> * NP JJ [1.0]
  |. . . . . . . . . . . . . . > . . . .| [14:14] VP|<NP-PP-CLR> -> * NP VP|<PP-CLR-NP-TMP> [1.0]
  |. . . . . . . . . . . . . . > . . . .| [14:14] NP-SBJ -> * NP NP-SBJ|<,-ADJP> [0.3333333333333333]
  |. . . . . . . . . . . . . . > . . . .| [14:14] NP -> * NP NP|<,-NP> [0.06666666666666667]
  |. . . . . . . . . . . . . . > . . . .| [14:14] NP -> * NP PP [0.06666666666666667]
  |. . . . . . . . . . . . . . [-> . . .| [14:15] NP-SBJ-1 -> NP * NP-SBJ-1|<,-UCP> [0.019047619047619046]
  |. . . . . . . . . . . . . . [-> . . .| [14:15] NP-PRD -> NP * PP [0.019047619047619046]
  |. . . . . . . . . . . . . . [-> . . .| [14:15] ADJP -> NP * JJ [0.019047619047619046]
  |. . . . . . . . . . . . . . [-> . . .| [14:15] VP|<NP-PP-CLR> -> NP * VP|<PP-CLR-NP-TMP> [0.019047619047619046]
  |. . . . . . . . . . . . . [-> . . . .| [13:14] NP -> JJ * NN [0.019047619047619046]
  |. . . . . [-> . . . . . . . . . . . .| [5:6] NP -> JJ * NN [0.019047619047619046]
  |. . . [---> . . . . . . . . . . . . .| [3:5] NP-SBJ -> NP * NP-SBJ|<,-ADJP> [0.014814814814814812]
  |. . . . . . . . . . . . . . . [-> . .| [15:16] NP -> NNP * NNP [0.014285714285714285]
  |[-> . . . . . . . . . . . . . . . . .| [0:1] NP -> NNP * NNP [0.014285714285714285]
  |. . . [-----] . . . . . . . . . . . .| [3:6] ADJP -> NP JJ * [0.012698412698412697]
  |. . . > . . . . . . . . . . . . . . .| [3:3] UCP -> * ADJP UCP|<CC-NP> [1.0]
  |. . . > . . . . . . . . . . . . . . .| [3:3] NP-SBJ|<ADJP-,> -> * ADJP , [1.0]
  |. . . [-----> . . . . . . . . . . . .| [3:6] UCP -> ADJP * UCP|<CC-NP> [0.012698412698412697]
  |. . . [-----> . . . . . . . . . . . .| [3:6] NP-SBJ|<ADJP-,> -> ADJP * , [0.012698412698412697]
  |. . . [-------] . . . . . . . . . . .| [3:7] NP-SBJ|<ADJP-,> -> ADJP , * [0.012698412698412697]
  |. . [---------] . . . . . . . . . . .| [2:7] NP-SBJ|<,-ADJP> -> , NP-SBJ|<ADJP-,> * [0.012698412698412697]
  |. . . . . . . . . . [-] . . . . . . .| [10:11] NP -> NN * [0.009523809523809523]
  |. . . . . . . . . . > . . . . . . . .| [10:10] NP-SBJ-1 -> * NP NP-SBJ-1|<,-UCP> [1.0]
  |. . . . . . . . . . > . . . . . . . .| [10:10] NP-PRD -> * NP PP [1.0]
  |. . . . . . . . . . > . . . . . . . .| [10:10] ADJP -> * NP JJ [1.0]
  |. . . . . . . . . . > . . . . . . . .| [10:10] VP|<NP-PP-CLR> -> * NP VP|<PP-CLR-NP-TMP> [1.0]
  |. . . . . . . . . . > . . . . . . . .| [10:10] NP-SBJ -> * NP NP-SBJ|<,-ADJP> [0.3333333333333333]
  |. . . . . . . . . . > . . . . . . . .| [10:10] NP -> * NP NP|<,-NP> [0.06666666666666667]
  |. . . . . . . . . . > . . . . . . . .| [10:10] NP -> * NP PP [0.06666666666666667]
  |. . . . . . . . . . [-> . . . . . . .| [10:11] NP-SBJ-1 -> NP * NP-SBJ-1|<,-UCP> [0.009523809523809523]
  |. . . . . . . . . . [-> . . . . . . .| [10:11] NP-PRD -> NP * PP [0.009523809523809523]
  |. . . . . . . . . . [-> . . . . . . .| [10:11] ADJP -> NP * JJ [0.009523809523809523]
  |. . . . . . . . . . [-> . . . . . . .| [10:11] VP|<NP-PP-CLR> -> NP * VP|<PP-CLR-NP-TMP> [0.009523809523809523]
  |. [-> . . . . . . . . . . . . . . . .| [1:2] NP -> NNP * NP|<NNP-NNP> [0.009523809523809523]
  |. . . . . . . . . . . . . . [-> . . .| [14:15] NP-SBJ -> NP * NP-SBJ|<,-ADJP> [0.006349206349206348]
  |. . . . . . . . . . . . . [---] . . .| [13:15] NP -> JJ NN * [0.005442176870748299]
  |. . . . . . . . . . . . . > . . . . .| [13:13] NP-SBJ-1 -> * NP NP-SBJ-1|<,-UCP> [1.0]
  |. . . . . . . . . . . . . > . . . . .| [13:13] NP-PRD -> * NP PP [1.0]
  |. . . . . . . . . . . . . > . . . . .| [13:13] ADJP -> * NP JJ [1.0]
  |. . . . . . . . . . . . . > . . . . .| [13:13] VP|<NP-PP-CLR> -> * NP VP|<PP-CLR-NP-TMP> [1.0]
  |. . . . . . . . . . . . . > . . . . .| [13:13] NP-SBJ -> * NP NP-SBJ|<,-ADJP> [0.3333333333333333]
  |. . . . . . . . . . . . . > . . . . .| [13:13] NP -> * NP NP|<,-NP> [0.06666666666666667]
  |. . . . . . . . . . . . . > . . . . .| [13:13] NP -> * NP PP [0.06666666666666667]
  |. . . . . . . . . . . . . [---> . . .| [13:15] NP-SBJ-1 -> NP * NP-SBJ-1|<,-UCP> [0.005442176870748299]
  |. . . . . . . . . . . . . [---> . . .| [13:15] NP-PRD -> NP * PP [0.005442176870748299]
  |. . . . . . . . . . . . . [---> . . .| [13:15] ADJP -> NP * JJ [0.005442176870748299]
  |. . . . . . . . . . . . . [---> . . .| [13:15] VP|<NP-PP-CLR> -> NP * VP|<PP-CLR-NP-TMP> [0.005442176870748299]
  |[---] . . . . . . . . . . . . . . . .| [0:2] NP|<NNP-NNP> -> NNP NNP * [0.00510204081632653]
  |. . . . . . . . . . . . . . . [-> . .| [15:16] NP -> NNP * NP|<NNP-NNP> [0.0047619047619047615]
  |[-> . . . . . . . . . . . . . . . . .| [0:1] NP -> NNP * NP|<NNP-NNP> [0.0047619047619047615]
  |. . . . . . . . . . . . [-----] . . .| [12:15] NP -> DT NP|<JJ-NN> * [0.004353741496598639]
  |. . . . . . . . . . . . > . . . . . .| [12:12] NP-SBJ-1 -> * NP NP-SBJ-1|<,-UCP> [1.0]
  |. . . . . . . . . . . . > . . . . . .| [12:12] NP-PRD -> * NP PP [1.0]
  |. . . . . . . . . . . . > . . . . . .| [12:12] ADJP -> * NP JJ [1.0]
  |. . . . . . . . . . . . > . . . . . .| [12:12] VP|<NP-PP-CLR> -> * NP VP|<PP-CLR-NP-TMP> [1.0]
  |. . . . . . . . . . . . > . . . . . .| [12:12] NP-SBJ -> * NP NP-SBJ|<,-ADJP> [0.3333333333333333]
  |. . . . . . . . . . . . > . . . . . .| [12:12] NP -> * NP NP|<,-NP> [0.06666666666666667]
  |. . . . . . . . . . . . > . . . . . .| [12:12] NP -> * NP PP [0.06666666666666667]
  |. . . . . . . . . . . . [-----> . . .| [12:15] NP-SBJ-1 -> NP * NP-SBJ-1|<,-UCP> [0.004353741496598639]
  |. . . . . . . . . . . . [-----> . . .| [12:15] NP-PRD -> NP * PP [0.004353741496598639]
  |. . . . . . . . . . . . [-----> . . .| [12:15] ADJP -> NP * JJ [0.004353741496598639]
  |. . . . . . . . . . . . [-----> . . .| [12:15] VP|<NP-PP-CLR> -> NP * VP|<PP-CLR-NP-TMP> [0.004353741496598639]
  |. . . . . . . . . [---] . . . . . . .| [9:11] NP -> DT NN * [0.0038095238095238095]
  |. . . . . . . . . > . . . . . . . . .| [9:9] NP-SBJ-1 -> * NP NP-SBJ-1|<,-UCP> [1.0]
  |. . . . . . . . . > . . . . . . . . .| [9:9] NP-PRD -> * NP PP [1.0]
  |. . . . . . . . . > . . . . . . . . .| [9:9] ADJP -> * NP JJ [1.0]
  |. . . . . . . . . > . . . . . . . . .| [9:9] VP|<NP-PP-CLR> -> * NP VP|<PP-CLR-NP-TMP> [1.0]
  |. . . . . . . . . > . . . . . . . . .| [9:9] NP-SBJ -> * NP NP-SBJ|<,-ADJP> [0.3333333333333333]
  |. . . . . . . . . > . . . . . . . . .| [9:9] NP -> * NP NP|<,-NP> [0.06666666666666667]
  |. . . . . . . . . > . . . . . . . . .| [9:9] NP -> * NP PP [0.06666666666666667]
  |. . . . . . . . . [---> . . . . . . .| [9:11] NP-SBJ-1 -> NP * NP-SBJ-1|<,-UCP> [0.0038095238095238095]
  |. . . . . . . . . [---> . . . . . . .| [9:11] NP-PRD -> NP * PP [0.0038095238095238095]
  |. . . . . . . . . [---> . . . . . . .| [9:11] ADJP -> NP * JJ [0.0038095238095238095]
  |. . . . . . . . . [---> . . . . . . .| [9:11] VP|<NP-PP-CLR> -> NP * VP|<PP-CLR-NP-TMP> [0.0038095238095238095]
  |[---] . . . . . . . . . . . . . . . .| [0:2] NP-SBJ -> NNP NNP * [0.0034013605442176865]
  |> . . . . . . . . . . . . . . . . . .| [0:0] S  -> * NP-SBJ S|<VP-.> [0.5]
  |> . . . . . . . . . . . . . . . . . .| [0:0] S  -> * NP-SBJ NP-PRD [0.25]
  |. . . . . . . . . . [-> . . . . . . .| [10:11] NP-SBJ -> NP * NP-SBJ|<,-ADJP> [0.003174603174603174]
  |. . . [---> . . . . . . . . . . . . .| [3:5] NP -> NP * NP|<,-NP> [0.0029629629629629624]
  |. . . [---> . . . . . . . . . . . . .| [3:5] NP -> NP * PP [0.0029629629629629624]
  |[---] . . . . . . . . . . . . . . . .| [0:2] NP -> NNP NNP * [0.002040816326530612]
  |> . . . . . . . . . . . . . . . . . .| [0:0] NP-SBJ-1 -> * NP NP-SBJ-1|<,-UCP> [1.0]
  |> . . . . . . . . . . . . . . . . . .| [0:0] NP-PRD -> * NP PP [1.0]
  |> . . . . . . . . . . . . . . . . . .| [0:0] ADJP -> * NP JJ [1.0]
  |> . . . . . . . . . . . . . . . . . .| [0:0] VP|<NP-PP-CLR> -> * NP VP|<PP-CLR-NP-TMP> [1.0]
  |> . . . . . . . . . . . . . . . . . .| [0:0] NP-SBJ -> * NP NP-SBJ|<,-ADJP> [0.3333333333333333]
  |> . . . . . . . . . . . . . . . . . .| [0:0] NP -> * NP NP|<,-NP> [0.06666666666666667]
  |> . . . . . . . . . . . . . . . . . .| [0:0] NP -> * NP PP [0.06666666666666667]
  |[---> . . . . . . . . . . . . . . . .| [0:2] NP-SBJ-1 -> NP * NP-SBJ-1|<,-UCP> [0.002040816326530612]
  |[---> . . . . . . . . . . . . . . . .| [0:2] NP-PRD -> NP * PP [0.002040816326530612]
  |[---> . . . . . . . . . . . . . . . .| [0:2] ADJP -> NP * JJ [0.002040816326530612]
  |[---> . . . . . . . . . . . . . . . .| [0:2] VP|<NP-PP-CLR> -> NP * VP|<PP-CLR-NP-TMP> [0.002040816326530612]
  |. . . . . . . . . . . . . [---> . . .| [13:15] NP-SBJ -> NP * NP-SBJ|<,-ADJP> [0.0018140589569160996]
  |[---> . . . . . . . . . . . . . . . .| [0:2] S  -> NP-SBJ * S|<VP-.> [0.0017006802721088433]
  |. . . . . . . . . . . . [-----> . . .| [12:15] NP-SBJ -> NP * NP-SBJ|<,-ADJP> [0.0014512471655328796]
  |. . . . . . . . . [---> . . . . . . .| [9:11] NP-SBJ -> NP * NP-SBJ|<,-ADJP> [0.0012698412698412698]
  |. . . . . . . . . . . . . . [-> . . .| [14:15] NP -> NP * NP|<,-NP> [0.0012698412698412696]
  |. . . . . . . . . . . . . . [-> . . .| [14:15] NP -> NP * PP [0.0012698412698412696]
  |. . . . . . . . . . . [-------] . . .| [11:15] PP -> IN NP * [0.0010884353741496598]
  |. . . . . . . . . . . [-------] . . .| [11:15] PP-CLR -> IN NP * [0.0010884353741496598]
  |. . . . . . . . . . . > . . . . . . .| [11:11] VP|<PP-CLR-NP-TMP> -> * PP-CLR NP-TMP [1.0]
  |. . . . . . . . . . . [-------> . . .| [11:15] VP|<PP-CLR-NP-TMP> -> PP-CLR * NP-TMP [0.0010884353741496598]
  |[---> . . . . . . . . . . . . . . . .| [0:2] S  -> NP-SBJ * NP-PRD [0.0008503401360544216]
  |[---> . . . . . . . . . . . . . . . .| [0:2] NP-SBJ -> NP * NP-SBJ|<,-ADJP> [0.0006802721088435373]
  |. . . . . . . . . . [-> . . . . . . .| [10:11] NP -> NP * NP|<,-NP> [0.0006349206349206348]
  |. . . . . . . . . . [-> . . . . . . .| [10:11] NP -> NP * PP [0.0006349206349206348]
  |. . . . . . . . . . . . . [---> . . .| [13:15] NP -> NP * NP|<,-NP> [0.0003628117913832199]
  |. . . . . . . . . . . . . [---> . . .| [13:15] NP -> NP * PP [0.0003628117913832199]
  |. . . . . . . . . . . . [-----> . . .| [12:15] NP -> NP * NP|<,-NP> [0.00029024943310657596]
  |. . . . . . . . . . . . [-----> . . .| [12:15] NP -> NP * PP [0.00029024943310657596]
  |. . . . . . . . . [---> . . . . . . .| [9:11] NP -> NP * NP|<,-NP> [0.00025396825396825396]
  |. . . . . . . . . [---> . . . . . . .| [9:11] NP -> NP * PP [0.00025396825396825396]
  |[---> . . . . . . . . . . . . . . . .| [0:2] NP -> NP * NP|<,-NP> [0.00013605442176870745]
  |[---> . . . . . . . . . . . . . . . .| [0:2] NP -> NP * PP [0.00013605442176870745]
  |. . . . . . . . . . . [-----------] .| [11:17] VP|<PP-CLR-NP-TMP> -> PP-CLR NP-TMP * [2.591512795594428e-05]
  |. . . . . . . . . . [---------] . . .| [10:15] NP-PRD -> NP PP * [1.0366051182377711e-05]
  |[-------------] . . . . . . . . . . .| [0:7] NP-SBJ -> NP NP-SBJ|<,-ADJP> * [8.638375985314757e-06]
  |[---------] . . . . . . . . . . . . .| [0:5] NP -> NP NP|<,-NP> * [6.04686318972033e-06]
  |[---------> . . . . . . . . . . . . .| [0:5] NP-SBJ-1 -> NP * NP-SBJ-1|<,-UCP> [6.04686318972033e-06]
  |[---------> . . . . . . . . . . . . .| [0:5] NP-PRD -> NP * PP [6.04686318972033e-06]
  |[---------> . . . . . . . . . . . . .| [0:5] ADJP -> NP * JJ [6.04686318972033e-06]
  |[---------> . . . . . . . . . . . . .| [0:5] VP|<NP-PP-CLR> -> NP * VP|<PP-CLR-NP-TMP> [6.04686318972033e-06]
  |[-------------> . . . . . . . . . . .| [0:7] S  -> NP-SBJ * S|<VP-.> [4.319187992657379e-06]
  |. . . . . . . . . [-----------] . . .| [9:15] NP-PRD -> NP PP * [4.146420472951085e-06]
  |[-------------> . . . . . . . . . . .| [0:7] S  -> NP-SBJ * NP-PRD [2.1595939963286893e-06]
  |[---------> . . . . . . . . . . . . .| [0:5] NP-SBJ -> NP * NP-SBJ|<,-ADJP> [2.01562106324011e-06]
  |[-----------] . . . . . . . . . . . .| [0:6] ADJP -> NP JJ * [1.7276751970629514e-06]
  |> . . . . . . . . . . . . . . . . . .| [0:0] UCP -> * ADJP UCP|<CC-NP> [1.0]
  |> . . . . . . . . . . . . . . . . . .| [0:0] NP-SBJ|<ADJP-,> -> * ADJP , [1.0]
  |[-----------> . . . . . . . . . . . .| [0:6] UCP -> ADJP * UCP|<CC-NP> [1.7276751970629514e-06]
  |[-----------> . . . . . . . . . . . .| [0:6] NP-SBJ|<ADJP-,> -> ADJP * , [1.7276751970629514e-06]
  |[-------------] . . . . . . . . . . .| [0:7] NP-SBJ|<ADJP-,> -> ADJP , * [1.7276751970629514e-06]
  |. . . . . . . . . . [---------] . . .| [10:15] NP -> NP PP * [6.910700788251807e-07]
  |. . . . . . . . . . [---------> . . .| [10:15] NP-SBJ-1 -> NP * NP-SBJ-1|<,-UCP> [6.910700788251807e-07]
  |. . . . . . . . . . [---------> . . .| [10:15] NP-PRD -> NP * PP [6.910700788251807e-07]
  |. . . . . . . . . . [---------> . . .| [10:15] ADJP -> NP * JJ [6.910700788251807e-07]
  |. . . . . . . . . . [---------> . . .| [10:15] VP|<NP-PP-CLR> -> NP * VP|<PP-CLR-NP-TMP> [6.910700788251807e-07]
  |[---------> . . . . . . . . . . . . .| [0:5] NP -> NP * NP|<,-NP> [4.0312421264802203e-07]
  |[---------> . . . . . . . . . . . . .| [0:5] NP -> NP * PP [4.0312421264802203e-07]
  |. . . . . . . . . [-----------] . . .| [9:15] NP -> NP PP * [2.764280315300723e-07]
  |. . . . . . . . . [-----------> . . .| [9:15] NP-SBJ-1 -> NP * NP-SBJ-1|<,-UCP> [2.764280315300723e-07]
  |. . . . . . . . . [-----------> . . .| [9:15] NP-PRD -> NP * PP [2.764280315300723e-07]
  |. . . . . . . . . [-----------> . . .| [9:15] ADJP -> NP * JJ [2.764280315300723e-07]
  |. . . . . . . . . [-----------> . . .| [9:15] VP|<NP-PP-CLR> -> NP * VP|<PP-CLR-NP-TMP> [2.764280315300723e-07]
  |. . . . . . . . . . [-------------] .| [10:17] VP|<NP-PP-CLR> -> NP VP|<PP-CLR-NP-TMP> * [2.4681074243756453e-07]
  |. . . . . . . . . . [---------> . . .| [10:15] NP-SBJ -> NP * NP-SBJ|<,-ADJP> [2.303566929417269e-07]
  |. . . . . . . . . [---------------] .| [9:17] VP|<NP-PP-CLR> -> NP VP|<PP-CLR-NP-TMP> * [9.872429697502583e-08]
  |. . . . . . . . . [-----------> . . .| [9:15] NP-SBJ -> NP * NP-SBJ|<,-ADJP> [9.214267717669077e-08]
  |. . . . . . . . . . [---------> . . .| [10:15] NP -> NP * NP|<,-NP> [4.607133858834538e-08]
  |. . . . . . . . . . [---------> . . .| [10:15] NP -> NP * PP [4.607133858834538e-08]
  |. . . . . . . . [-----------------] .| [8:17] VP -> VB VP|<NP-PP-CLR> * [1.9744859395005166e-08]
  |. . . . . . . . > . . . . . . . . . .| [8:8] S|<VP-.> -> * VP . [1.0]
  |. . . . . . . . [-----------------> .| [8:17] S|<VP-.> -> VP * . [1.9744859395005166e-08]
  |. . . . . . . . [-------------------]| [8:18] S|<VP-.> -> VP . * [1.9744859395005166e-08]
  |. . . . . . . . . [-----------> . . .| [9:15] NP -> NP * NP|<,-NP> [1.8428535435338155e-08]
  |. . . . . . . . . [-----------> . . .| [9:15] NP -> NP * PP [1.8428535435338155e-08]
  |. . . . . . . [-------------------] .| [7:17] VP -> MD VP * [3.948971879001034e-09]
  |. . . . . . . > . . . . . . . . . . .| [7:7] S|<VP-.> -> * VP . [1.0]
  |. . . . . . . [-------------------> .| [7:17] S|<VP-.> -> VP * . [3.948971879001034e-09]
  |. . . . . . . [---------------------]| [7:18] S|<VP-.> -> VP . * [3.948971879001034e-09]
  |[===================================]| [0:18] S  -> NP-SBJ S|<VP-.> * [1.705635192312291e-14]
(S
  (NP-SBJ
    (NP (NNP Pierre) (NNP Vinken))
    (NP-SBJ|<,-ADJP>
      (, ,)
      (NP-SBJ|<ADJP-,>
        (ADJP (NP (CD 61) (NNS years)) (JJ old))
        (, ,))))
  (S|<VP-.>
    (VP
      (MD will)
      (VP
        (VB join)
        (VP|<NP-PP-CLR>
          (NP (DT the) (NN board))
          (VP|<PP-CLR-NP-TMP>
            (PP-CLR
              (IN as)
              (NP
                (DT a)
                (NP|<JJ-NN>
                  (JJ nonexecutive)
                  (NN director))))
            (NP-TMP (NNP Nov.) (CD 29))))))
    (. .))) (p=1.70564e-14)

The parsers are defined in module nltk.parse.

In [23]:
import sys, time
from nltk import tokenize
from nltk.grammar import toy_pcfg1
from nltk.parse import pchart
from nltk.parse import ViterbiParser

demos = [('I saw John with my telescope', toy_pcfg1)]
sent, grammar = demos[0]

# Tokenize the sentence.
tokens = sent.split()

# Define a list of parsers.  We'll use all parsers.
parsers = [
ViterbiParser(grammar),
pchart.InsideChartParser(grammar),
pchart.RandomChartParser(grammar),
pchart.UnsortedChartParser(grammar),
pchart.LongestChartParser(grammar),
pchart.InsideChartParser(grammar, beam_size = len(tokens)+1)
]
In [24]:
# Run the parsers on the tokenized sentence.
from functools import reduce
times = []
average_p = []
num_parses = []
all_parses = {}
for parser in parsers:
    print('\ns: %s\nparser: %s\ngrammar: %s' % (sent,parser,grammar))
    parser.trace(3)
    t = time.time()
    parses = parser.parse_all(tokens)
    times.append(time.time()-t)
    if parses: 
        lp = len(parses)
        p = reduce(lambda a,b:a+b.prob(), parses, 0.0)
    else: 
        p = 0
    average_p.append(p)
    num_parses.append(len(parses))
    for p in parses: 
        all_parses[p.freeze()] = 1

# Print summary statistics
print()
print('-------------------------+------------------------------------------')
print('   Parser           Beam | Time (secs)   # Parses   Average P(parse)')
print('-------------------------+------------------------------------------')
for i in range(len(parsers)):
    print('%19s %4d |%11.4f%11d%19.14f' % (parsers[i].__class__.__name__,
      getattr(parsers[0], "beam_size", 0),
      times[i], 
      num_parses[i], 
      average_p[i]))
parses = all_parses.keys()
if parses: 
    p = reduce(lambda a,b:a+b.prob(), parses, 0)/len(parses)
else: 
    p = 0
print('-------------------------+------------------------------------------')
print('%19s      |%11s%11d%19.14f' % ('(All Parses)', 'n/a', len(parses), p))
print()

for parse in parses:
    print(parse)
s: I saw John with my telescope
parser: <ViterbiParser for <Grammar with 17 productions>>
grammar: Grammar with 17 productions (start state = S)
    S -> NP VP [1.0]
    NP -> Det N [0.5]
    NP -> NP PP [0.25]
    NP -> 'John' [0.1]
    NP -> 'I' [0.15]
    Det -> 'the' [0.8]
    Det -> 'my' [0.2]
    N -> 'man' [0.5]
    N -> 'telescope' [0.5]
    VP -> VP PP [0.1]
    VP -> V NP [0.7]
    VP -> V [0.2]
    V -> 'ate' [0.35]
    V -> 'saw' [0.65]
    PP -> P NP [1.0]
    P -> 'with' [0.61]
    P -> 'under' [0.39]
Inserting tokens into the most likely constituents table...
   Insert: |=.....| I
   Insert: |.=....| saw
   Insert: |..=...| John
   Insert: |...=..| with
   Insert: |....=.| my
   Insert: |.....=| telescope
Finding the most likely constituents spanning 1 text elements...
   Insert: |=.....| NP -> 'I' [0.15]                0.1500000000 
   Insert: |.=....| V -> 'saw' [0.65]               0.6500000000 
   Insert: |.=....| VP -> V [0.2]                   0.1300000000 
   Insert: |..=...| NP -> 'John' [0.1]              0.1000000000 
   Insert: |...=..| P -> 'with' [0.61]              0.6100000000 
   Insert: |....=.| Det -> 'my' [0.2]               0.2000000000 
   Insert: |.....=| N -> 'telescope' [0.5]          0.5000000000 
Finding the most likely constituents spanning 2 text elements...
   Insert: |==....| S -> NP VP [1.0]                0.0195000000 
   Insert: |.==...| VP -> V NP [0.7]                0.0455000000 
   Insert: |....==| NP -> Det N [0.5]               0.0500000000 
Finding the most likely constituents spanning 3 text elements...
   Insert: |===...| S -> NP VP [1.0]                0.0068250000 
   Insert: |...===| PP -> P NP [1.0]                0.0305000000 
Finding the most likely constituents spanning 4 text elements...
   Insert: |..====| NP -> NP PP [0.25]              0.0007625000 
Finding the most likely constituents spanning 5 text elements...
   Insert: |.=====| VP -> VP PP [0.1]               0.0001387750 
   Insert: |.=====| VP -> V NP [0.7]                0.0003469375 
  Discard: |.=====| VP -> VP PP [0.1]               0.0001387750 
Finding the most likely constituents spanning 6 text elements...
   Insert: |======| S -> NP VP [1.0]                0.0000520406 

s: I saw John with my telescope
parser: <nltk.parse.pchart.InsideChartParser object at 0x0000000008088E10>
grammar: Grammar with 17 productions (start state = S)
    S -> NP VP [1.0]
    NP -> Det N [0.5]
    NP -> NP PP [0.25]
    NP -> 'John' [0.1]
    NP -> 'I' [0.15]
    Det -> 'the' [0.8]
    Det -> 'my' [0.2]
    N -> 'man' [0.5]
    N -> 'telescope' [0.5]
    VP -> VP PP [0.1]
    VP -> V NP [0.7]
    VP -> V [0.2]
    V -> 'ate' [0.35]
    V -> 'saw' [0.65]
    PP -> P NP [1.0]
    P -> 'with' [0.61]
    P -> 'under' [0.39]
  |[-] . . . . .| [0:1] 'I'                          [1.0]
  |. [-] . . . .| [1:2] 'saw'                        [1.0]
  |. . [-] . . .| [2:3] 'John'                       [1.0]
  |. . . [-] . .| [3:4] 'with'                       [1.0]
  |. . . . [-] .| [4:5] 'my'                         [1.0]
  |. . . . . [-]| [5:6] 'telescope'                  [1.0]
  |. . . . . [-]| [5:6] 'telescope'                  [1.0]
  |. . . . [-] .| [4:5] 'my'                         [1.0]
  |. . . [-] . .| [3:4] 'with'                       [1.0]
  |. . [-] . . .| [2:3] 'John'                       [1.0]
  |. [-] . . . .| [1:2] 'saw'                        [1.0]
  |[-] . . . . .| [0:1] 'I'                          [1.0]
  |. [-] . . . .| [1:2] V  -> 'saw' *                [0.65]
  |. > . . . . .| [1:1] VP -> * V NP                 [0.7]
  |. > . . . . .| [1:1] V  -> * 'saw'                [0.65]
  |. . . [-] . .| [3:4] P  -> 'with' *               [0.61]
  |. . . > . . .| [3:3] PP -> * P NP                 [1.0]
  |. . . [-> . .| [3:4] PP -> P * NP                 [0.61]
  |. . . > . . .| [3:3] P  -> * 'with'               [0.61]
  |. . . . . [-]| [5:6] N  -> 'telescope' *          [0.5]
  |. . . . . > .| [5:5] N  -> * 'telescope'          [0.5]
  |. [-> . . . .| [1:2] VP -> V * NP                 [0.45499999999999996]
  |. > . . . . .| [1:1] VP -> * V                    [0.2]
  |. . . . [-] .| [4:5] Det -> 'my' *                [0.2]
  |. . . . > . .| [4:4] NP -> * Det N                [0.5]
  |. . . . > . .| [4:4] Det -> * 'my'                [0.2]
  |[-] . . . . .| [0:1] NP -> 'I' *                  [0.15]
  |> . . . . . .| [0:0] S  -> * NP VP                [1.0]
  |> . . . . . .| [0:0] NP -> * NP PP                [0.25]
  |[-> . . . . .| [0:1] S  -> NP * VP                [0.15]
  |> . . . . . .| [0:0] NP -> * 'I'                  [0.15]
  |. [-] . . . .| [1:2] VP -> V *                    [0.13]
  |. > . . . . .| [1:1] VP -> * VP PP                [0.1]
  |. . . . [-> .| [4:5] NP -> Det * N                [0.1]
  |. . [-] . . .| [2:3] NP -> 'John' *               [0.1]
  |. . > . . . .| [2:2] S  -> * NP VP                [1.0]
  |. . > . . . .| [2:2] NP -> * NP PP                [0.25]
  |. . [-> . . .| [2:3] S  -> NP * VP                [0.1]
  |. . > . . . .| [2:2] NP -> * 'John'               [0.1]
  |. . . . [---]| [4:6] NP -> Det N *                [0.05]
  |. . . . > . .| [4:4] S  -> * NP VP                [1.0]
  |. . . . > . .| [4:4] NP -> * NP PP                [0.25]
  |. . . . [--->| [4:6] S  -> NP * VP                [0.05]
  |. [---] . . .| [1:3] VP -> V NP *                 [0.0455]
  |[-> . . . . .| [0:1] NP -> NP * PP                [0.0375]
  |. . . [-----]| [3:6] PP -> P NP *                 [0.0305]
  |. . [-> . . .| [2:3] NP -> NP * PP                [0.025]
  |[---] . . . .| [0:2] S  -> NP VP *                [0.0195]
  |. [-> . . . .| [1:2] VP -> VP * PP                [0.013000000000000001]
  |. . . . [--->| [4:6] NP -> NP * PP                [0.0125]
  |[-----] . . .| [0:3] S  -> NP VP *                [0.0068249999999999995]
  |. [---> . . .| [1:3] VP -> VP * PP                [0.00455]
  |. . [-------]| [2:6] NP -> NP PP *                [0.0007625]
  |. . [------->| [2:6] S  -> NP * VP                [0.0007625]
  |. [---------]| [1:6] VP -> V NP *                 [0.00034693749999999997]
  |. . [------->| [2:6] NP -> NP * PP                [0.000190625]
  |. [---------]| [1:6] VP -> VP PP *                [0.000138775]
  |[===========]| [0:6] S  -> NP VP *                [5.204062499999999e-05]
  |. [--------->| [1:6] VP -> VP * PP                [3.469375e-05]
  |[===========]| [0:6] S  -> NP VP *                [2.081625e-05]
  |. [--------->| [1:6] VP -> VP * PP                [1.38775e-05]

s: I saw John with my telescope
parser: <nltk.parse.pchart.RandomChartParser object at 0x0000000008088EF0>
grammar: Grammar with 17 productions (start state = S)
    S -> NP VP [1.0]
    NP -> Det N [0.5]
    NP -> NP PP [0.25]
    NP -> 'John' [0.1]
    NP -> 'I' [0.15]
    Det -> 'the' [0.8]
    Det -> 'my' [0.2]
    N -> 'man' [0.5]
    N -> 'telescope' [0.5]
    VP -> VP PP [0.1]
    VP -> V NP [0.7]
    VP -> V [0.2]
    V -> 'ate' [0.35]
    V -> 'saw' [0.65]
    PP -> P NP [1.0]
    P -> 'with' [0.61]
    P -> 'under' [0.39]
  |[-] . . . . .| [0:1] 'I'                          [1.0]
  |. [-] . . . .| [1:2] 'saw'                        [1.0]
  |. . [-] . . .| [2:3] 'John'                       [1.0]
  |. . . [-] . .| [3:4] 'with'                       [1.0]
  |. . . . [-] .| [4:5] 'my'                         [1.0]
  |. . . . . [-]| [5:6] 'telescope'                  [1.0]
  |[-] . . . . .| [0:1] 'I'                          [1.0]
  |. . . . [-] .| [4:5] 'my'                         [1.0]
  |[-] . . . . .| [0:1] NP -> 'I' *                  [0.15]
  |. [-] . . . .| [1:2] 'saw'                        [1.0]
  |. . . . > . .| [4:4] Det -> * 'my'                [0.2]
  |. . . [-] . .| [3:4] 'with'                       [1.0]
  |[-> . . . . .| [0:1] NP -> NP * PP                [0.0375]
  |> . . . . . .| [0:0] NP -> * 'I'                  [0.15]
  |. . . . . [-]| [5:6] 'telescope'                  [1.0]
  |. . . [-] . .| [3:4] P  -> 'with' *               [0.61]
  |. . [-] . . .| [2:3] 'John'                       [1.0]
  |. . > . . . .| [2:2] NP -> * 'John'               [0.1]
  |[-> . . . . .| [0:1] S  -> NP * VP                [0.15]
  |. . . . . [-]| [5:6] N  -> 'telescope' *          [0.5]
  |. . . > . . .| [3:3] PP -> * P NP                 [1.0]
  |. . [-] . . .| [2:3] NP -> 'John' *               [0.1]
  |> . . . . . .| [0:0] S  -> * NP VP                [1.0]
  |. [-] . . . .| [1:2] V  -> 'saw' *                [0.65]
  |. . [-> . . .| [2:3] NP -> NP * PP                [0.025]
  |. . > . . . .| [2:2] NP -> * NP PP                [0.25]
  |. . [-> . . .| [2:3] S  -> NP * VP                [0.1]
  |. . . . . > .| [5:5] N  -> * 'telescope'          [0.5]
  |. . . . [-] .| [4:5] Det -> 'my' *                [0.2]
  |. [-] . . . .| [1:2] VP -> V *                    [0.13]
  |. . . . [-> .| [4:5] NP -> Det * N                [0.1]
  |. . . . > . .| [4:4] NP -> * Det N                [0.5]
  |. [-> . . . .| [1:2] VP -> VP * PP                [0.013000000000000001]
  |> . . . . . .| [0:0] NP -> * NP PP                [0.25]
  |. . . [-> . .| [3:4] PP -> P * NP                 [0.61]
  |[---] . . . .| [0:2] S  -> NP VP *                [0.0195]
  |. > . . . . .| [1:1] VP -> * V NP                 [0.7]
  |. > . . . . .| [1:1] VP -> * V                    [0.2]
  |. > . . . . .| [1:1] VP -> * VP PP                [0.1]
  |. . . . [---]| [4:6] NP -> Det N *                [0.05]
  |. . . . [--->| [4:6] S  -> NP * VP                [0.05]
  |. . . . > . .| [4:4] NP -> * NP PP                [0.25]
  |. . > . . . .| [2:2] S  -> * NP VP                [1.0]
  |. > . . . . .| [1:1] V  -> * 'saw'                [0.65]
  |. [-> . . . .| [1:2] VP -> V * NP                 [0.45499999999999996]
  |. . . . > . .| [4:4] S  -> * NP VP                [1.0]
  |. . . . [--->| [4:6] NP -> NP * PP                [0.0125]
  |. . . [-----]| [3:6] PP -> P NP *                 [0.0305]
  |. [---] . . .| [1:3] VP -> V NP *                 [0.0455]
  |. . . > . . .| [3:3] P  -> * 'with'               [0.61]
  |[-----] . . .| [0:3] S  -> NP VP *                [0.0068249999999999995]
  |. [---> . . .| [1:3] VP -> VP * PP                [0.00455]
  |. [---------]| [1:6] VP -> VP PP *                [0.000138775]
  |. . [-------]| [2:6] NP -> NP PP *                [0.0007625]
  |. . [------->| [2:6] NP -> NP * PP                [0.000190625]
  |. [--------->| [1:6] VP -> VP * PP                [1.38775e-05]
  |. . [------->| [2:6] S  -> NP * VP                [0.0007625]
  |. [---------]| [1:6] VP -> V NP *                 [0.00034693749999999997]
  |. [--------->| [1:6] VP -> VP * PP                [3.469375e-05]
  |[===========]| [0:6] S  -> NP VP *                [5.204062499999999e-05]
  |[===========]| [0:6] S  -> NP VP *                [2.081625e-05]

s: I saw John with my telescope
parser: <nltk.parse.pchart.UnsortedChartParser object at 0x0000000008088B00>
grammar: Grammar with 17 productions (start state = S)
    S -> NP VP [1.0]
    NP -> Det N [0.5]
    NP -> NP PP [0.25]
    NP -> 'John' [0.1]
    NP -> 'I' [0.15]
    Det -> 'the' [0.8]
    Det -> 'my' [0.2]
    N -> 'man' [0.5]
    N -> 'telescope' [0.5]
    VP -> VP PP [0.1]
    VP -> V NP [0.7]
    VP -> V [0.2]
    V -> 'ate' [0.35]
    V -> 'saw' [0.65]
    PP -> P NP [1.0]
    P -> 'with' [0.61]
    P -> 'under' [0.39]
  |[-] . . . . .| [0:1] 'I'                          [1.0]
  |. [-] . . . .| [1:2] 'saw'                        [1.0]
  |. . [-] . . .| [2:3] 'John'                       [1.0]
  |. . . [-] . .| [3:4] 'with'                       [1.0]
  |. . . . [-] .| [4:5] 'my'                         [1.0]
  |. . . . . [-]| [5:6] 'telescope'                  [1.0]
  |. . . . . [-]| [5:6] 'telescope'                  [1.0]
  |. . . . . [-]| [5:6] N  -> 'telescope' *          [0.5]
  |. . . . . > .| [5:5] N  -> * 'telescope'          [0.5]
  |. . . . [-] .| [4:5] 'my'                         [1.0]
  |. . . . [-] .| [4:5] Det -> 'my' *                [0.2]
  |. . . . [-> .| [4:5] NP -> Det * N                [0.1]
  |. . . . [---]| [4:6] NP -> Det N *                [0.05]
  |. . . . [--->| [4:6] NP -> NP * PP                [0.0125]
  |. . . . [--->| [4:6] S  -> NP * VP                [0.05]
  |. . . . > . .| [4:4] NP -> * NP PP                [0.25]
  |. . . . > . .| [4:4] S  -> * NP VP                [1.0]
  |. . . . > . .| [4:4] NP -> * Det N                [0.5]
  |. . . . > . .| [4:4] Det -> * 'my'                [0.2]
  |. . . [-] . .| [3:4] 'with'                       [1.0]
  |. . . [-] . .| [3:4] P  -> 'with' *               [0.61]
  |. . . [-> . .| [3:4] PP -> P * NP                 [0.61]
  |. . . [-----]| [3:6] PP -> P NP *                 [0.0305]
  |. . . > . . .| [3:3] PP -> * P NP                 [1.0]
  |. . . > . . .| [3:3] P  -> * 'with'               [0.61]
  |. . [-] . . .| [2:3] 'John'                       [1.0]
  |. . [-] . . .| [2:3] NP -> 'John' *               [0.1]
  |. . [-> . . .| [2:3] NP -> NP * PP                [0.025]
  |. . [-------]| [2:6] NP -> NP PP *                [0.0007625]
  |. . [------->| [2:6] NP -> NP * PP                [0.000190625]
  |. . [------->| [2:6] S  -> NP * VP                [0.0007625]
  |. . [-> . . .| [2:3] S  -> NP * VP                [0.1]
  |. . > . . . .| [2:2] NP -> * NP PP                [0.25]
  |. . > . . . .| [2:2] S  -> * NP VP                [1.0]
  |. . > . . . .| [2:2] NP -> * 'John'               [0.1]
  |. [-] . . . .| [1:2] 'saw'                        [1.0]
  |. [-] . . . .| [1:2] V  -> 'saw' *                [0.65]
  |. [-] . . . .| [1:2] VP -> V *                    [0.13]
  |. [-> . . . .| [1:2] VP -> VP * PP                [0.013000000000000001]
  |. > . . . . .| [1:1] VP -> * VP PP                [0.1]
  |. [-> . . . .| [1:2] VP -> V * NP                 [0.45499999999999996]
  |. [---------]| [1:6] VP -> V NP *                 [0.00034693749999999997]
  |. [--------->| [1:6] VP -> VP * PP                [3.469375e-05]
  |. [---] . . .| [1:3] VP -> V NP *                 [0.0455]
  |. [---> . . .| [1:3] VP -> VP * PP                [0.00455]
  |. [---------]| [1:6] VP -> VP PP *                [0.000138775]
  |. [--------->| [1:6] VP -> VP * PP                [1.38775e-05]
  |. > . . . . .| [1:1] VP -> * V                    [0.2]
  |. > . . . . .| [1:1] VP -> * V NP                 [0.7]
  |. > . . . . .| [1:1] V  -> * 'saw'                [0.65]
  |[-] . . . . .| [0:1] 'I'                          [1.0]
  |[-] . . . . .| [0:1] NP -> 'I' *                  [0.15]
  |[-> . . . . .| [0:1] NP -> NP * PP                [0.0375]
  |[-> . . . . .| [0:1] S  -> NP * VP                [0.15]
  |[===========]| [0:6] S  -> NP VP *                [2.081625e-05]
  |[===========]| [0:6] S  -> NP VP *                [5.204062499999999e-05]
  |[-----] . . .| [0:3] S  -> NP VP *                [0.0068249999999999995]
  |[---] . . . .| [0:2] S  -> NP VP *                [0.0195]
  |> . . . . . .| [0:0] NP -> * NP PP                [0.25]
  |> . . . . . .| [0:0] S  -> * NP VP                [1.0]
  |> . . . . . .| [0:0] NP -> * 'I'                  [0.15]

s: I saw John with my telescope
parser: <nltk.parse.pchart.LongestChartParser object at 0x0000000008088C50>
grammar: Grammar with 17 productions (start state = S)
    S -> NP VP [1.0]
    NP -> Det N [0.5]
    NP -> NP PP [0.25]
    NP -> 'John' [0.1]
    NP -> 'I' [0.15]
    Det -> 'the' [0.8]
    Det -> 'my' [0.2]
    N -> 'man' [0.5]
    N -> 'telescope' [0.5]
    VP -> VP PP [0.1]
    VP -> V NP [0.7]
    VP -> V [0.2]
    V -> 'ate' [0.35]
    V -> 'saw' [0.65]
    PP -> P NP [1.0]
    P -> 'with' [0.61]
    P -> 'under' [0.39]
  |[-] . . . . .| [0:1] 'I'                          [1.0]
  |. [-] . . . .| [1:2] 'saw'                        [1.0]
  |. . [-] . . .| [2:3] 'John'                       [1.0]
  |. . . [-] . .| [3:4] 'with'                       [1.0]
  |. . . . [-] .| [4:5] 'my'                         [1.0]
  |. . . . . [-]| [5:6] 'telescope'                  [1.0]
  |. . . . . [-]| [5:6] 'telescope'                  [1.0]
  |. . . . . [-]| [5:6] N  -> 'telescope' *          [0.5]
  |. . . . [-] .| [4:5] 'my'                         [1.0]
  |. . . . [-] .| [4:5] Det -> 'my' *                [0.2]
  |. . . . [-> .| [4:5] NP -> Det * N                [0.1]
  |. . . . [---]| [4:6] NP -> Det N *                [0.05]
  |. . . . [--->| [4:6] NP -> NP * PP                [0.0125]
  |. . . . [--->| [4:6] S  -> NP * VP                [0.05]
  |. . . [-] . .| [3:4] 'with'                       [1.0]
  |. . . [-] . .| [3:4] P  -> 'with' *               [0.61]
  |. . . [-> . .| [3:4] PP -> P * NP                 [0.61]
  |. . . [-----]| [3:6] PP -> P NP *                 [0.0305]
  |. . [-] . . .| [2:3] 'John'                       [1.0]
  |. . [-] . . .| [2:3] NP -> 'John' *               [0.1]
  |. . [-> . . .| [2:3] NP -> NP * PP                [0.025]
  |. . [-------]| [2:6] NP -> NP PP *                [0.0007625]
  |. . [------->| [2:6] NP -> NP * PP                [0.000190625]
  |. . [------->| [2:6] S  -> NP * VP                [0.0007625]
  |. . [-> . . .| [2:3] S  -> NP * VP                [0.1]
  |. [-] . . . .| [1:2] 'saw'                        [1.0]
  |. [-] . . . .| [1:2] V  -> 'saw' *                [0.65]
  |. [-] . . . .| [1:2] VP -> V *                    [0.13]
  |. [-> . . . .| [1:2] VP -> VP * PP                [0.013000000000000001]
  |. [-> . . . .| [1:2] VP -> V * NP                 [0.45499999999999996]
  |. [---------]| [1:6] VP -> V NP *                 [0.00034693749999999997]
  |. [--------->| [1:6] VP -> VP * PP                [3.469375e-05]
  |. [---] . . .| [1:3] VP -> V NP *                 [0.0455]
  |. [---> . . .| [1:3] VP -> VP * PP                [0.00455]
  |. [---------]| [1:6] VP -> VP PP *                [0.000138775]
  |. [--------->| [1:6] VP -> VP * PP                [1.38775e-05]
  |[-] . . . . .| [0:1] 'I'                          [1.0]
  |[-] . . . . .| [0:1] NP -> 'I' *                  [0.15]
  |[-> . . . . .| [0:1] NP -> NP * PP                [0.0375]
  |[-> . . . . .| [0:1] S  -> NP * VP                [0.15]
  |[===========]| [0:6] S  -> NP VP *                [2.081625e-05]
  |[===========]| [0:6] S  -> NP VP *                [5.204062499999999e-05]
  |[-----] . . .| [0:3] S  -> NP VP *                [0.0068249999999999995]
  |[---] . . . .| [0:2] S  -> NP VP *                [0.0195]
  |> . . . . . .| [0:0] NP -> * NP PP                [0.25]
  |> . . . . . .| [0:0] S  -> * NP VP                [1.0]
  |> . . . . . .| [0:0] NP -> * 'I'                  [0.15]
  |. > . . . . .| [1:1] VP -> * VP PP                [0.1]
  |. > . . . . .| [1:1] VP -> * V                    [0.2]
  |. > . . . . .| [1:1] VP -> * V NP                 [0.7]
  |. > . . . . .| [1:1] V  -> * 'saw'                [0.65]
  |. . > . . . .| [2:2] NP -> * NP PP                [0.25]
  |. . > . . . .| [2:2] S  -> * NP VP                [1.0]
  |. . > . . . .| [2:2] NP -> * 'John'               [0.1]
  |. . . > . . .| [3:3] PP -> * P NP                 [1.0]
  |. . . > . . .| [3:3] P  -> * 'with'               [0.61]
  |. . . . > . .| [4:4] NP -> * NP PP                [0.25]
  |. . . . > . .| [4:4] S  -> * NP VP                [1.0]
  |. . . . > . .| [4:4] NP -> * Det N                [0.5]
  |. . . . > . .| [4:4] Det -> * 'my'                [0.2]
  |. . . . . > .| [5:5] N  -> * 'telescope'          [0.5]

s: I saw John with my telescope
parser: <nltk.parse.pchart.InsideChartParser object at 0x00000000080887B8>
grammar: Grammar with 17 productions (start state = S)
    S -> NP VP [1.0]
    NP -> Det N [0.5]
    NP -> NP PP [0.25]
    NP -> 'John' [0.1]
    NP -> 'I' [0.15]
    Det -> 'the' [0.8]
    Det -> 'my' [0.2]
    N -> 'man' [0.5]
    N -> 'telescope' [0.5]
    VP -> VP PP [0.1]
    VP -> V NP [0.7]
    VP -> V [0.2]
    V -> 'ate' [0.35]
    V -> 'saw' [0.65]
    PP -> P NP [1.0]
    P -> 'with' [0.61]
    P -> 'under' [0.39]
  |[-] . . . . .| [0:1] 'I'                          [1.0]
  |. [-] . . . .| [1:2] 'saw'                        [1.0]
  |. . [-] . . .| [2:3] 'John'                       [1.0]
  |. . . [-] . .| [3:4] 'with'                       [1.0]
  |. . . . [-] .| [4:5] 'my'                         [1.0]
  |. . . . . [-]| [5:6] 'telescope'                  [1.0]
  |. . . . . [-]| [5:6] 'telescope'                  [1.0]
  |. . . . [-] .| [4:5] 'my'                         [1.0]
  |. . . . > . .| [4:4] Det -> * 'my'                [DISCARDED]
  |. . . [-] . .| [3:4] 'with'                       [1.0]
  |. . . . [-] .| [4:5] Det -> 'my' *                [DISCARDED]
  |. . [-] . . .| [2:3] 'John'                       [1.0]
  |. . > . . . .| [2:2] NP -> * 'John'               [DISCARDED]
  |. [-] . . . .| [1:2] 'saw'                        [1.0]
  |. . [-] . . .| [2:3] NP -> 'John' *               [DISCARDED]
  |[-] . . . . .| [0:1] 'I'                          [1.0]
  |> . . . . . .| [0:0] NP -> * 'I'                  [DISCARDED]
  |. [-] . . . .| [1:2] V  -> 'saw' *                [0.65]
  |. [-] . . . .| [1:2] VP -> V *                    [DISCARDED]
  |[-] . . . . .| [0:1] NP -> 'I' *                  [DISCARDED]
  |. > . . . . .| [1:1] VP -> * V                    [DISCARDED]
  |. > . . . . .| [1:1] VP -> * V NP                 [0.7]
  |. > . . . . .| [1:1] V  -> * 'saw'                [0.65]
  |. . . [-] . .| [3:4] P  -> 'with' *               [0.61]
  |. . . > . . .| [3:3] PP -> * P NP                 [1.0]
  |. . . [-> . .| [3:4] PP -> P * NP                 [0.61]
  |. . . > . . .| [3:3] P  -> * 'with'               [0.61]
  |. . . . . [-]| [5:6] N  -> 'telescope' *          [0.5]
  |. . . . . > .| [5:5] N  -> * 'telescope'          [0.5]
  |. [-> . . . .| [1:2] VP -> V * NP                 [0.45499999999999996]
  |. [---] . . .| [1:3] VP -> V NP *                 [0.0455]
  |. > . . . . .| [1:1] VP -> * VP PP                [0.1]
  |. [-> . . . .| [1:2] VP -> VP * PP                [0.013000000000000001]
  |. [---> . . .| [1:3] VP -> VP * PP                [0.00455]

-------------------------+------------------------------------------
   Parser           Beam | Time (secs)   # Parses   Average P(parse)
-------------------------+------------------------------------------
      ViterbiParser    0 |     0.0050          1   0.00005204062500
  InsideChartParser    0 |     0.0080          2   0.00007285687500
  RandomChartParser    0 |     0.0080          2   0.00007285687500
UnsortedChartParser    0 |     0.0070          2   0.00007285687500
 LongestChartParser    0 |     0.0080          2   0.00007285687500
  InsideChartParser    0 |     0.0030          0   0.00000000000000
-------------------------+------------------------------------------
       (All Parses)      |        n/a          2   0.00003642843750

(S
  (NP I)
  (VP
    (VP (V saw) (NP John))
    (PP (P with) (NP (Det my) (N telescope))))) [2.081625e-05]
(S
  (NP I)
  (VP
    (V saw)
    (NP
      (NP John)
      (PP (P with) (NP (Det my) (N telescope)))))) [5.204062499999999e-05]
In [ ]: