微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用 RDF Ontology 链接 csv 文件中的数据集?

如何解决如何使用 RDF Ontology 链接 csv 文件中的数据集?

我想将 .CSV 格式的 Adob​​e 安全咨询产品的数据集与我已经创建的本体相关联,数据集示例如下所示:

文字 标签
APSA08-05 SecAdvisoryID
APSB12-09 公告ID

这是我使用 WebOWL 工具创建的简单本体:

enter image description here

对于本体,我使用 Python 中的 RDFlib。下面是本体的代码

comprehension

我以.ttl(海龟)格式保存。

testgraph.ttl输出

from rdflib import Graph,Namespace
from rdflib.namespace import RDF,XSD,RDFS
from rdflib.term import Literal

#create the graph
graph = Graph()
test = Namespace("http://example.org/cyber/test#")
graph.bind("test",test)

graph.add((test.SecAdvisoryID,RDF.type,RDFS.Class))
graph.add((test.BulletiniD,RDFS.Class))

graph.add((test.hasTitle,RDFS.domain,test.SecAdvisoryID))
graph.add((test.hasTitle,test.BulletiniD))

graph.add((test.hasBulletin,test.SecAdvisoryID)) 
graph.add((test.hasBulletin,RDFS.range,test.BulletiniD))
graph.add((test.hasAdvisory,test.BulletiniD)) 
graph.add((test.hasAdvisory,test.SecAdvisoryID))

# save the graph
with open("testgraph.ttl","wb") as f:
    f.write(graph.serialize(format="turtle"))

我的意图是制作一个安全公告的知识图谱,我爬取的知识来自Adobe的安全公告。因此,我的问题是如何确保本体能够识别数据集?

解决方法

CSV on the Web 规范提供了一种使用 CSV to RDF 来描述关系的一般映射 metadata file 的方法。

虽然有与元数据文件相关联的词汇表,但该格式允许在元数据中使用任何词汇表。

迄今为止,我知道没有 Python 实现,但我的 Ruby implementation 与规范完全兼容,可以在 http://rdf.greggkellogg.net/distiller 上进行在线测试。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。