import spacy
nlp = spacy.load('en')
parsed_text = nlp(u"I thought it was the complete set")
#get token dependencies
for text in parsed_text:
#subject would be
if text.dep_ == "nsubj":
subject = text.orth_
#iobj for indirect object
if text.dep_ == "iobj":
indirect_object = text.orth_
#dobj for direct object
if text.dep_ == "dobj":
direct_object = text.orth_
print(subject)
print(direct_object)
print(indirect_object)
以最简单的方式。 依赖项由令牌.dep_ 有输入空间:
你可以用名词块。在
代码
结果:
^{pr2}$要只选择“I”而不是“I”和“it”,可以先编写一个测试,将nsubj放在ROOT的左边。在
相关问题 更多 >
编程相关推荐