def demo():
 from nltk import Tree, ProbabilisticTree
 s = u'(S (NP (DT the) (NN cat)) (VP (VBD ate) (NP (DT a) (NN cookie))))'
 t = Tree.fromstring(s)
 print(u'Convert bracketed string into tree:')
 print(t)
 print(t.__repr__())
 print(u'Display tree properties:')
 print(t.label())
 print(t[0])
 print(t[1])
 print(t.height())
 print(t.leaves())
 print(t[1])
 print(t[(1, 1)])
 print(t[(1, 1, 0)])
 the_cat = t[0]
 the_cat.insert(1, Tree.fromstring(u'(JJ big)'))
 print(u'Tree modification:')
 print(t)
 t[(1, 1, 1)] = Tree.fromstring(u'(NN cake)')
 print(t)
 print()
 print(u'Collapse unary:')
 t.collapse_unary()
 print(t)
 print(u'Chomsky normal form:')
 t.chomsky_normal_form()
 print(t)
 print()
 pt = ProbabilisticTree(u'x', [u'y', u'z'], prob=0.5)
 print(u'Probabilistic Tree:')
 print(pt)
 print()
 t = Tree.fromstring(t.pformat())
 print(u'Convert tree to bracketed string and back again:')
 print(t)
 print()
 print(u'LaTeX output:')
 print(t.pformat_latex_qtree())
 print()
 print(u'Production output:')
 print(t.productions())
 print()
 t.set_label((u'test', 3))
 print(t)

def demo ( ) : from nltk import Tree , ProbabilisticTree s = u'(S (NP (DT the) (NN cat)) (VP (VBD ate) (NP (DT a) (NN cookie))))' t = Tree . fromstring ( s ) print ( u'Convert bracketed string into tree:' ) print ( t ) print ( t . __repr__ ( ) ) print ( u'Display tree properties:' ) print ( t . label ( ) ) print ( t [ 0 ] ) print ( t [ 1 ] ) print ( t . height ( ) ) print ( t . leaves ( ) ) print ( t [ 1 ] ) print ( t [ ( 1 , 1 ) ] ) print ( t [ ( 1 , 1 , 0 ) ] ) the_cat = t [ 0 ] the_cat . insert ( 1 , Tree . fromstring ( u'(JJ big)' ) ) print ( u'Tree modification:' ) print ( t ) t [ ( 1 , 1 , 1 ) ] = Tree . fromstring ( u'(NN cake)' ) print ( t ) print ( ) print ( u'Collapse unary:' ) t . collapse_unary ( ) print ( t ) print ( u'Chomsky normal form:' ) t . chomsky_normal_form ( ) print ( t ) print ( ) pt = ProbabilisticTree ( u'x' , [ u'y' , u'z' ] , prob = 0.5 ) print ( u'Probabilistic Tree:' ) print ( pt ) print ( ) t = Tree . fromstring ( t . pformat ( ) ) print ( u'Convert tree to bracketed string and back again:' ) print ( t ) print ( ) print ( u'LaTeX output:' ) print ( t . pformat_latex_qtree ( ) ) print ( ) print ( u'Production output:' ) print ( t . productions ( ) ) print ( ) t . set_label ( ( u'test' , 3 ) ) print ( t )
a demonstration of the porter stemmer on a sample from the penn treebank corpus .