On 06/05/2022 16:34, Nouwt, B. (Barry) wrote:
Just tried to move the VALUES clause of the second query inside the WHERE 
clause and now it gives the same result as the first query. I am using the 
Query# setValuesDataBlock(...) method to set the values programmatically. Can I 
control where this method puts the VALUES clause?


yes - by syntax.

If it is outside the WHERE pattern at the end, the query is

  "do WHERE pattern, THEN join with the values"

so filtering happen before ?sat value is handled. It is an unbound variable in FILTER NOT EXISTS

FILTER NOT EXISTS {
  ?anyVariableNameNoWheerElseInTheQuery a  ?someClass
}

If it is first then the query is

"join(values and ?req a  ?someClass) then filter."

?sat set by the VALUES, then FILER NOT EXISTS happens.

so the order affects whether VALUEs is before or after the filtering. Hence whether ?sat is an unboudn valriable or a single term and in NOT EXISTS that very different.

    Andy




Regards, Barry

-----Original Message-----
From: Nouwt, B. (Barry) <[email protected]>
Sent: vrijdag 6 mei 2022 17:26
To: [email protected]
Subject: RE: SPARQL question

I also tried the two queries below using Virtuoso instead of Apache Jena, but 
Virtuoso behaves the same with the first query, but gives the following parse 
error with the second query:

Virtuoso S0022 Error SQ200: No column sat.

-----Original Message-----
From: Nouwt, B. (Barry) <[email protected]>
Sent: vrijdag 6 mei 2022 17:21
To: [email protected]
Subject: RE: SPARQL question

Just found the following Stack Overflow question which looks related: 
https://stackoverflow.com/questions/56891312/difference-in-performance-between-using-values-keyword-and-using-directly-the-ur

Although they talk mostly about the difference in performance between the two 
approaches and not about the difference in semantics.


-----Original Message-----
From: Nouwt, B. (Barry) <[email protected]>
Sent: vrijdag 6 mei 2022 17:16
To: [email protected]
Subject: SPARQL question

Hi everyone, two SPARQL queries which I assumed are the same give different 
results in Apache Jena. The two queries are:

SELECT * WHERE {
<https://www.tno.nl/kb1/meta/knowledgeinteractions/react/changed/act/requirement> a  
?someClass FILTER NOT EXISTS { 
<https://www.tno.nl/kb2/meta/knowledgeinteractions/post/new/act/satisfaction> a  
?someClass } }

SELECT * WHERE
{
?req a  ?someClass
FILTER NOT EXISTS {
?sat a  ?someClass
}
}
VALUES (?req ?sat) {
(<https://www.tno.nl/kb1/meta/knowledgeinteractions/react/changed/act/requirement> 
<https://www.tno.nl/kb2/meta/knowledgeinteractions/post/new/act/satisfaction>)
}

Note that the queries are basically the same, but the second query uses the 
VALUES keyword to bind the ?req and ?sat variables, while the first query 
replaces the actual ?req and ?sat variables occurrences instead.

Does anyone know what I am missing?

Best regards,

Barry
This message may contain information that is not intended for you. If you are 
not the addressee or if this message was sent to you by mistake, you are 
requested to inform the sender and delete the message. TNO accepts no liability 
for the content of this e-mail, for the manner in which you use it and for 
damage of any kind resulting from the risks inherent to the electronic 
transmission of messages.

Reply via email to