On 01/02/16 12:11, Joël Kuiper wrote:
Hey all,

I’m trying to run a query to find the path to the root concept of a graph.
The entries are defined as rdfs:subClassOf

Currently I’m using

PREFIX skos: <http://www.w3.org/2004/02/skos/core# 
<http://www.w3.org/2004/02/skos/core#>>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema# 
<http://www.w3.org/2000/01/rdf-schema#>>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns# 
<http://www.w3.org/1999/02/22-rdf-syntax-ns#>>

SELECT ?parent ?label
WHERE {
  GRAPH ?g {
    ?concept rdfs:subClassOf* ?parent
  }}

However on a moderately sized data set < 1M triples, this query sometimes takes 
/minutes/.
I suspect it has to do with the disk-based TDB (since I hear my HDD spin a 
lot), but still.
Is there a way to optimise this query, maybe by using a different reasoner? And 
if so how would that reasoner be used!

Thanks in advance,

Joël


If you are using a reasoner and doing rdfs:subClassOf* then that is doing excessive redundant work.

(Otherwise, with TDB is materialises more nodes that it needs to.)

The root is a node without a parent so this might help, without a reasoner:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?top
WHERE {
   GRAPH ?g {
     ?concept rdfs:subClassOf ?top
     FILTER NOT EXISTS { ?top rdfs:subClassOf ?x }
  }
}

Reply via email to