Example #1
0
def demo():
      """
      This performs a demo of the main functionalities implemented in this module.
      It may be used as a starting point for developers wishing to reuse the functionalities of this module
      """
      import fastptbparser as parser

      tree = parser.parse_line('(S (NP (D the) (N cat)) (VP (V sleeps) (PP (P on) (NP (D the) (N mat))))(ADVP (ADV really))(PONCT .))')
      print "<A sentence>"
      print tree.do_sentence_string()
      print 
      print "<The PoS tags in Brown format>"
      print tree.do_tag_string(tagsep="/")
      print
      print "<The PoS tags in Database format>"
      print tree.do_tag_string(tagsep="\t",wordsep="\n")
      print
      print "<A parse tree (PTB style, one line flat)>"
      print tree.do_flat_string()
      print
      print "<A parse tree with dummy root (PTB style, multiline indented)>"
      tree = add_dummy_root(tree)
      print tree
      print
      print "<A parse tree with head annotation (PTB style, multiline indented)>"
      tree = parser.parse_line("(SENT (NP-SUJ (D le) (NC chat) (ADJ noir) (PP (P de) (NP (D la) (NC voisine)))) (VN (V dort)) (PP-MOD (P sur) (NP (D le) (NC paillasson))))",parse_symbols=True)
      tree.annotate_all(ftb4_fixer(),ftb_symset4())
      print tree
      print
      print "<A parse tree in French Treebank XML like format>"
      print TreebankTree(tree,index=10).do_xml_string()
      print
      print "<Dependency triples extracted from the tree>"
      dg = tree.build_dependency_graph()
      print dg.triples2string(sorted=True)
      print
      print "<A diff illustrated>" 
      treea = parser.parse_line('(S (NP (D the) (N cat)) (VP (V sleeps) (PP (P on) (NP (D the) (N mat)))))')
      treeb = parser.parse_line('(S (NP (D the) (N cat)) (VP (V sleeps)) (PP (P on) (NP (D the) (N mat))))')
      print 'A:',treea.do_flat_string()
      print 'B:',treeb.do_flat_string()
      print
      (common,aspec,bspec) = tree_diff(treea,treeb)
      print 'Intersection :',', '.join(map(lambda x:x[0]+'|'+str(x[1])+'|'+str(x[2]),common))
      print 'A diffs :', ', '.join(map(lambda x:x[0]+'|'+str(x[1])+'|'+str(x[2]),aspec))
      print 'B diffs :',', '.join(map(lambda x:x[0]+'|'+str(x[1])+'|'+str(x[2]),bspec))
Example #2
0
line = instream.readline()
treeid = 0
# whether to decode functional annotations in node symbols (NP-SUJ)
parse_symbols = (in_format == 'ptbfunc')

while line:
    line = line.strip()
    if readtreeids:
        (treeid, line) = line.split('\t',1)
    else:
        treeid = treeid+1
    if not line:
        print ''
        continue
    # read bracketed tree
    tree = fastptbparser.parse_line(line, parse_symbols=parse_symbols)
            
    # head annotation and conversion
    depparse = DepParse(treeid,
                        labelledtree_2_depgraph(tree, tagfixer, headrules))

    # if labeled dependencies are required
    if labeled:
        #if in_format == 'ptb':
            #TODO HERE : call functional role labelling
            #print "FRL"

        # Inference of remaining underspecified dependency labels
        depparse.depgraph.infer_deplabels()

    if out_format == 'pivot':