SPARQL-从远程端点插入数据 [英] SPARQL - Insert data from remote endpoint
问题描述
我如何查询远程端点(例如 DBPedia 或
How can i query a remote endpoint (like endpoints of DBPedia or Wikidata) and insert resulting triples in a local graph? So far, i know that there are commands like INSERT, ADD, COPY etc. which can be used for such tasks. What i don't understand is how to address a remote endpoint while updating my local graph. Could someone provide a minimum example or the main steps?
I'm using Apache Jena Fuseki v2 on Windows and this is my query so far:
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX wd: <http://www.wikidata.org/entity/>
INSERT
{ GRAPH <???> { ?s ?p ?o } } #don't know what to insert here for "GRAPH"
WHERE
{ GRAPH <???> #don't know what to insert here for "GRAPH" either
{ #a working example query for wikidata:
?s wdt:P31 wd:Q5. #humans
?s wdt:P54 wd:Q43310. #germans
?s wdt:P1344 wd:Q79859. #part of world cup 2014
?s ?p ?o.
}
}
我正在查询的本地端点是http://localhost:3030/mylocaldb/update
.我已经读过/update
是编辑数据库所必需的(虽然我不确定我是否正确理解).
到目前为止,我的方法正确吗?还是需要更多诸如SPARQL之外的其他脚本之类的东西?
My local endpoint i'm querying is http://localhost:3030/mylocaldb/update
. I've read that /update
is necessary to edit the database (i'm not sure if i understood that correctly though).
Is my approach correct so far? Or is more stuff like additional scripting outside SPARQL needed?
推荐答案
语法是
( WITH IRIref )?
INSERT QuadPattern
( USING ( NAMED )? IRIref )*
WHERE GroupGraphPattern
如果INSERT模板指定GRAPH块,那么这些将是受影响的图形.否则,该操作将应用于默认图形,或者分别应用于在WITH子句中指定的图形(如果已指定).如果不存在USING(NAMED)子句,则WHERE子句中的模式将与Graph Store匹配,否则将与USING(NAMED)子句指定的数据集匹配.与WHERE子句的匹配将创建绑定,该绑定将应用于模板以确定要插入的三元组(遵循与DELETE/INSERT相同的规则).
If the INSERT template specifies GRAPH blocks then these will be the graphs affected. Otherwise, the operation will be applied to the default graph, or, respectively, to the graph specified in the WITH clause, if one was specified. If no USING (NAMED) clause is present, then the pattern in the WHERE clause will be matched against the Graph Store, otherwise against the dataset specified by the USING (NAMED) clauses. The matches against the WHERE clause create bindings to be applied to the template for determining triples to be inserted (following the same rules as for DELETE/INSERT).
因此,这基本上意味着,如果要将GRAPH
定义存储在默认图形中,则可以从INSERT
部分中省略GRAPH
定义,否则它将是您要在其中存储数据的图形.
So this basically means, you can omit the GRAPH
definition from the INSERT
part if you want to store it in the default graph, otherwise it will be the graph in which you want to store the data.
关于WHERE
子句,通常必须在此处使用SERVICE
关键字在Wikidata终结点上应用联合查询(
Regarding the WHERE
clause, usually you would have to use the SERVICE
keyword here to apply federated querying on the Wikidata endpoint (https://query.wikidata.org/bigdata/namespace/wdq/sparql):
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX wd: <http://www.wikidata.org/entity/>
INSERT
{ ?s ?p ?o }
WHERE
{ SERVICE <https://query.wikidata.org/bigdata/namespace/wdq/sparql>
{ #a working example query for wikidata:
?s wdt:P31 wd:Q5. #humans
?s wdt:P54 wd:Q43310. #germans
?s wdt:P1344 wd:Q79859. #part of world cup 2014
?s ?p ?o.
}
}
我使用Apache Jena对其进行了测试,并将其插入了4462个三元组到我的本地数据集中.
I tested it with Apache Jena and it inserts 4462 triples into my local dataset.
这篇关于SPARQL-从远程端点插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!