You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Milorad Tosic <mb...@yahoo.com> on 2013/10/02 11:41:25 UTC

semantics of the FROM clause in SPARQL queries

Hi,

What is the intended semantics of the FROM clause in SPARQL queries? I got confused with the results of the following tests that I run against a rdf store (arq-2.8.7, jena-2.6.4, tdb-0.8.9):

Let us have two datasets in a single triplestore:
PREFIX ex: <http://www.example.info>

ex:ds1 { <ex:r><ex:p1><ex:o1> . }
ex:ds2 { <ex:r><ex:p2><ex:o2> . }
(each of the datasets contains a single triplet, each of the triplets has the same subject <ex:r>.)

Let us now run the query that is going to return all triplets from the triplestore that have <ex:r> as a subject. It should be like this:
PREFIX ex: <http://www.example.info>
FROM <ex:ds1>

FROM <ex:ds2>
SELECT ?p ?o WHERE {
 <ex:r> ?p ?o .

}

As expected, we get the following results:

?p           ?o

<ex:p1>  <ex:o1>
<ex:p2>  <ex:o2>

Next, let us run the following query ("return all resources that have a property with value  <ex:o1> and a property with value  <ex:o2>" would be an non-formal not-necessarily correct interpretation in English language):
PREFIX ex: <http://www.example.info>
FROM <ex:ds1>

FROM <ex:ds2>
SELECT ?s WHERE {
 ?s ?p1 <ex:o1> .
 ?s ?p2 <ex:o2> .

}

One would expect the following result:
?s

<ex:r>
Rationale for the expectation is that FROM clause constructs union of the default graph and the graphs specified by FROM statements in the query, and then runs rest of the query against the union of graphs.

However, experimentation results are different: The query returns an EMPTY result.
Rationale for the obtained results is that query was run against each individual dataset and then the union of results is returned.

So, is my expectation wrong because of misinterpretation of the standard specification or it is a bug in the version of Jena that I work with?

Thanks,
Milorad

Re: semantics of the FROM clause in SPARQL queries

Posted by Diogo FC Patrao <dj...@gmail.com>.
Hi Milorad

According to the sparql reference, multiple FROM clauses should mean a
query over the merge of all specified datasets, so the expected results you
presented should be returned indeed. Is this a bug?

http://www.w3.org/TR/sparql11-query/#unnamedGraph

Cheers

Dfcp
 Em 02/10/2013 06:42, "Milorad Tosic" <mb...@yahoo.com> escreveu:

> Hi,
>
> What is the intended semantics of the FROM clause in SPARQL queries? I got
> confused with the results of the following tests that I run against a rdf
> store (arq-2.8.7, jena-2.6.4, tdb-0.8.9):
>
> Let us have two datasets in a single triplestore:
> PREFIX ex: <http://www.example.info>
>
> ex:ds1 { <ex:r><ex:p1><ex:o1> . }
> ex:ds2 { <ex:r><ex:p2><ex:o2> . }
> (each of the datasets contains a single triplet, each of the triplets has
> the same subject <ex:r>.)
>
> Let us now run the query that is going to return all triplets from the
> triplestore that have <ex:r> as a subject. It should be like this:
> PREFIX ex: <http://www.example.info>
> FROM <ex:ds1>
>
> FROM <ex:ds2>
> SELECT ?p ?o WHERE {
>  <ex:r> ?p ?o .
>
> }
>
> As expected, we get the following results:
>
> ?p           ?o
>
> <ex:p1>  <ex:o1>
> <ex:p2>  <ex:o2>
>
> Next, let us run the following query ("return all resources that have a
> property with value  <ex:o1> and a property with value  <ex:o2>" would be
> an non-formal not-necessarily correct interpretation in English language):
> PREFIX ex: <http://www.example.info>
> FROM <ex:ds1>
>
> FROM <ex:ds2>
> SELECT ?s WHERE {
>  ?s ?p1 <ex:o1> .
>  ?s ?p2 <ex:o2> .
>
> }
>
> One would expect the following result:
> ?s
>
> <ex:r>
> Rationale for the expectation is that FROM clause constructs union of the
> default graph and the graphs specified by FROM statements in the query, and
> then runs rest of the query against the union of graphs.
>
> However, experimentation results are different: The query returns an EMPTY
> result.
> Rationale for the obtained results is that query was run against each
> individual dataset and then the union of results is returned.
>
> So, is my expectation wrong because of misinterpretation of the standard
> specification or it is a bug in the version of Jena that I work with?
>
> Thanks,
> Milorad

Re: semantics of the FROM clause in SPARQL queries

Posted by Andy Seaborne <an...@apache.org>.
On 02/10/13 13:27, james anderson wrote:
> good afternoon.
>
> On 2 Oct 2013, at 12:27 PM, Andy Seaborne wrote:
>
> with respect to part of the originally posed question:
>
>>> Rationale for the expectation is that FROM clause constructs union of the default graph and the graphs specified by FROM statements in the query, and then runs rest of the query against the union of graphs.
>>>
>>> However, experimentation results are different: The query returns an EMPTY result.
>>> Rationale for the obtained results is that query was run against each individual dataset and then the union of results is returned.
>>
>
> in particular, the expectation that the active graph include the default graph from the store, if the store were to contain
>
> PREFIX ex: <http://www.example.info>
>
> ex:ds1 { <ex:r><ex:p1><ex:o1> . }
> ex:ds2 { <ex:r><ex:p2><ex:o2> . }
>   <ex:r><ex:p2><ex:o3> .
>
> would the posed query,
>
> PREFIX ex: <http://www.example.info>
> FROM <ex:ds1>
> FROM <ex:ds2>
> SELECT ?p ?o WHERE {
>   <ex:r> ?p ?o .
>
> }
>
>
> include "<ex:p2><ex:o3> " ?

No - the default graph becomes the union of the named graph and the 
original default graph is not visible.

(well, it is accessible via the synthetic name <urn:x-arq:DefaultGraph> 
which specifically accesses the real default graph regardless of 
anything else.)

	Andy

>
>
>
>
> ---
> james anderson | james@dydra.com | http://dydra.com
>
>
>
>
>
>


Re: semantics of the FROM clause in SPARQL queries

Posted by Rob Vesse <rv...@dotnetrdf.org>.
No it should not

If FROM or FROM NAMED are present then the dataset should consist solely
of those graphs ignoring any default dataset description the service would
otherwise use

Rob

On 10/2/13 1:27 PM, "james anderson" <ja...@dydra.com> wrote:

>good afternoon.
>
>On 2 Oct 2013, at 12:27 PM, Andy Seaborne wrote:
>
>with respect to part of the originally posed question:
>
>>> Rationale for the expectation is that FROM clause constructs union of
>>>the default graph and the graphs specified by FROM statements in the
>>>query, and then runs rest of the query against the union of graphs.
>>> 
>>> However, experimentation results are different: The query returns an
>>>EMPTY result.
>>> Rationale for the obtained results is that query was run against each
>>>individual dataset and then the union of results is returned.
>> 
>
>in particular, the expectation that the active graph include the default
>graph from the store, if the store were to contain
>
>PREFIX ex: <http://www.example.info>
>
>ex:ds1 { <ex:r><ex:p1><ex:o1> . }
>ex:ds2 { <ex:r><ex:p2><ex:o2> . }
> <ex:r><ex:p2><ex:o3> .
>
>would the posed query,
>
>PREFIX ex: <http://www.example.info>
>FROM <ex:ds1>
>FROM <ex:ds2>
>SELECT ?p ?o WHERE {
> <ex:r> ?p ?o .
>
>}
>
>
>include "<ex:p2><ex:o3> " ?
>
>
>
>
>---
>james anderson | james@dydra.com | http://dydra.com
>
>
>
>
>





Re: semantics of the FROM clause in SPARQL queries

Posted by james anderson <ja...@dydra.com>.
good afternoon.

On 2 Oct 2013, at 12:27 PM, Andy Seaborne wrote:

with respect to part of the originally posed question:

>> Rationale for the expectation is that FROM clause constructs union of the default graph and the graphs specified by FROM statements in the query, and then runs rest of the query against the union of graphs.
>> 
>> However, experimentation results are different: The query returns an EMPTY result.
>> Rationale for the obtained results is that query was run against each individual dataset and then the union of results is returned.
> 

in particular, the expectation that the active graph include the default graph from the store, if the store were to contain

PREFIX ex: <http://www.example.info>

ex:ds1 { <ex:r><ex:p1><ex:o1> . }
ex:ds2 { <ex:r><ex:p2><ex:o2> . }
 <ex:r><ex:p2><ex:o3> .

would the posed query,

PREFIX ex: <http://www.example.info>
FROM <ex:ds1>
FROM <ex:ds2>
SELECT ?p ?o WHERE {
 <ex:r> ?p ?o .

}


include "<ex:p2><ex:o3> " ?




---
james anderson | james@dydra.com | http://dydra.com






Re: semantics of the FROM clause in SPARQL queries

Posted by Milorad Tosic <mb...@yahoo.com>.
Thank you all. I'll give a chance to a more recent version of Jena.

Regards,
Milorad





>________________________________
> From: Andy Seaborne <an...@apache.org>
>To: users@jena.apache.org 
>Sent: Wednesday, October 2, 2013 12:27 PM
>Subject: Re: semantics of the FROM clause in SPARQL queries
> 
>
>On 02/10/13 10:41, Milorad Tosic wrote:
>
>> (arq-2.8.7, jena-2.6.4, tdb-0.8.9)
>
>Quite old.  Thgere may well have been fixes.
>
>> Next, let us run the following query ("return all resources that have a property with value  <ex:o1> and a property with value  <ex:o2>" would be an non-formal not-necessarily correct interpretation in English language):
>> PREFIX ex:<http://www.example.info>
>> FROM <ex:ds1>
>>
>> FROM <ex:ds2>
>> SELECT ?s WHERE {
>>   ?s ?p1 <ex:o1> .
>>   ?s ?p2 <ex:o2> .
>>
>> }
>>
>> One would expect the following result:
>> ?s
>>
>> <ex:r>
>> Rationale for the expectation is that FROM clause constructs union of the default graph and the graphs specified by FROM statements in the query, and then runs rest of the query against the union of graphs.
>>
>> However, experimentation results are different: The query returns an EMPTY result.
>> Rationale for the obtained results is that query was run against each individual dataset and then the union of results is returned.
>
>While I agree the results are wrong (try the current version), this 
>isn't a corect statement of why.
>
>{
>   ?s ?p1 <ex:o1> .
>   ?s ?p2 <ex:o2> .
>}
>
>both parts must match for the same ?s
>
>Each triple pattern is matched agains the combined graph, with duplicate 
>supression so the combined graoph really is a set of triples.  There is 
>no union going on after some matching, it happens as each triple pattern 
>is matched.
>
>It has to be that way:
>1/ Get the right cardinality
>2/ patterns can span graphs
>
>c.f the different:
>
>GRAPH ?g {
>    ?s ?p1 <ex:o1> .
>    ?s ?p2 <ex:o2> .
>}
>
>where the pattern does not span graphs.
>
>    Andy
>
>
>
>
>
>

Re: semantics of the FROM clause in SPARQL queries

Posted by Rob Vesse <rv...@dotnetrdf.org>.
I believe there have been.  I wrote a selection of unit tests around
dataset descriptions at one point and I remember making some fixes to the
relevant code so this may indeed already be fixed

Rob

On 10/2/13 11:27 AM, "Andy Seaborne" <an...@apache.org> wrote:

>On 02/10/13 10:41, Milorad Tosic wrote:
>
> > (arq-2.8.7, jena-2.6.4, tdb-0.8.9)
>
>Quite old.  Thgere may well have been fixes.
>
>> Next, let us run the following query ("return all resources that have a
>>property with value  <ex:o1> and a property with value  <ex:o2>" would
>>be an non-formal not-necessarily correct interpretation in English
>>language):
>> PREFIX ex:<http://www.example.info>
>> FROM <ex:ds1>
>>
>> FROM <ex:ds2>
>> SELECT ?s WHERE {
>>   ?s ?p1 <ex:o1> .
>>   ?s ?p2 <ex:o2> .
>>
>> }
>>
>> One would expect the following result:
>> ?s
>>
>> <ex:r>
>> Rationale for the expectation is that FROM clause constructs union of
>>the default graph and the graphs specified by FROM statements in the
>>query, and then runs rest of the query against the union of graphs.
>>
>> However, experimentation results are different: The query returns an
>>EMPTY result.
>> Rationale for the obtained results is that query was run against each
>>individual dataset and then the union of results is returned.
>
>While I agree the results are wrong (try the current version), this
>isn't a corect statement of why.
>
>{
>   ?s ?p1 <ex:o1> .
>   ?s ?p2 <ex:o2> .
>}
>
>both parts must match for the same ?s
>
>Each triple pattern is matched agains the combined graph, with duplicate
>supression so the combined graoph really is a set of triples.  There is
>no union going on after some matching, it happens as each triple pattern
>is matched.
>
>It has to be that way:
>1/ Get the right cardinality
>2/ patterns can span graphs
>
>c.f the different:
>
>GRAPH ?g {
>    ?s ?p1 <ex:o1> .
>    ?s ?p2 <ex:o2> .
>}
>
>where the pattern does not span graphs.
>
>	Andy
>
>
>





Re: semantics of the FROM clause in SPARQL queries

Posted by Andy Seaborne <an...@apache.org>.
On 02/10/13 10:41, Milorad Tosic wrote:

 > (arq-2.8.7, jena-2.6.4, tdb-0.8.9)

Quite old.  Thgere may well have been fixes.

> Next, let us run the following query ("return all resources that have a property with value  <ex:o1> and a property with value  <ex:o2>" would be an non-formal not-necessarily correct interpretation in English language):
> PREFIX ex:<http://www.example.info>
> FROM <ex:ds1>
>
> FROM <ex:ds2>
> SELECT ?s WHERE {
>   ?s ?p1 <ex:o1> .
>   ?s ?p2 <ex:o2> .
>
> }
>
> One would expect the following result:
> ?s
>
> <ex:r>
> Rationale for the expectation is that FROM clause constructs union of the default graph and the graphs specified by FROM statements in the query, and then runs rest of the query against the union of graphs.
>
> However, experimentation results are different: The query returns an EMPTY result.
> Rationale for the obtained results is that query was run against each individual dataset and then the union of results is returned.

While I agree the results are wrong (try the current version), this 
isn't a corect statement of why.

{
   ?s ?p1 <ex:o1> .
   ?s ?p2 <ex:o2> .
}

both parts must match for the same ?s

Each triple pattern is matched agains the combined graph, with duplicate 
supression so the combined graoph really is a set of triples.  There is 
no union going on after some matching, it happens as each triple pattern 
is matched.

It has to be that way:
1/ Get the right cardinality
2/ patterns can span graphs

c.f the different:

GRAPH ?g {
    ?s ?p1 <ex:o1> .
    ?s ?p2 <ex:o2> .
}

where the pattern does not span graphs.

	Andy