Questions about SPARQL Graph #461
Replies: 5 comments 1 reply
-
It sounds like you have it right. In the SPARQL language, MINUS specifies a section of the query which must not be satisfied in order for a pattern to match. Since SPARQL is a W3C standard (not ours) there are lots of examples and tutorials out there. Do note that SPARQLgraph doesn't yet support the entire language, but a big chunk of it. This might help: stackoverflow: select the negative of a sparql query RACK ships with a couple queries (they have "without" in their names) that use MINUS. Consider "query Requirements without Tests": This one finds all REQUIREMENTS that are not verified by a TEST. Two subtlties:
Hope this helps |
Beta Was this translation helpful? Give feedback.
-
Thanks - I have a reasonable understanding of SPARQL from reviewing some of
the tutorials and examples out there, but isn’t always obvious how to
express them using SPARQLGraph, which is why I asked if there was any
SPARQLGraph documentation available.
|
Beta Was this translation helpful? Give feedback.
-
In principle, I would like to use MINUS between two sub-graphs, but I'm not sure this is consistent with SPARQL syntax and it doesn't seem to be allowed by SPARQLGraph, which only allows MINUS to be applied to a property or a relationship. As a simple example, consider the query "All Requirements whose identifier is not HLR-2" (the actual query is more complex). I could write this in SPARQL as follows:
However, when I tried to construct this query in SPARQL Graph using MINUS, I got this query, which returns nothing:
I'm not sure if this behaviour is a bug or a feature of SPARQL Graph. |
Beta Was this translation helpful? Give feedback.
-
In SPARQL, the MINUS keyword means that the overall query will not match if an instance of this data property exists. |
Beta Was this translation helpful? Give feedback.
-
My apologies - I thought I did have a counter-example, but you're right, the list of returned variables at the top of the query changes when you check and un-check the return box, even though the body of the query remains unchanged. However, I still think that SPARQL Graph is constructing the wrong query for my example. This isn't about whether the query is valid SPARQL or whether it returns sensible results, but whether the query is what the user expects the query to be, in other words, whether the semantics of SPARQL Graph queries is natural. I also think your characterisation of MINUS is incorrect - as I understand it, MINUS is used to subtract one graph from another. So MINUS applies to graph patterns, not individual terms. This is at the root of our disagreement. The issue is whether RETURN takes precedence over MINUS, in other words, whether RETURN applies to the left hand graph as well as the right hand graph. I think this is a reasonable interpretation of the graphical query, particularly given that RETURN is above MINUS in the layout of the query boxes, so I think that SPARQL Graph should translate "RETURN MINUS identifier" as
This returns exactly the same as your query, so there's no difference in behaviour for the simple case. However, when you add in a FILTER, the query works more naturally:
This returns what I would expect, namely all the identifiers that do not match Note that it is necessary to match
See the discussion of the relationship between NOT EXISTS and MINUS in the w3c specification: |
Beta Was this translation helpful? Give feedback.
-
I have been trying to construct some complex queries using SPARQL Graph and would appreciate some help. Is there any documentation available? The SemTK Advanced Queries page is helpful, but it mainly talks about UNION and doesn't explain how MINUS works.
For example, suppose I have constructed a query that returns all the requirements that satisfy a certain property. How would I invert this query to return all the requirements that don't satisfy the property? Is it possible to do something like
All requirements MINUS All requirements that satisfy property
Or is this the wrong way to think about the query?
More generally, how do you compose queries to build more complex queries?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions