parsing - 解析树的 Python 列表
问题描述
在 Python 中,我有一个列表输入,如下所示 -
[('S', ['NP', 'VP']),
('A', ['V', 'NP']),
('VP', ['V', 'NP']),
('NP', ['DET', 'NP']),
('N', "'mouse'"),
('NP', "'mouse'"),
('DET', "'the'"),
('V', "'saw'"),
('N', "'Ron'"),
('NP', "'Ron'")]
这是以下 CYK 算法的结果 -
S -> NP VP
VP -> A NP | V NP
NP -> N N | DET NP | 'chocolate' | 'cat' | 'John' | 'Ron' | 'mouse'
DET -> 'the'
N -> 'chocolate' | 'cat' | 'John' | 'Ron' | 'mouse'
V -> 'saw' | 'bought' | 'ate'
A -> V NP
我要匹配的字符串是“Ron saw the mouse”
我想像这样关联输出-
(S (NP Ron) (VP (V saw) (NP (DET the) (NP mouse))))
我不确定应该如何构造算法,尤其是使用可能包含多个输出的模棱两可的算法。我应该如何构建代码?有什么建议有/没有递归应该是更好的方法吗?
更新 - -
在使用输入列表添加额外的父节点和子节点位置值后,我设法获得了一个精确的解析树。但是我的问题并没有用模棱两可的句子解决。
解决方案
推荐阅读
- amazon-web-services - 检索刚刚上传的文件后的 AWS s3 NoSuchKey 错误
- excel - VBA Excel获取ListObject中包含数据的总行数
- swift - SwiftUI 错误?ScrollView ,数据源,是否加载?
- python - 如何打开和读取文件夹python中的文本文件
- vue.js - nginx 在我的生产 vue-cli 应用程序的页面重新加载时给出 404 错误
- python - Raspberry Pi Zero 和 OpenCV 上的网络摄像头损坏图像
- reactjs - 在 React Hooks 的对象数组中使用 onChange 更新 useState 中的日期(日期选择器)
- c# - C# 如何在生产中调查 OutOfMemoryException
- json - 将数千个 JSON 文件加载到 BigQuery
- python - 在pytest的测试中多次刷新python进程