|
Hi! I ran into an issue that requires me to find all subjects, for which only triples with specified predicates, but no other kinds of triples exist. Or, thinking the other way round, I want to exclude all subjects having triples with predicates different than the ones specified. Generally, those subjects have the specified specified predicates too, but do have different predicates as well. As a minimal example:
For example, I would like to query for everyone who does nothing else than "hate" or "love" any kind of hobby. So, in this case, I would want s:tom as a result. I have been trying to get this to work with my limited SPARQL knowledge by playing around with Subqueries, MINUS, FILTERS and just can't get it to work. Using FILTER I managed to exclude triples with the specified predicates and therefore got the subjects having more predicates than the specified ones. I thought that it should maybe possible to use this in a Subquery to get what I need, but I could neither get that to work, nor do I know whether it makes sense or if there are better alternatives. Another similar issue on here ( http://answers.semanticweb.com/questions/628/limiting-results-in-sparql-to-subjects-with-only-one-predicate-of-a-certain-type ) couldn't help me out either. As a note: I am using Jena Arq 2.7 with the advanced parser for SPARQL 1.1 functionality. Thanks in advance, any help would be appreciated! |
|
Not sure about performance on large datasets, but you could try something like:
5
Nice use of the not in filter operator!
The following will work in a very recent sparql engine. Introduces unions which might perform better than filters.
1
@Jerven, you need another negation ... you need to say that @Signified, thanks for letting me know. I had misread the question. Then the answer by @AB is definitely the correct one. Introducing a MINUS around the ?s ?q ?y will be unlikely to improve the performance. |

