我有一个关于斯坦福CoreNLP OpenIE注释器的问题.
我正在使用Stanford CoreNLP版stanford-corenlp-full-2015-12-09来使用OpenIE提取关系.我不太了解Java,这就是我使用pycorenlpPython 3.4包装器的原因.
我想提取一个句子的所有单词之间的关系,下面是我使用的代码.我也有兴趣展示每个三胞胎的信心:
import nltk
from pycorenlp import *
import collections
nlp=StanfordCoreNLP("http://localhost:9000/")
s="Twenty percent electric motors are pulled from an assembly line"
output = nlp.annotate(s, properties={"annotators":"tokenize,ssplit,pos,depparse,natlog,openie",
"outputFormat": "json","triple.strict":"true"})
result = [output["sentences"][0]["openie"] for item in output]
print(result)
for i in result:
for rel in i:
relationSent=rel['relation'],rel['subject'],rel['object']
print(relationSent)
Run Code Online (Sandbox Code Playgroud)
这是我得到的结果:
[[{'relationSpan': [4, 6], 'subject': 'Twenty percent electric motors', 'objectSpan': [8, 10], 'relation': 'are pulled from', 'object': 'assembly line', 'subjectSpan': [0, 4]}, {'relationSpan': [4, 6], 'subject': 'percent …Run Code Online (Sandbox Code Playgroud)