An RDF Dataset is a collection of one, unnamed, default graph and zero, or more named graphs. In a SPARQL query, a query pattern is matched against the default graph unless the GRAPH keyword is applied to a pattern.
One file location (directory) is used to store one RDF dataset. The unnamed graph of the dataset is held as a single graph while all the named graphs are held in a collection of quad indexes.
Every dataset is obtained via TDBFactory.createDataset(Location) within a JVM is the same dataset. If a model is obtained from via TDBFactory.createModel(Location) there is a hidden, shared dataset and the appropriate model is returned.
There is full support for SPARQL query over named graphs in a TDB-back dataset.
All the named graphs can be treated as a single graph which is the union (RDF merge) of all the named graphs. This is given the special graph name <urn:x-arq:UnionGraph> in a GRAPH pattern.
When querying the RDF merge of named graphs, the default graph in the store is not included. This feature applies to queries only. It does not affect the storage nor does it change loading.
Alternatively, if the symbol tdb:unionDefaultGraph (see
TDB Configuration) is
set, the unnamed graph for the query is the union of all the named
graphs in the datasets. The stored default graph is ignored and is
not part of the the data of the union graph although it is
accessible by the special name <urn:x-arq:DefaultGraph\>
in a GRAPH
pattern.
Set globally:
TDB.getContext().set(TDB.symUnionDefaultGraph, true) ;
or set on a per query basis:
QueryExecution qExec = QueryExecutionFactory.create(...) ; qExec.getContext().set(TDB.symUnionDefaultGraph, true) ;
URI | Meaning |
---|---|
urn:x-arq:UnionGraph |
The RDF merge of all the named graphs in the datasets of the query. |
urn:x-arq:DefaultGraph |
The default graph of the dataset, used when the default graph of the query is the union graph. |
Note that setting tdb:unionDefaultGraph does not affect the default graph or default model obtained with dataset.getDefaultModel().
The RDF merge of all named graph can be accessed as the named graph
urn:x-arq:UnionGraph
using
Dataset.getNamedModel("urn:x-arq:UnionGraph")
.