首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >实体关系提取斯坦福CoreNLP

实体关系提取斯坦福CoreNLP
EN

Stack Overflow用户
提问于 2018-09-29 03:24:53
回答 1查看 1.3K关注 0票数 0

请我尝试做一个从一个解析句子的pdf文本串的关系提取。我使用了斯坦福大学的coreNLP和python pycorenlp来解析句子,现在我想从这个解析树中提取主语、动词和宾语。

下面是我的数据样本:“马克·罗伯特是3trucks的创始人。3trucks成立于2010年。”

以下是我想要的输出:('Mark Robert',创始人,'3trucks') ('3truck',成立于'2010')

以下是文本和代码的示例

代码语言:javascript
复制
import nltk
import re
from pycorenlp import *

nlp = StanfordCoreNLP("http://localhost:9000/")

text = 'Mark Robert is the founder of 3trucks. 3trucks was founded in 2010'

output = nlp.annotate(text, properties={
'annotators': 'tokenize,ssplit,pos,depparse,parse',
"timeout": "50000",
'outputFormat': 'json'

 })

print(output['sentences'][0]['parse'])
print('------------------------------')
print(output['sentences'][1]['parse'])`

我的代码输出:

代码语言:javascript
复制
(ROOT
(S
(NP (NNP Mark) (NNP Robert))
(VP (VBZ is)
  (NP
    (NP (DT the) (NN founder))
    (PP (IN of)
      (NP (NNS 3trucks)))))
(. .)))
------------------------------
(ROOT
(S
(NP (NNS 3trucks))
(VP (VBD was)
  (VP (VBN founded)
    (PP (IN in)
      (NP (CD 2010)))))))
EN

回答 1

Stack Overflow用户

发布于 2019-02-12 17:31:24

您可以在注释器列表中包含'openie‘。Openie还将形成三元组,这是列表所必需的。还要记住将输出限制为3。

代码语言:javascript
复制
output = nlp.annotate(s, properties={"annotators":"tokenize,ssplit,pos,depparse,natlog,openie",
                            "outputFormat": "json",
                             "openie.triple.strict":"true",
                             "openie.max_entailments_per_clause":"1"})

Post,您可以根据需要添加输出。

代码语言:javascript
复制
result = [output["sentences"][0]["openie"] for item in output]
for i in result:
    for rel in i:
        relationSent=rel['subject'],rel['relation'],rel['object']
        print(relationset)

希望这能有所帮助。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52561555

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档