首页 文章

UPdate Data属性值基于SPARQL DELETE和INSERT

提问于
浏览
0

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

例如,我有一个personapropery has-age“30”和has-age-category =“child”的person类我创建了这个SPARQL查询,但我没有结果 .

“DELETE?person nn:has-category-age'child'\ n”“INSERT?person nn:has-category-age'adath'\ 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“”}“;非常感谢

我的本体论是:

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

  • 2
    • 格式化您的问题总是有助于其他人阅读问题 .

    • 您使用哪个三重存储/ SPARQL引擎?

    • 如果没有看到数据,我们如何检查 WHERE 部分是否正确并匹配某些数据?

    • 通过首先检查WHERE部分是否匹配任何结果,显然可以调试SPARQL更新查询 - 这确实可以通过使用 SELECT 查询来完成 .

    从您的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'))
    }
    
    • 三重模式 ?person nn:has-category-age ?categry . ,FILTER为 (has-category-age='child') . 为什么?您必须根据变量值进行过滤,而不是再次使用谓词

    • 三重模式 ?person nn:has-age ?ag . ,FILTER为 (?has-age='30') . 与之前相同的问题...另外,如果年龄的数据类型是 xsd:integer ,则不能使用 '30' ,因为在引号内它将是一个字符串 . 使用 30"30"^^xsd:integer

    • 请下次查看你的变量名,看到那里的拼写错误很可怕 . ?ag - > ?age?categry - > ?category

    修复 WHERE 部分(我假设年龄是一个整数值):

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

相关问题