UPdate Data属性值基于SPARQL DELETE和INSERT

时间:2017-10-15 10:41:50

标签: sparql ontology

我创建了一个本体,我想更新其中的一些数据属性。我在enter link description here中阅读了SPARQL更新,我发现通过SPARQL更新(插入/更新),我可以根据Pellet推理器更新RDF三元组。但我怀疑它对数据属性有用。

例如,我有一个带有datapropery has-age" 30"和年龄类别="孩子" 我创建了这个SPARQL查询,但我没有结果。

" DELETE?person nn:has-category-age' child' \ n"  " INSERT?person nn:has-category-age' adult' \ n"  "在哪里{\ n"  "?person rdf:type nn:person。\ n"  "?person nn:has-age?age。\ n"  "?person nn:has-category-age?category。\ n"   " FILTER((has-category-age =' child')&&(?has-age =' 30'))\ n"  "}&#34 ;; 非常感谢

我的本​​体是:

<?xml version="1.0"?>

    

<!-- 
///////////////////////////////////////////////////////////////////////////////////////
//
// Object Properties
//
///////////////////////////////////////////////////////////////////////////////////////
 -->




<!-- http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#has-class -->

<owl:ObjectProperty rdf:about="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#has-class">
    <rdfs:domain rdf:resource="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Person"/>
    <rdfs:range rdf:resource="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Classroom"/>
</owl:ObjectProperty>



<!-- http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#has-time -->

<owl:ObjectProperty rdf:about="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#has-time">
    <rdfs:domain rdf:resource="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Courses"/>
    <rdfs:range rdf:resource="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Time"/>
</owl:ObjectProperty>



<!-- 
///////////////////////////////////////////////////////////////////////////////////////
//
// Data properties
//
///////////////////////////////////////////////////////////////////////////////////////
 -->




<!-- http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#has-age -->

<owl:DatatypeProperty rdf:about="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#has-age">
    <rdfs:domain rdf:resource="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Person"/>
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#integer"/>
</owl:DatatypeProperty>



<!-- http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#has-category-age -->

<owl:DatatypeProperty rdf:about="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#has-category-age">
    <rdfs:domain rdf:resource="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Person"/>
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
</owl:DatatypeProperty>



<!-- 
///////////////////////////////////////////////////////////////////////////////////////
//
// Classes
//
///////////////////////////////////////////////////////////////////////////////////////
 -->




<!-- http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Classroom -->

<owl:Class rdf:about="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Classroom"/>



<!-- http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Courses -->

<owl:Class rdf:about="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Courses"/>



<!-- http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Person -->

<owl:Class rdf:about="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Person"/>



<!-- http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Time -->

<owl:Class rdf:about="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Time"/>



<!-- 
///////////////////////////////////////////////////////////////////////////////////////
//
// Individuals
//
///////////////////////////////////////////////////////////////////////////////////////
 -->




<!-- http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Jihed -->

<owl:NamedIndividual rdf:about="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Jihed">
    <rdf:type rdf:resource="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Person"/>
    <has-age rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">30</has-age>
    <has-category-age rdf:datatype="http://www.w3.org/2001/XMLSchema#string">child</has-category-age>
</owl:NamedIndividual>



<!-- http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Joseph -->

<owl:NamedIndividual rdf:about="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Joseph">
    <rdf:type rdf:resource="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Person"/>
    <has-age rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">10</has-age>
    <has-category-age rdf:datatype="http://www.w3.org/2001/XMLSchema#string">child</has-category-age>
</owl:NamedIndividual>



<!-- http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Ralph -->

<owl:NamedIndividual rdf:about="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Ralph">
    <rdf:type rdf:resource="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Person"/>
    <has-age rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">25</has-age>
    <has-category-age rdf:datatype="http://www.w3.org/2001/XMLSchema#string">adult</has-category-age>
</owl:NamedIndividual>

1 个答案:

答案 0 :(得分:2)

  1. 格式化您的问题总是有助于其他人阅读问题。
  2. 您使用哪个三重存储/ SPARQL引擎?
  3. 如果没有看到数据,我们如何检查WHERE部分是否正确并匹配某些数据?
  4. 通过首先检查WHERE部分是否与任何结果匹配,显然可以调试SPARQL更新查询 - 这确实可以通过使用SELECT查询来完成。
  5. 从您的SPARQL查询中我可以看到WHERE部分中的明显错误:

    WHERE {
     ?person rdf:type nn:person .
     ?person nn:has-age ?ag .
     ?person nn:has-category-age ?categry .
     FILTER ((has-category-age='child') && (?has-age='30'))
    }
    
    1. 三重模式?person nn:has-category-age ?categry .,FILTER为(has-category-age='child')。为什么?您必须根据变量值进行过滤,而不是再次使用谓词
    2. 三重模式?person nn:has-age ?ag .,FILTER为(?has-age='30')。与以前相同的问题...此外,如果年龄的数据类型为xsd:integer,则您无法使用'30',因为在引号内部它将是一个字符串。使用30"30"^^xsd:integer
    3. 请下次检查你的变量名,看到那里的拼写错误很可怕。 ?ag - &gt; ?age?categry - &gt; ?category
    4. 修正WHERE部分(我假设年龄是整数值):

       WHERE {
           ?person rdf:type nn:person .
           ?person nn:has-age ?age .
           ?person nn:has-category-age ?category .
           FILTER ((?category='child') && (?age=30))
       }