首页 > 解决方案 > 如何将实体关系从 corenlp 转换为本体?

问题描述

我想为新闻数据集创建一个本体。我的任务是将实体关系从 corenlp 转换为本体。

我已经使用斯坦福 corenlp 提取了关系。

for k in range(0,50):
    text = df['event_summary'][k]
    print('sentence:'+text+ '\n')
    output = nlp.annotate(text, properties={"annotators":"tokenize,ssplit,pos,depparse,natlog,openie",
                            "outputFormat": "json",
                             "openie.triple.strict":"true",
                             "openie.max_entailments_per_clause":"1"})
    result = [output["sentences"][0]["openie"] for item in output]
    for i in result:
        for rel in i:
            relationSent=rel['subject'],rel['relation'],rel['object']
            print(relationSent )
            print('\n')
            df['Entity Relation'][k]= relationSent

我的输出如下所示:

sentence:U.S. fast-food restaurant chain Chick-fil-A warns that a security > breach may have leaked credit card details of 9

('security breach', 'leaked', 'credit card details of 9')


sentence:The Palestine Authority signs a treaty to join and participate in the International Criminal Court. (Wall Street Journal)

sentence:The Eurasian Economic Union between Russia

sentence:Vietnam’s new marriage law goes into effect

('Vietnam', 'has', 'new marriage law')

现在我想将这些关系转换为本体。

标签: pythonstanford-nlpontology

解决方案


构建本体时需要回答的主要问题之一是“您希望从本体中获得哪些推论?”。根据您提供的信息,我无法回答这个问题。因此,告诉您如何为给定句子构建本体并不容易。

对我来说更现实的是把这些句子放在一个 RDF 三元存储中。由于 RDF 数据存储为<subject, predicate, object>,因此它与检索到的句子非常匹配。即,('越南','有','新婚姻法')将成为<Vietnam, has, new_marriage_law>。这样做的好处是您可以使用 SPARQL 查询 RDF 数据。


推荐阅读