我想识别一组句子的主语和宾语。我的实际工作是从一组评论数据中找出因果关系。
我正在使用 Spacy 包来分块和解析数据。但实际上并没有达到我的目标。有什么办法吗?
例如:
I thought it was the complete set
输出:
subject object
I complete set
请您参考如下方法:
以最简单的方式。 通过 token.dep_ 访问依赖项 导入spacy:
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)
