def process(self, sSentence): # don't process empty sentences if sSentence.strip() == "": return # find the cfg node head = fidtree.parse_object(sSentence) if type(head) == list: lHead = head else: lHead = [head] # output the dep node for head in lHead: lTokens = [] head_child = self.find_head(head, lTokens) if self.m_bLabeled: head_child.label = 'ROOT' for tokn in lTokens: if self.m_bLabeled: print "\t".join([ gb2utf(tokn.token), tokn.pos, str(tokn.link), tokn.label ]) else: print "\t".join( [gb2utf(tokn.token), tokn.pos, str(tokn.link)]) print # empty line
def __str__(self): if self.type == 'constituent': sType = self.head_child if self.head_child == 's': sContent = self.left_child.__str__() else: sContent = self.left_child.__str__() + " " + self.right_child.__str__() elif self.type == 'token': if self.pos == '': sType = 't' sContent = gb2utf(self.token) else: sType = 'c' sContent = self.pos + ' ' + gb2utf(self.token) else: raise "Type not defined for node" if self.temporary: sType += "*" return "( %s %s %s ) " % (self.name, sType, sContent)
def __str__(self): if self.type == "constituent": sType = self.head_child if self.head_child == "s": sContent = self.left_child.__str__() else: sContent = self.left_child.__str__() + " " + self.right_child.__str__() elif self.type == "token": if self.pos == "": sType = "t" sContent = gb2utf(self.token) else: sType = "c" sContent = self.pos + " " + gb2utf(self.token) else: raise "Type not defined for node" if self.temporary: sType += "*" return "( %s %s %s ) " % (self.name, sType, sContent)
def __str__(self): if self.type == 'constituent': sType = self.head_child if self.head_child == 's': sContent = self.left_child.__str__() else: sContent = self.left_child.__str__( ) + " " + self.right_child.__str__() elif self.type == 'token': if self.pos == '': sType = 't' sContent = gb2utf(self.token) else: sType = 'c' sContent = self.pos + ' ' + gb2utf(self.token) else: raise "Type not defined for node" if self.temporary: sType += "*" return "( %s %s %s ) " % (self.name, sType, sContent)
def process(self, sSentence): # don't process empty sentences if sSentence.strip() == "": return # find the cfg node head = fidtree.parse_object(sSentence) if type(head) == list: lHead = head else: lHead = [head] # output the dep node for head in lHead: lTokens = [] head_child = self.find_head(head, lTokens) if self.m_bLabeled: head_child.label = 'ROOT' for tokn in lTokens: if self.m_bLabeled: print "\t".join([gb2utf(tokn.token), tokn.pos, str(tokn.link), tokn.label]) else: print "\t".join([gb2utf(tokn.token), tokn.pos, str(tokn.link)]) print # empty line