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 如何展平解析树并存储在字符串中以进
基础教程推荐
猜你喜欢
- 尝试制作WhatsApp机器人 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
