在单个查询中更新多个三元组的SPARQL更新示例 [英] SPARQL Update example for updating more than one triple in a single query
本文介绍了在单个查询中更新多个三元组的SPARQL更新示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人能在任何文档(无论是W3C、Virtuoso、语义网页或您自己的自定义代码等)中指出SPARQL中有效的UPDATE语句吗?
它必须完整,并在单个查询中更新WHERE规范和一个以上的三元组。
谢谢。
编辑/示例:
以下是我当前的代码,其目标是用INSERT子句中指定的值替换dc:creator
、dc:title
和dc:description
的所有当前值。此查询在逻辑和语法上是否正确?
WITH GRAPH <http://127.0.0.1:3000/dendro_graph>
DELETE
{
:teste dc:creator ?o0 .
:teste dc:title ?o1 .
:teste dc:description ?o2 .
}
INSERT
{
:teste dc:creator "Creator%201" .
:teste dc:creator "Creator%202" .
:teste dc:title "Title%201" .
:teste dc:description "Description%201" .
}
WHERE
{
:teste dc:creator ?o0 .
:teste dc:title ?o1 .
:teste dc:description ?o2 .
}
推荐答案
我仍然不完全清楚您试图实现的目标以及为什么您提供的示例更新没有执行您想要的操作,但如果目标是使更新替换给定主题的三元组,则可以执行以下操作:
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
@prefix ex: <http://example.org/>
DELETE {?s ?p ?o}
INSERT {?s ex:title "foo" ;
ex:description "bar" ;
rdf:type ex:FooBar .
}
WHERE { ?s ?p ?o .
FILTER (?s = ex:subject1)
}
上述操作将删除主题为ex:subject1
的所有现有三元组,并插入新的标题、描述和类型。
或者如果你不喜欢滤镜,你也可以这样表述上面的内容:
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
@prefix ex: <http://example.org/>
DELETE {ex:subject1 ?p ?o}
INSERT {ex:subject1 ex:title "foo" ;
ex:description "bar" ;
rdf:type ex:FooBar .
}
WHERE {
ex:subject1 ?p ?o .
}
如果您只想删除给定主题的特定属性(而不是该主题的所有三元组),则可以按如下方式修改操作:
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
@prefix ex: <http://example.org/>
DELETE {ex:subject1 ex:title ?t ;
ex:description ?d ;
rdf:type ?c .
}
INSERT {ex:subject1 ex:title "foo" ;
ex:description "bar" ;
rdf:type ex:FooBar .
}
WHERE {
ex:subject1 ex:title ?t ;
ex:description ?d ;
rdf:type ?c .
}
这篇关于在单个查询中更新多个三元组的SPARQL更新示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文