On 05/07/12 06:49, Federico López wrote:
I looking for a good quey that allows me to get the roots elements of a
Ontology. Also, I need to know wich one of these roots have children...
Version of Jena used?
I have each ontology in a NAMED GRAPH....
And you are querying the union graph?
This is what I using for it but the query is taking too much.
How big is the data (in triples)?
Are you using inference?
SELECT DISTINCT ?root ?label (COUNT(?child) AS ?nChild)
FROM <http://ontologyURI>
WHERE
{
?root a ?class .
?class rdfs:subClassOf owl:Class .
?root rdfs:label ?label .
OPTIONAL {
?root rdfs:subClassOf ?super .
}
OPTIONAL {
?child rdfs:subClassOf ?root .
}
FILTER (!bound(?super))
}
GROUP BY ?root ?label
Any idea?
Thanks...
without inference, this maybe what you want: I'm guessing from your
description:
SELECT ?root
{
# A root is something that is of type class
# which has no super class mentioned.
?root rdf:type owl:Class .
FILTER NOT EXISTS { ?root rdfs:subClassOf ?super }
?root rdfs:label ?label .
}
Adding in the COUNT of ?child and GROUP BY is unlikely to be cheap.
SELECT ?root (COUNT(DISTINCT ?child) AS ?nChild)
{
# A root is something that is of type class
# which has no super class mentioned.
?root rdf:type owl:Class .
FILTER NOT EXISTS { ?root rdfs:subClassOf ?super }
?root rdfs:label ?label .
# Children, any depth, by property paths
OPTIONAL { ?child rdfs:subClassOf+ ?root }
}
GROUP BY ?root
Andy