python - 如何将实体关系从 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')
现在我想将这些关系转换为本体。
解决方案
构建本体时需要回答的主要问题之一是“您希望从本体中获得哪些推论?”。根据您提供的信息,我无法回答这个问题。因此,告诉您如何为给定句子构建本体并不容易。
对我来说更现实的是把这些句子放在一个 RDF 三元存储中。由于 RDF 数据存储为<subject, predicate, object>
,因此它与检索到的句子非常匹配。即,('越南','有','新婚姻法')将成为<Vietnam, has, new_marriage_law>
。这样做的好处是您可以使用 SPARQL 查询 RDF 数据。
推荐阅读
- python - Flask 向 HTML 页面添加无限的函数调用
- selenium-webdriver - 在虚拟机中获取 UnreachableBrowserException 异常
- go - 如何为从标准输入读取的内容编写 go Test 函数?
- makefile - 在 Makefile 中,$subst 函数中的“缺少分隔符错误”但在“subst”之前放置一个制表符会删除错误。为什么?
- flow-project - 射线和流冲突
- xml - VB:安全通道支持发生错误
- mule - 少数条目的 Dataweave2 更新功能不起作用?
- python-3.x - 转置几列并重塑它们
- laravel - 路由组前缀在 Laravel 8 中不起作用
- android - 将图像视图从 Parse 转换为 RecyclerView 的 int 数组