python - 在 Python 中使用 Stanfrod Parser 构建折叠树
问题描述
我正在按照本教程使用 Python 为句子构建依赖关系树。本教程展示了如何将 Stanfrod Parser 与 NLTK 一起使用。我已经完成了这一步,我可以构建树,如下面的代码所示。
from config import config
from nltk.parse.stanford import StanfordDependencyParser
class ExtractTree:
def __init__(self):
"""
Init Stanford parse tree
"""
path_to_jar = config['libs_root'] + "stanford-parser-full-2018-10-17/stanford-parser.jar"
path_to_models_jar = config['libs_root'] + "stanford-parser-full-2018-10-17/stanford-parser-3.9.2-models.jar"
self.dependency_parser = StanfordDependencyParser(
path_to_jar=path_to_jar, path_to_models_jar=path_to_models_jar,java_options=[]
)
def extract_tree(self, sentence):
"""
Extract the dependency tree for a sentence
:param sentence:
:return:
"""
result = self.dependency_parser.raw_parse(sentence)
return next(result)
但是,我无法弄清楚如何构建一个折叠的依赖树,如下所述:(图像和引用来自Stanford Parser Documentation page.20)
在折叠表示中,涉及介词、连词以及关系从句的所指信息的依赖关系被折叠,以获得实词之间的直接依赖关系。
似乎java有一个API,但我找不到将它集成到Python中的方法,有什么想法吗?
解决方案
推荐阅读
- python - 使用 Tensorflow 构建 RNN。如何正确预处理我的数据集以匹配 RNN 的输入和输出形状?
- flask - 无法在本地网络中访问 Flask 应用程序
- django - Celery - 如何获取 shared_task 的任务 ID?
- macos - ubuntu 18.04.1 in paralles desktop on mac arrowkey down and up 异常
- python - Pandas 数据框 OrderedDict 提取数据
- amazon-web-services - Azure Databricks 是否安全地挂载 S3
- tensorflow - 在训练期间切换 AI 学习技术?
- java - 删除时的参照完整性约束违反错误(休眠)
- google-api - Google Vision 徽标检测 API 支持的徽标
- powerbi - 如何在 power bi 中更改年终?