如何使用SPARQL将新实例插入OWL本体

时间:2017-03-15 15:41:30

标签: sparql owl ontology

我想使用SPARQL INSERT语句在我的本体中插入一个新实例。 示例实例:

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

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

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 " 
{
//...
}

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

index <- seq_along(L)
do.call(rbind, lapply(index, function(i) do.call(cbind, L[abs(i-index)+1])))

#     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
#[1,]    1    2   11   12  101  102 1001 1002
#[2,]    3    4   13   14  103  104 1003 1004
#[3,]   11   12    1    2   11   12  101  102
#[4,]   13   14    3    4   13   14  103  104
#[5,]  101  102   11   12    1    2   11   12
#[6,]  103  104   13   14    3    4   13   14
#[7,] 1001 1002  101  102   11   12    1    2
#[8,] 1003 1004  103  104   13   14    3    4

2 个答案:

答案 0 :(得分: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 . 
   } 
} 

答案 1 :(得分:0)

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 DATA
{
   owl:cap_456 rdf:type owl:HealthBeauty;
               rdf:type oo:NamedIndividual;
               owl:id 456 ; 
               owl:hasPrice 15; 
               owl:description 'Test2 test2 test2' .
}