def to_constituent(self, done=None): """ Overwrite original constituent (self.const) with its xbar version (self). """ if done is None: done = {} parts = [] if self.part0: if self.part0 in done: p0 = done[self.part0] else: p0 = self.part0.to_constituent(done) parts.append(p0) if self.part1: if self.part1 in done: p1 = done[self.part1] else: p1 = self.part1.to_constituent(done) parts.append(p1) if parts: self.const.label = self.label self.const.features = [] self.const.parts = parts else: head = Constituent(label=self.label, features=self.features) self.const.label = self.category self.const.features = [] self.const.parts = [head] done[self] = self.const return self.const
def checkpoint(self, derivation): """ Here we can output, pause or otherwise intercept the parsing process """ dtree = DTree.dnodes_to_dtree(derivation.results, all_features=True) #input() if in_kataja: self.forest.derivation_steps.save_and_create_derivation_step( [dtree]) else: print('******* dtree *******') pprint.pprint(dtree)
def checkpoint(self, derivation): """ Here we can output, pause or otherwise intercept the parsing process """ dtree = DTree.dnodes_to_dtree(derivation.results, all_features=True, dtrees=self.dtrees) #input() if in_kataja: self.forest.derivation_steps.save_and_create_derivation_step([dtree]) pprint.pprint(dtree) else: print('******* dtree *******') pprint.pprint(dtree)
def print_results(dnodes, lexicon=None): print("attempting to create derivation tree...") dt = Constituent.dnodes_to_dtree(dnodes, all_features=True) # False) res = {} # d -- derivation tree res["d"] = list_tree_to_nltk_tree(dt.as_list_tree()) print("success at creating derivation tree.") # pd -- pretty-printed derivation tree output = io.StringIO() pptree(output, dt.as_list_tree()) res["pd"] = output.getvalue() print(res["pd"]) output.close() # s -- state tree print("attempting to create state tree...") res["s"] = list_tree_to_nltk_tree(StateTree(dt).as_list_tree()) print("success at creating state tree.") # ps -- pretty-printed state tree output = io.StringIO() pptree(output, StateTree(dt).as_list_tree()) res["ps"] = output.getvalue() print(res["ps"]) output.close() # b -- bare tree print("attempting to create bare tree...") res["b"] = list_tree_to_nltk_tree(BareTree(dt).as_list_tree()) print("success at creating bare tree.") # pb -- pretty-printed bare tree output = io.StringIO() pptree(output, BareTree(dt).as_list_tree()) res["pb"] = output.getvalue() output.close() # x -- xbar tree print("attempting to create xbar tree...") res["x"] = list_tree_to_nltk_tree(XBarTree(dt).as_list_tree()) print("success at creating xbar tree.") # px -- pretty-printed xbar tree output = io.StringIO() pptree(output, XBarTree(dt).as_list_tree()) res["px"] = output.getvalue() output.close() # pg -- print grammar as items output = io.StringIO() res["pg"] = output.getvalue() output.close() if lexicon: # l -- grammar as tree res["l"] = list_tree_to_nltk_tree(["."] + lex_array_as_list(lexicon)) # pl -- pretty-printed grammar as tree output = io.StringIO() pptree(output, ["."] + lex_array_as_list(lexicon)) # changed EA res["pl"] = output.getvalue() output.close() return res
def print_results(dnodes, lexicon=None): print('attempting to create derivation tree...') dt = Constituent.dnodes_to_dtree(dnodes, all_features=True) #False) res = {} # d -- derivation tree res['d'] = list_tree_to_nltk_tree(dt.as_list_tree()) print('success at creating derivation tree.') # pd -- pretty-printed derivation tree output = io.StringIO() pptree(output, dt.as_list_tree()) res['pd'] = output.getvalue() print(res['pd']) output.close() # s -- state tree print('attempting to create state tree...') res['s'] = list_tree_to_nltk_tree(StateTree(dt).as_list_tree()) print('success at creating state tree.') # ps -- pretty-printed state tree output = io.StringIO() pptree(output, StateTree(dt).as_list_tree()) res['ps'] = output.getvalue() print(res['ps']) output.close() # b -- bare tree print('attempting to create bare tree...') res['b'] = list_tree_to_nltk_tree(BareTree(dt).as_list_tree()) print('success at creating bare tree.') # pb -- pretty-printed bare tree output = io.StringIO() pptree(output, BareTree(dt).as_list_tree()) res['pb'] = output.getvalue() output.close() # x -- xbar tree print('attempting to create xbar tree...') res['x'] = list_tree_to_nltk_tree(XBarTree(dt).as_list_tree()) print('success at creating xbar tree.') # px -- pretty-printed xbar tree output = io.StringIO() pptree(output, XBarTree(dt).as_list_tree()) res['px'] = output.getvalue() output.close() # pg -- print grammar as items output = io.StringIO() res['pg'] = output.getvalue() output.close() if lexicon: # l -- grammar as tree res['l'] = list_tree_to_nltk_tree(['.'] + lex_array_as_list(lexicon)) # pl -- pretty-printed grammar as tree output = io.StringIO() pptree(output, ['.'] + lex_array_as_list(lexicon)) # changed EA res['pl'] = output.getvalue() output.close() return res