tbloader vs SPARQL INSERT - Why different behaviour with named graphs?

时光毁灭记忆、已成空白 提交于 2019-12-01 18:49:53

Try this query:

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

and the output is

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

or try:

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

to get the results in a different form.

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

What you are seeing is that

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

used data exactly as is to name the graph. But

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

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

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 :.

Finally try:

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

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> |
----------------------------------------------------------------------------------------------------------------
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!