Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

将关键词与实体进行关系抽取的函数返回空列表 #3

Open
BrambleXu opened this issue Jan 17, 2019 · 2 comments
Open

Comments

@BrambleXu
Copy link

BrambleXu commented Jan 17, 2019

text_grapher.py文件中,构建实体与关键词关系的函数返回的events_entity_keyword是空列表[]
通过查看函数的代码,发现问题可能出在这一行:keyword = [i[0] for i in keyword]

  • 传入的keyword为['谢雕', '凯旋', '同学', '家人', '北京', '南都', '记者', '高中', '警方', '告诉']
  • keyword = [i[0] for i in keyword]['谢', '凯', '同', '家', '北', '南', '记', '高', '警', '告']

可以看到返回的结果是关键词的第一个字。这样得到的events是空列表。如果想要得到正常的结果的话,应该删除keyword = [i[0] for i in keyword]这一行。

请问我的理解对吗?想知道这里是不是bug,还是说有我没有想到的地方。

'''基于文章关键词,建立起实体与关键词之间的关系'''
def rel_entity_keyword( ners, keyword, subsent):
    events = []
    rels = []
    sents = []
    ners = [i.split('/')[0] for i in set(ners)]
    keyword = [i[0] for i in keyword]
    for sent in subsent:
        tmp = []
        for wd in sent:
            if wd in ners + keyword:
                tmp.append(wd)
        if len(tmp) > 1:
            sents.append(tmp)
    for ner in ners:
        for sent in sents:
            if ner in sent:
                tmp = ['->'.join([ner, wd]) for wd in sent if wd in keyword and wd != ner and len(wd) > 1]
                if tmp:
                    rels += tmp
    for e in set(rels):
        events.append([e.split('->')[0], e.split('->')[1]])
    return events

#将关键词与实体进行关系抽取
events_entity_keyword = rel_entity_keyword(ners, keywords, subsents_seg)
events += events_entity_keyword
@BrambleXu
Copy link
Author

如果不添加events_entity_keyword,最后events里只有80多个元素,但是如果添加了的话,events会有600多个元素。画出图来太密集了,看起来很不方便。是因为这个原因才令events_entity_keyword为空列表吗?要是这样的话,也没有必要直接修改rel_entity_keyword吧。只要不写events += events_entity_keyword就行了。

@CQUPTNLP
Copy link

同样发现上面这个问题,楼上老哥解决了吗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants