如何使用 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 上进行在线测试。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...