【问题标题】:How to get De-Duplicated OpenIE (Clause Extraction) Results?如何获得去重的 OpenIE(子句提取)结果?
【发布时间】:2022-04-18 03:35:40
【问题描述】:

我已经用尽了所有我知道的配置选项:

from openie import StanfordOpenIE
  
# https://stanfordnlp.github.io/CoreNLP/openie.html#api
# Default value of openie.affinity_probability_cap was 1/3.
properties = {
    "annotators":"tokenize,ssplit,pos,depparse,natlog,openie",
    'openie.affinity_probability_cap': 2 / 3,
    "openie.triple.strict":"true",
    'openie.max_entailments_per_clause': 1,
    'splitter.disable': True
}

with StanfordOpenIE(properties=properties) as client:
    text = 'Barack Obama was born in Hawaii. Richard Manning wrote this sentence.'
    print('Text: %s.' % text)
    for triple in client.annotate(text): #, max_entailments_per_clause=True):
        print('|-', triple)

但结果仍然包含未合并的重复变体:

|- {'subject': 'Barack Obama', 'relation': 'was', 'object': 'born'}
|- {'subject': 'Barack Obama', 'relation': 'was born in', 'object': 'Hawaii'}

而我只是在寻找最大的子句提取结果:

|- {'subject': 'Barack Obama', 'relation': 'was born in', 'object': 'Hawaii'}

有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: python stanford-nlp information-extraction


    【解决方案1】:

    这段代码对我有用。

    from pycorenlp import *
    import json
    import nltk
    
    nlp = StanfordCoreNLP("http://localhost:9000/")
    text = 'Barack Obama was born in Hawaii. Richard Manning wrote this sentence.'
    
    props = {"annotators": "tokenize,ssplit,pos,depparse,natlog,openie",
                                      "outputFormat": "json",
                                      "openie.triple.strict": "true",
                                      "openie.max_entailments_per_clause": "1"}
    sentences = nltk.sent_tokenize(text)
    for sent in sentences:
        print(sent)
        output = nlp.annotate(sent, properties=props)
        j_data = json.loads(output)
        openie = j_data['sentences'][0]['openie']
        for i in openie:
            for rel in i:
                relationSen = i['subject'], i['relation'], i['object']
        print(relationSen)
    

    它产生以下输出...

    Barack Obama was born in Hawaii.
    ('Barack Obama', 'was born in', 'Hawaii')
    Richard Manning wrote this sentence.
    ('Richard Manning', 'wrote', 'sentence')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-09
      • 1970-01-01
      • 1970-01-01
      • 2017-04-29
      • 1970-01-01
      • 2020-07-19
      相关资源
      最近更新 更多