0
votes

I have created an ontology, and I want to update some data property in it. I read SPARQL Update in enter link description here and I found that with SPARQL Update (Insert/Update) I can update RDF triple based on Pellet reasoner. but I'm in doubt that it is useful fo data property.

For example I have a person class with datapropery has-age "30" and has-age-category="child" I create this SPARQL query and I don't have result.

"DELETE ?person nn:has-category-age 'child'\n" "INSERT ?person nn:has-category-age 'adult'\n" "WHERE {\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" "} "; Thanks a lot

my ontology is:

<?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

1 Answers

2
votes
  1. Formatting of your question always helps other to read the question.
  2. Which triple store /SPARQL engine do you use?
  3. Without seeing the data, how can we check whether the WHERE part is correct and matches some data?
  4. Debugging of SPARQL Update queries is obviously possible by first checking whether the WHERE part matches any result - this can indeed be done by using a SELECT query.

From your SPARQL query I can see obvious errors in the WHERE part:

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. Triple pattern ?person nn:has-category-age ?categry . and the FILTER is (has-category-age='child'). Why? You have to filter based on the variable value, not using the predicate again
  2. Triple pattern ?person nn:has-age ?ag . and the FILTER is (?has-age='30'). The same problem as before...in addition, if the datatype of the age is xsd:integer, you can't use '30', because inside quotes it would be a string. Either use 30 or "30"^^xsd:integer
  3. Please please check your variable names next time, it's horrible to see typos there. ?ag -> ?age and ?categry -> ?category

Fixed WHERE part (I'm assuming the age is an integer value):

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