python - NLP:spacy 获取依赖项
问题描述
我试图从这句话中提取一些数字,但我想验证正确的数字是否与正确的文本匹配。
nlp = spacy.load('en_core_web_sm')
s2 = 'Revenue from the advertising and subscription business for the first quarter of 2019 was RMB897.0 million (US$133.7 million), representing a 13.9% increase from RMB787.5 million (US$117.3 million) in the corresponding period in 2018.'
doc = nlp(s2)
for w in doc.ents:
print(w.text, w.label_, w.root)
for i in w.subtree:
print(" ", i, i.head)
for a in i.ancestors:
print(" ", a, a.head)
我想联系RMB897.0 million
但advertising and subscription
不知道该怎么做。还尝试了名词分块。
for chunk in doc.noun_chunks:
print(chunk.text, chunk.root.text, chunk.root.dep_,
chunk.root.head.text)
for c in chunk.subtree:
print(" ", c, c.head)
解决方案
首先,您需要考虑您的数据。如果您发现数字和相关名词的某些模式,您也许可以使用它们来找出关系,无论如何,这并不是很可靠。更好的方法是使用依赖解析或完全解析算法,使用词性标记 (POS) 信息和可能的关于头部动词的语义信息。这是一项真正的语言任务,这意味着您需要语言信息。连接动词表示数字与动词参数有关,因此提取和关系很简单。其他情况可能不太明显。
也许开始对包含数字的表达式及其出现的矩阵动词(be,amount to,reduce to,increase等)进行一些搭配分析,然后您可以使用动词参数的信息进行注释关系。也许看看相关和照应分辨率,这可能会帮助你。
推荐阅读
- firebase - 如何发送具有重叠主题的firebase推送通知
- java - java的run方法是否存在并发问题
- linux - 网站不在局域网上显示,但在主机上显示
- unity3d - ScreenToWorldPoint 和 ScreenPointToWorldPointInRectangle 有什么区别?
- android - 如何在 kotlin 中解析文本 ascii protobuf 字符串
- c++ - 将cin值放入数组时出现段错误
- javascript - 动态过滤 D3 有向图的节点
- python - 如何在主文件中使用相同变量的同时使用其他文件中的函数?
- aws-glue - AWS Glue 爬虫如何排除 oracle 架构或 oracle 表?
- mongodb - 带有 $in 记录和后续条件的 mongodb 查询