You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Erich Bremer <er...@ebremer.com> on 2013/12/11 03:56:00 UTC

odd SPARQL MINUS behavior Jena 2.11.0

In the following segment of code:

String queryString = "construct {?s a ?o} where {?s a ?o minus {?s a 
<http://xmlns.com/foaf/0.1/Person>}}";
Query query = QueryFactory.create(queryString);
QueryExecution qe = QueryExecutionFactory.create(query,m);
Model whoa = qe.execConstruct();

Rather than remove just the pattern {?s a 
<http://xmlns.com/foaf/0.1/Person>}, it removes all types as if the 
MINUS pattern was {?s a ?p}

     - Erich
========================
http://www.ebremer.com
http://haylyn.io

Re: odd SPARQL MINUS behavior Jena 2.11.0

Posted by Erich Bremer <er...@ebremer.com>.
So, if I understand this correctly, if my data is:

<http://sample.com/p1> a :Person; name "Person A"; :nick "Buddy"; 
:status "Living" .
<http://sample.com/p2> a :Person; name "Person B"; :nick "Bro"; :status 
"Living" .
<http://sample.com/p3> a :DeadPerson; name "Person C"; :nick "Butch"; 
:status "Dead" .

and I give the command:

construct {?s ?p ?o} where {?s ?p ?o minus {?s ?p 
<http://xmlns.com/foaf/0.1/DeadPerson>}}"

then I should get the resultant graph:

<http://sample.com/p1> a :Person; name "Person A"; :nick "Buddy"; 
:status "Living" .
<http://sample.com/p2> a :Person; name "Person B"; :nick "Bro"; :status 
"Living" .

      Would this be correct?  - Erich

On 12/11/13 4:25 AM, Andy Seaborne wrote:
> On 11/12/13 02:56, Erich Bremer wrote:
>> In the following segment of code:
>>
>> String queryString = "construct {?s a ?o} whereccc minus {?s a
>> <http://xmlns.com/foaf/0.1/Person>}}";
>> Query query = QueryFactory.create(queryString);
>> QueryExecution qe = QueryExecutionFactory.create(query,m);
>> Model whoa = qe.execConstruct();
>>
>> Rather than remove just the pattern {?s a
>> <http://xmlns.com/foaf/0.1/Person>}, it removes all types as if the
>> MINUS pattern was {?s a ?p}
>
> Sound like you want:
>
> FILTER (?o != <http://xmlns.com/foaf/0.1/Person>)
>
> which just excludes any (?s, ?o) row where ?o is foaf:Person.
>
> MINUS will take the left-hand side  "?s a ?o" and the right-hand side
> { ?s a foaf:Person}, and remove all rows from the LHS that match 
> (=join) with the RHS.
>
> So it removes all rows involving ?s where there is a match for
>  {?s a <http://xmlns.com/foaf/0.1/Person>}
>
> See also
>
> FILTER NOT EXISTS {?s a <http://xmlns.com/foaf/0.1/Person>}
>
> which applies a test to ?s for every row to see if can be matched.
>
> In both MINUS and FILTER NOT EXISTS, ?o is not playing a part - it's 
> not mentioned in the negation side and, in this case, MINUS and FILTER 
> NOT EXISTS have the same outcome.
>
>     Andy
>
>>
>>      - Erich
>> ========================
>> http://www.ebremer.com
>> http://haylyn.io
>


Re: odd SPARQL MINUS behavior Jena 2.11.0

Posted by Andy Seaborne <an...@apache.org>.
On 11/12/13 02:56, Erich Bremer wrote:
> In the following segment of code:
>
> String queryString = "construct {?s a ?o} whereccc minus {?s a
> <http://xmlns.com/foaf/0.1/Person>}}";
> Query query = QueryFactory.create(queryString);
> QueryExecution qe = QueryExecutionFactory.create(query,m);
> Model whoa = qe.execConstruct();
>
> Rather than remove just the pattern {?s a
> <http://xmlns.com/foaf/0.1/Person>}, it removes all types as if the
> MINUS pattern was {?s a ?p}

Sound like you want:

FILTER (?o != <http://xmlns.com/foaf/0.1/Person>)

which just excludes any (?s, ?o) row where ?o is foaf:Person.

MINUS will take the left-hand side  "?s a ?o" and the right-hand side
{ ?s a foaf:Person}, and remove all rows from the LHS that match (=join) 
with the RHS.

So it removes all rows involving ?s where there is a match for
  {?s a <http://xmlns.com/foaf/0.1/Person>}

See also

FILTER NOT EXISTS {?s a <http://xmlns.com/foaf/0.1/Person>}

which applies a test to ?s for every row to see if can be matched.

In both MINUS and FILTER NOT EXISTS, ?o is not playing a part - it's not 
mentioned in the negation side and, in this case, MINUS and FILTER NOT 
EXISTS have the same outcome.

	Andy

>
>      - Erich
> ========================
> http://www.ebremer.com
> http://haylyn.io


Re: odd SPARQL MINUS behavior Jena 2.11.0

Posted by Rob Vesse <rv...@dotnetrdf.org>.
You haven't given any other details of your problem I.e. data but the
behaviour as described sounds in line with the specification for MINUS.
MINUS finds all matches for its pattern and then does a set subtraction
based on the bound variables.

So your pattern { ?s a <http://xmlns.com/foaf/0.1/person> } matches all
things declared as type foaf:Person in the data binding the associated
subject to ?s.  It then subtracts any matching solutions from the LHS, so
if a given ?s is declared to be a foaf:Person then all matches pertaining
to ?s will be removed from the LHS.

It sounds like what you actually want to do is exclude foaf:Person type
declarations?

In this case neither MINUS nor FILTER NOT EXISTS will do what you want and
you have to use a simpler filter e.g.

CONSTRUCT
{
  ?s a ?o
}
WHERE
{
  ?s a ?o .
  FILTER(!SAMETERM(?o, <http://xmlns.com/foaf/0.1/Person>))
}

Hope this helps,

Rob

On 11/12/2013 02:56, "Erich Bremer" <er...@ebremer.com> wrote:

>In the following segment of code:
>
>String queryString = "construct {?s a ?o} where {?s a ?o minus {?s a
><http://xmlns.com/foaf/0.1/Person>}}";
>Query query = QueryFactory.create(queryString);
>QueryExecution qe = QueryExecutionFactory.create(query,m);
>Model whoa = qe.execConstruct();
>
>Rather than remove just the pattern {?s a
><http://xmlns.com/foaf/0.1/Person>}, it removes all types as if the
>MINUS pattern was {?s a ?p}
>
>     - Erich
>========================
>http://www.ebremer.com
>http://haylyn.io