我想将.CSV格式的 Adobe 安全咨询产品的数据集与我已经创建的本体链接起来,数据集的示例如下所示:
文本 | 标签 |
---|---|
APSA08-05 | SecAdvisoryID |
APSB12-09 | 公告编号 |
这是我使用WebOWL 工具创建的简单本体:
对于本体,我在Python中使用RDFlib。这是本体的代码:
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(乌龟)格式。
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的安全咨询。因此,我的问题是如何确保本体能够识别数据集?