SPARQL DELETE/INSERT with SERVICE语句

SPARQL DELETE/INSERT with SERVICE语句,sparql,wikidata,federated-queries,Sparql,Wikidata,Federated Queries,我正在为Wikidata中的一些数据创建一个本地缓存,以确保标记的快速自动完成。我想每周更新一次数据,但前提是服务条款有效 基本上我是这样做的: INSERT { GRAPH <http://my.data/graph/wikidata> { ?concept wdt:P902 ?hls ; rdfs:label ?label ; schema:description ?description . }} WHERE { SERVICE

我正在为Wikidata中的一些数据创建一个本地缓存,以确保标记的快速自动完成。我想每周更新一次数据,但前提是服务条款有效

基本上我是这样做的:

INSERT { GRAPH <http://my.data/graph/wikidata> {
    ?concept wdt:P902 ?hls ;
        rdfs:label ?label ;
        schema:description ?description .
}} WHERE {
    SERVICE <https://query.wikidata.org/sparql> {
        ?concept wdt:P902 ?hls .
        ?concept rdfs:label ?label .
        ?concept schema:description ?description .
        FILTER (lang(?description) = "en")
        FILTER (lang(?label) = "en" || lang(?label) = "de" || lang(?label) = "fr" || lang(?label) = "it")
}}
INSERT{GRAPH{
?概念wdt:P902?hls;
rdfs:标签?标签;
模式:描述?描述。
}}在哪里{
服务{
?概念wdt:P902?hls。
?概念RDF:标签?标签。
?概念模式:描述?描述。
过滤器(lang(?description)=“en”)
过滤器(lang(?label)=“en”| lang(?label)=“de”| lang(?label)=“fr”| lang(?label)=“it”)
}}
现在我想我可以执行删除/插入操作,首先删除所有数据:

PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX schema: <http://schema.org/>

WITH <http://my.data/graph/wikidata>
DELETE { ?s ?p ?o }
INSERT {
    ?concept wdt:P902 ?hls ;
        rdfs:label ?label ;
        schema:description ?description .
} WHERE {
    SERVICE <https://query.wikidata.org/sparql> {
        ?concept wdt:P902 ?hls .
        ?concept rdfs:label ?label .
        ?concept schema:description ?description .
        FILTER (lang(?description) = "en")
        FILTER (lang(?label) = "en" || lang(?label) = "de" || lang(?label) = "fr" || lang(?label) = "it")
    }
    ?s ?p ?o
}
前缀wdt:
前缀架构:
具有
删除{s?p?o}
插入{
?概念wdt:P902?hls;
rdfs:标签?标签;
模式:描述?描述。
}在哪里{
服务{
?概念wdt:P902?hls。
?概念RDF:标签?标签。
?概念模式:描述?描述。
过滤器(lang(?description)=“en”)
过滤器(lang(?label)=“en”| lang(?label)=“de”| lang(?label)=“fr”| lang(?label)=“it”)
}
?s?p?o
}
但像这样,我从维基数据中得到了400条。我在没有服务的情况下执行类似的删除/插入操作,但我不明白为什么不能这样做,因为我没有在现有图和服务查询之间绑定任何变量


有人看到这里出了什么问题吗?基本上,我希望擦除现有图形,但在Wikidata关闭的情况下不会以空图形结束。

感谢用户AKSW对UNION的提示,这是一个有效的查询:

PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX schema: <http://schema.org/>


DELETE { GRAPH  <http://data.alod.ch/graph/wikidata> { ?s ?p ?o }}
INSERT { GRAPH  <http://data.alod.ch/graph/wikidata> {
    ?concept wdt:P902 ?hls ;
        rdfs:label ?label ;
        schema:description ?description .
}} WHERE {
{
    SERVICE <https://query.wikidata.org/sparql> {
        ?concept wdt:P902 ?hls .
        ?concept rdfs:label ?label .
        ?concept schema:description ?description .
        FILTER (lang(?description) = "en")
        FILTER (lang(?label) = "en" || lang(?label) = "de" || lang(?label) = "fr" || lang(?label) = "it")
    }
}
UNION
{
    GRAPH  <http://data.alod.ch/graph/wikidata> {
      ?s ?p ?o
    }
}
}
前缀wdt:
前缀架构:
删除{GRAPH{s?p?o}
插入{图{
?概念wdt:P902?hls;
rdfs:标签?标签;
模式:描述?描述。
}}在哪里{
{
服务{
?概念wdt:P902?hls。
?概念RDF:标签?标签。
?概念模式:描述?描述。
过滤器(lang(?description)=“en”)
过滤器(lang(?label)=“en”| lang(?label)=“de”| lang(?label)=“fr”| lang(?label)=“it”)
}
}
联合
{
图表{
?s?p?o
}
}
}

AFAIK,您可以在一个批中执行多个SPARQL 1.1 Update语句,并除以
。考虑到这一点,我建议I)通过
delete WHERE{s?p?o}
删除图形,或者更有效地使用like ii)
CLEAR
有趣的想法,我在规范中找不到任何指针?同样,这仍然是原子的方式吗?参考文献在第一段中,非正式地引用了相关部分:“请求是一个操作序列,由EOF(文件结尾)终止。多个操作用“;”(分号)分隔字符。请求中最后一个操作后的分号是可选的。实现必须确保以一种方式执行单个请求的操作,以保证与按照它们在请求中出现的顺序顺序执行它们相同的效果。“关于原子性,我不知道-但第二段说:“如果一个请求中存在多个操作,则任何操作的失败结果都必须中止操作序列,从而导致后续操作被忽略。”也许您不需要删除所有16000个实体,然后重新加载它们,而只需要最近更新的实体。类似这样的情况:​<代码>?概念wdt:P902?hls。?概念模式:dateModified?date.FILTER(?date>“2018-02-28T00:00:00Z”^^xsd:dateTime)
。酷tnx,不知道这一点