带有SERVICE语句的SPARQL DELETE / INSERT

问题描述 投票:1回答:1

我正在为维基数据中的某些数据创建本地缓存,以确保我有快速的标签自动完成功能。我想每周更新一次数据,但仅限于SERVICE子句有效。

基本上我做:

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")
}}

现在我以为我可以执行DELETE / INSERT并首先删除所有数据:

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
}

但是像这样看起来我从维基数据上得到了400回。我在没有SERVICE的情况下执行类似的DELETE / INSERT但是我不明白为什么这不会像这样工作,因为我没有绑定现有图形和SERVICE查询之间的任何变量。

有谁看到这里出了什么问题?基本上我想擦除现有的图形,但在维基数据关闭的情况下不会以空图形结束。

sparql wikidata federated-queries
1个回答
2
投票

感谢用户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
    }
}
}
© www.soinside.com 2019 - 2024. All rights reserved.