2017-03-15 111 views
1

我想使用SPARQL INSERT语句将新实例插入到本体中。 样本实例:如何使用SPARQL将新实例插入到OWL本体中

<owl:NamedIndividual rdf:about="http://www.test123.com/test123-ontology.owl#cap_123"> 
<rdf:type rdf:resource="http://www.test123.com/test123-ontology.owl#HealthBeauty"/> 
<description>Test test test</description> 
<hasPrice rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">49</hasPrice> 
<id rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">123</id> 
</owl:NamedIndividual> 

应插入具有以下属性的新实例:

id: 456 
hasPrice: 15 
description: "Test2 test2 test2" 

我不知道如何完成查询的INSERT部分:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX owl: <http://www.test123.com/test123-ontology.owl#> 
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> 
PREFIX oo: <http://www.w3.org/2002/07/owl#> 
INSERT " 
{ 
//... 
} 
+0

这在W3C规范中有详细记载:https://www.w3.org/TR/sparql11-update/#insertData – AKSW

+0

@AKSW:我不明白如何指定这个部分'rdf:type rdf:resource =“http://www.test123.com/test123-ontology.owl#HealthBeauty”/>' – Dinosaurius

+0

我不明白。一切都是三重的,因此,它只是 rdf:type .' – AKSW

回答

2

解决方案如下:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX owl: <http://www.test123.com/test123-ontology.owl#> 
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> 
PREFIX oo: <http://www.w3.org/2002/07/owl#> 

INSERT 
{ 
    owl:cap_456 rdf:type owl:HealthBeauty . 
    owl:cap_456 owl:id 456 . 
    owl:cap_456 owl:hasPrice 15 . 
    owl:cap_456 owl:description 'Test2 test2 test2' . } 
WHERE 
{ 
    FILTER NOT EXISTS 
    { 
    owl:cap_456 rdf:type owl:HealthBeauty . 
    } 
} 
+0

我不明白你为什么需要'WHERE'子句,而不是简单地使用'INSERT DATA',就像我在之前的评论中提到的那样。你没有任何三重模式,即没有变量 - 只需三倍。 WHERE子句用于匹配数据中的模式 – AKSW