2

Looking for a good way to return the results of all classes with missing definitions in a very large ontology. I'm using SPARQL Query in Protege 5.0. I can also use the DL query, but I'm not familiar with this one.

I tried to do a FILTER regex "definition", but it returned nothing. And if I do end up with all the classes that HAVE definitions, how would I be able to reverse that to return all that don't?

I'm happy to provide more detail if necessary, but I can't think of anything else at the moment.

R Jackson
  • 105
  • 3
  • 13

1 Answers1

4

If you want to find resources that don't have a value for a particular property, you can do it as in the following query. I don't know what definition property you're using (since you didn't mention it in the question), so you'd have to replace the <http://…/definition> in this query with the actual property that you're interested in.

select ?class {
  { ?class a owl:Class }
  minus
  { ?class <http://.../definition> ?def }
}
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • That's query is absolutely correct and the same results - in this case, but not in general - can be achieved using `FILTER NOT EXISTS` instead of `MINUS`. – Ivo Velitchkov Jun 16 '16 at 18:30
  • @IvoVelitchkov Yup, my default is to use filter not exists, but after [some comments yesterday](http://stackoverflow.com/questions/37832758/how-to-convert-model-checking-logic-query-to-sparql-query/37834303#comment63132273_37834303), I've had **minus** on the mind. – Joshua Taylor Jun 16 '16 at 18:45
  • 1
    I wonder, could we say that "if the two patterns share at least one variable, `MINUS` and `FILTER NOT EXISTS` are interchangeable" is a safe rule? Could there be an exception? And the opposite, is there a case when they could be interchangeable even if the patterns don't share a variable. I think not, but I'm not sure. – Ivo Velitchkov Jun 16 '16 at 19:01
  • 1
    @IvoVelitchkov **I think** that if they don't share a variable, then MINUS can't remove anything, since it's basically doing a join, and then *removing* the things that were joinable and keeping the rest, rather than *keeping* the joinable things and removing the rest. As for the case when they do share a variable, I *think* that they should not always be interchangeable (if they are always interchangeable, then what's the point of having MINUS at all?). But an example of where they're not interchangeable isn't immediately popping into my head. – Joshua Taylor Jun 16 '16 at 19:21
  • Thanks! This is exactly what I was looking for. – R Jackson Jun 16 '16 at 21:19
  • One more thing... turns out `MINUS` didn't work in the SPARQL query for Protege, but `FILTER NOT EXISTS` was perfect. Also had to filter out blank nodes, but I did that with a slightly convoluted `FILTER NOT EXISTS {FILTER isBlank(?class)}`... – R Jackson Jun 17 '16 at 13:21