How to flatten the parse tree and store in a string for further string operations python nltk(python nltk 如何展平解析树并存储在字符串中以进行进一步的字符串操作)
本文介绍了python nltk 如何展平解析树并存储在字符串中以进行进一步的字符串操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从树结构中获取扁平树,如下所示.
I am trying to get flat tree from the tree structure like the one given below.
我想在一个字符串中获取整个树,就像没有检测到坏树错误一样:
I want to get this whole tree in a string like without Bad tree detected error:
( (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 函数将树转换为字符串,然后拆分和连接如下:
You can convert the tree into string using str function then split and join as follow:
parse_string = ' '.join(str(tree).split())
print parse_string
这篇关于python nltk 如何展平解析树并存储在字符串中以进行进一步的字符串操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:python nltk 如何展平解析树并存储在字符串中以进
基础教程推荐
猜你喜欢
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 包装空间模型 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
