tbloader与SPARQL INSERT-为什么命名图具有不同的行为? [英] tbloader vs SPARQL INSERT - Why different behaviour with named graphs?

查看:108
本文介绍了tbloader与SPARQL INSERT-为什么命名图具有不同的行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ARQ,TDB和命名图的命令行工具连接时出现奇怪的行为.如果在指定的图中通过tdbloader导入数据,则无法通过SPARQL SELECT查询中的GRAPH子句对其进行查询.但是,当使用SPARQL INSERT在同一图中插入数据时,可以进行此查询.

There is a strange behaviour in the connection of the commandline tools of ARQ, TDB and Named Graphs. If importing data via tdbloader in a named graph it can not be queried via GRAPH clause in a SPARQL SELECT query. However, this query is possible when inserting the data in the same graph with SPARQL INSERT.

我有以下汇编程序描述文件 tdb.ttl :

I have following assembler description file tdb.ttl:

@prefix rdfs:   <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf:    <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix ja:     <http://jena.hpl.hp.com/2005/11/Assembler#> .
@prefix tdb:     <http://jena.hpl.hp.com/2008/tdb#> .


[] ja:loadClass "com.hp.hpl.jena.tdb.TDB" .
tdb:DatasetTDB  rdfs:subClassOf  ja:RDFDataset .
tdb:GraphTDB    rdfs:subClassOf  ja:Model .

[] rdf:type         tdb:DatasetTDB ;
    tdb:location "DB" ;
.

文件 data.ttl 中有一个数据集:

<a> <b> <c>.

现在,我要使用tdbloader插入此数据,其次使用SPARQL INSERT插入另一个数据,都在命名图 data 中:

Now, I am inserting this data with tdbloader and secondly another triple with SPARQL INSERT, both in the named graph data:

tdbloader --desc tdb.ttl --graph data data.ttl
update --desc tdb.ttl "INSERT DATA {GRAPH <data> {<d> <e> <f>.}}"

现在,可以通过以下方式使用SPARQL查询数据:

Now, the data can be queried with SPARQL via:

$arq --desc tdb.ttl "SELECT *  WHERE{ GRAPH ?g {?s ?p ?o.}}"
----------------------------
| s   | p   | o   | g      |
============================
| <a> | <b> | <c> | <data> |
| <d> | <e> | <f> | <data> |
----------------------------

一切似乎都很完美.但是现在我只想查询这个特定的名为图 data 的图形:

Everything seems perfect. But now I want to query only this specifc named graph data:

$ arq --desc tdb.ttl "SELECT *  WHERE{ GRAPH <data> {?s ?p ?o.}}"
-------------------
| s   | p   | o   |
===================
| <d> | <e> | <f> |
-------------------

为什么从tdbloader导入的数据丢失了?此查询有什么问题?如何从两次导入中获得结果?

Why is the data imported from tdbloader missing? What is wrong with this query? How can I get results back from both imports?

推荐答案

尝试以下查询:

PREFIX : <data>
SELECT * { { ?s ?p ?o } UNION { GRAPH ?g { ?s ?p ?o } } }

,输出为

----------------------------
| s   | p   | o   | g      |
============================
| <a> | <b> | <c> | <data> |
| <d> | <e> | <f> | :      |
----------------------------

或尝试:

 tdbquery --loc DB --file Q.rq -results srj

以另一种形式获得结果.

to get the results in a different form.

文本输出看起来很漂亮,但是最终出现了两个不同的结果,即<data>.

The text output is makign things look nice but two different things end up as <data>.

您看到的是

tdbloader --desc tdb.ttl --graph data data.ttl

使用data的方式与为图形命名的方式完全相同.但是

used data exactly as is to name the graph. But

INSERT DATA {GRAPH <data> {<d> <e> <f>.}}

执行完整的SPARQL解析,并针对基本URI进行解析,可能看起来像file://*currentdirectory*.

does a full SPARQL parse, and resolves against the base URI, probably looking like file://*currentdirectory*.

以文本打印时,URI会缩写,包括使用基数.因此,原始的data(来自tdbloader)和file:///path/data都显示为<data>.

When printing in text, URIs get abbreviated, including using the base. So both the original data (from tdbloader) and file:///path/data appear as <data>.

PREFIX : <data>

使文本输出以另一种方式写为:.

gives the text output a different way to write it as :.

最后尝试:

BASE <http://example/>
SELECT * { { ?s ?p ?o } UNION { GRAPH ?g { ?s ?p ?o } } }

将基本URI设置为您的数据URI附近的任何地方,因此请关闭基本URI的良好格式:

which sets the base URI to something no where near your data URIs so switching off nice formatting by base URI:

----------------------------------------------------------------------------------------------------------------
| s                        | p                        | o                        | g                           |
================================================================================================================
| <file:///home/afs/tmp/a> | <file:///home/afs/tmp/b> | <file:///home/afs/tmp/c> | <data>                      |
| <file:///home/afs/tmp/d> | <file:///home/afs/tmp/e> | <file:///home/afs/tmp/f> | <file:///home/afs/tmp/data> |
----------------------------------------------------------------------------------------------------------------

这篇关于tbloader与SPARQL INSERT-为什么命名图具有不同的行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆