On 20/05/14 18:05, Joakim Soderberg wrote:
Thanks Andy,
That is also what I found out, and I can confirm that using:
SELECT * {
   { ?s ?p ?o } UNION { GRAPH ?g { ?s ?p ?o } }
}

retrieves triples from both default model and named model. But I am
curious to learn about alternatives, because  I'd really prefer to do
a  CONSTRUCT
query, and I don't think that will work with "GRAPH"

Try:

CONSTRUCT {
  ?s ?p ?o
} WHERE
{
  { ?s ?p ?o } UNION { GRAPH ?g { ?s ?p ?o } }
}

CONSTRUCT is templating over a general WHERE clause.

But it emits a graph (so no GRAPH in CONSTRUCT).

You might wish to use SPARQL Update

        Andy


/J



On Tue, May 20, 2014 at 1:29 AM, Andy Seaborne <[email protected]> wrote:

On 20/05/14 08:15, Joakim Soderberg wrote:

Hi,

I create a dataset with a unnamed default model and a named model

mDataset = TDBFactory.createDataset(tdbDirectory);

mDefaultModel = mDataset.getDefaultModel();
mDefaultModel = FileManager.get().loadModel(coreOntologyFile);


Model rtmodel = FileManager.get().loadModel("ontology/data1221.rdf");
if (mDataset.containsNamedModel("r1221"))
{
mDataset.getNamedModel("r1221");
} else {
          mDataset.getDataSet().addNamedModel("rt1221", rtmodel);
}



  From what I read, passing a dataset and not specifying "FROM NAMED" in
the
sparql query, should query both the unnamed model and named model, but it
only queries the default data set, e.g.


QueryExecution qe1 = QueryExecutionFactory.create( "SELECT * WHERE { ?s ?p
?o }", mDataset );

only returns data from the defaultmodel, unless if I explicitly pass the
named model

QueryExecution qe1 = QueryExecutionFactory.create( "SELECT * WHERE { ?s ?p
?o }", mDataset.getNamedModel("r1221") );

then I get triples from the named model. Adding FROM NAMED <e1221>

"SELECT * FROM NAMED <r1221> WHERE { ?s ?p ?o> }", mDataset

Does not help. Has anyone had the same problem?


try this query:

SELECT * {
   { ?s ?p ?o } UNION { GRAPH ?g { ?s ?p ?o } }
}

"SELECT * WHERE { ?s ?p ?o }" only accesses the default graph.  You need
GRAPH to get to the named graphs.

You can have many named graphs and make the default graph of the query by
the union of all named graphs (see documentation [*]), but the stored
default graph isn't then visible in { ?s ?p ?o }

         Andy

[*] http://jena.apache.org/documentation/tdb/datasets.html


best
J





Reply via email to