我正在尝试从如下所示的树结构中获取扁平树。
我想把整棵树放在一个字符串中,就像没有检测到坏树错误一样:
( (S (NP-SBJ (NP (DT The) (JJ high) (JJ seven-day) )(PP (IN of) (NP (DT the) (CD 400) (NNS money) )))(VP (VBD was) (NP-PRD (CD 8.12) (NN %) )(, ,) (ADVP (RB down) (PP (IN from) (NP (CD 8.14) (NN %) ))))(. .) ))
请您参考如下方法:
您可以使用 str 函数将树转换为字符串,然后拆分和连接如下:
parse_string = ' '.join(str(tree).split())
print parse_string
