PYTHON中的主体对象标识 [英] subject object identification in python

查看:15
本文介绍了PYTHON中的主体对象标识的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想识别一组句子的主语和宾语。我的实际工作是从一组审查数据中识别因果关系。

我正在使用Spacy Package来分块和解析数据。但并没有真正达到我的目标。有没有办法做到这一点?

例如:

 I thought it was the complete set

输出:

subject  object
I        complete set

推荐答案

以最简单的方式。 依赖项由内标识访问。dep_ 已导入空间:

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)

这篇关于PYTHON中的主体对象标识的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆