1

How do I create a query that just returns asserted individuals, not blank nodes (anonymous individuals) if they exist?

Here is my SPARQL query:

PREFIX ont: <http://ontologies/aa-CurrentOntology#>
PREFIX rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT DISTINCT ?ind
WHERE {
    ?ind rdf:type ont:Size .
}
ORDER by ?ind

Here are some of the results (solutions):

sol: ( ?ind = <http://ontologies/aa-CurrentOntology#Big> )
sol: ( ?ind = <http://ontologies/aa-CurrentOntology#Small> )
sol: ( ?ind = _:b0 )
sol: ( ?ind = _:b1 )
sol: ( ?ind = _:b2 )
sol: ( ?ind = _:b3 )… thousands more after this

I want the query to only return the first two results, not the last four (_:b0, _:b1, etc). These do not exist in my input OWL file. I realize the blank nodes are probably because of the way the ontology is defined, but is there a way to eliminate them from the query result set?

I tried adding:

FILTER isURI (?ind)

...but this still requires all blank nodes to be calculated before being filtered out. Unfortunately, there seem to be thousands of blank nodes and the query never completes.

Is there a way of stating

don't bother calculating blank nodes

?

Kenny Cason
  • 497
  • 5
  • 17
  • 1
    https://stackoverflow.com/a/44113648/7879193 ? – Stanislav Kralin Jul 24 '18 at 18:42
  • That would work if the query actually completed, I've used that solution in other situations so you are mostly correct. I've edited my question to be more clear that I need the query itself to ignore blank nodes, not just filter them out after the fact. – Kenny Cason Jul 24 '18 at 18:54
  • 1
    `?ind rdf:type ont:Size, owl:NamedIndividual`? I can't understand, why these blank nodes come into existence, please paste respective fragment of your ontology. – Stanislav Kralin Jul 24 '18 at 19:07
  • I wish I could but I am restricted from posting actual data. :-( – Kenny Cason Jul 24 '18 at 19:09
  • 1
    do you have reasoning enabled? I don't see why for this simple query blank nodes are returned, except you have subclass axioms with complex OWL class expressions like `:p some :Size` – UninformedUser Jul 24 '18 at 19:29
  • Yes, reasoning is enabled. It is likely there are subclass axioms with complex OWL class expressions, like you said. I'm not the person developing the ontology structure. But I am working with them to resolve this issue. – Kenny Cason Jul 24 '18 at 19:34
  • Ok, but then it's at least clear from where the blank nodes are computed. As Stanislav said, adding `?ind rdf:type owl:NamedIndividual` should avoid class expression based nodes. – UninformedUser Jul 25 '18 at 09:55

0 Answers0