如何使用 RDF Ontology 链接 csv 文件中的数据集? [英] How to linked datasets in csv file with RDF Ontology?

查看:93
本文介绍了如何使用 RDF Ontology 链接 csv 文件中的数据集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I wanted to link the datasets of Adobe's Security Advisory product that in .CSV format with the ontology that I already created, the example of datasets looks like this:

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

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

Here is the simple ontology that I created using WebOWL tool :

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

For the ontology , I use RDFlib in Python. Here is the code of the ontology:

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, RDF.type, RDFS.Class))

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

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

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

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

I saved it in .ttl (turtle) format.

testgraph.ttl 的输出:

@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix test: <http://example.org/cyber/test#> .

test:BulletinID a rdfs:Class .

test:SecAdvisoryID a rdfs:Class .

test:hasAdvisory rdfs:domain test:BulletinID ;
    rdfs:range test:SecAdvisoryID .

test:hasBulletin rdfs:domain test:SecAdvisoryID ;
    rdfs:range test:BulletinID .

test:hasTitle rdfs:domain test:BulletinID,
        test:SecAdvisoryID .

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

My intention is to make a knowledge graph of security advisory, knowledge that I crawled is from Adobe's Security Advisory. Hence, my problem is how I want to make sure that the ontology will recognize the datasets?

推荐答案

CSV在 Web 上 规范提供了一种将 CSV 映射到 RDF 的方法 使用元数据文件来描述关系.

The CSV on the Web specifications provide a means of generically mapping CSV to RDF using a metadata file to describe relationships.

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

While there is vocabulary associated with the metadata file, the format allows any vocabulary to be used in the metadata.

到目前为止,我不知道 Python 实现,但我在 Ruby 实现 上是完全与规范兼容,并且可以在 http://rdf.greggkellogg.net/distiller 上进行在线测试.

To date, I know of no Python implementation, but my on Ruby implementation is fully compatible with the specs, and can be tested online at http://rdf.greggkellogg.net/distiller.

这篇关于如何使用 RDF Ontology 链接 csv 文件中的数据集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆