Date: 2009-08-02 02:52:22
From: J.Petrak-at-dcs.shef.ac.uk
Is there a way to find all owl:Classes that are not the subclass
of any other class except owl:Thing using a SPARQL query?
If it is not possible with SPARQL, what is the most efficient
(least time and memory consuming) way to do this using SerQL?
Cheers,
Johann

asked 02 Apr '13, 12:25

Discussion-Board-Archive's gravatar image

Discussion-B...
6.1k143160227
accept rate: 30%

edited 17 Apr '13, 09:45

nkrustev's gravatar image

nkrustev ♦♦
66117


Date: 2009-08-03 09:31:58
From: marin.nozhchev-at-ontotext.com
Hi Johann,
It's nice to hear from you again after the summer school. Let me 
elaborate a little on Naso's response, because some of its details are 
not trivial and I can save you the time of figuring out them yourself. 
(At least, they were not trivial to me, I'm sorry if I'm stating obvious.)
Based on what we discussed in Sheffield, I think that you needed to find 
all classes that are *only* sub class of owl:Thing .  The classes that 
are not the subclass of any other class except *possibly* owl:Thing 
include classes like
http://www.w3.org/2002/07/owl#DataRange, 
http://www.w3.org/2002/07/owl#Ontology . They are not sub classes of any 
class . If you actually need those, in his email from 9AM 03.07, Naso 
gave you the correct query to retrieve such classes.
Here's the final query that retrieves all direct subclasses of owl:Thing.
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix owl: <http://www.w3.org/2002/07/owl#>
SELECT ?cl
WHERE {
?cl rdfs:subClassOf owl:Thing .
OPTIONAL
{
?cl rdfs:subClassOf ?sc.
?sc rdfs:subClassOf owl:Thing .
filter(?cl != ?sc && ?sc != owl:Thing)   
}
filter (!bound(?sc) && isURI(?cl) && ?cl != owl:Thing && ?cl != 
owl:Nothing)
}
This query follows the same pattern that Naso proposed - "find all 
classes, below owl:Thing that don't have a super class below owl:Thing".
Bases on our discussions, I also know that you are not interested in the 
blank nodes so I added isURI(?cl) to get rid of them. Finally, we need 
to filter out owl:Thing and owl:Nothing, since they match the previous 
restrictions. As you noted, you may need to disable partialRdfs to have 
this query work with ontologies which don't explicitly state that their 
top classes are a sub class of owl:Thing.
The rationale of partialRDFS is that is doesn't infer stuff which is 
very easy to be added to any ontology and every good ontology author 
will include them anyway even if they are not strictly required. Here is 
an example of a good ontology -  
http://wiki.dbpedia.org/Downloads33#dbpediaontology .
Hope that helps!
Best regards,
Marin Nozhchev,
tech lead of the KIM team
link

answered 02 Apr '13, 12:26

Discussion-Board-Archive's gravatar image

Discussion-B...
6.1k143160227
accept rate: 30%

edited 17 Apr '13, 09:45

nkrustev's gravatar image

nkrustev ♦♦
66117

Date: 2009-08-02 18:48:12
From: naso-at-sirma.bg
Hi Johann
one effcient way to get this in SPARQL is to get all classes and filter out 
those which do not have super-class. In order to avoid set difference, one 
can use a trick, using optional statement which binds super-classes where 
those exists and latter on filter out those for which super class exists 
(i.e. for which the corresponding variable is bound)
SELECT ?cl
WHERE {
?cl rdfs:type rdfs:Class
optional { ?cl rdfs:subClassOf ?sc}
filter ( NOT bound(?sc) )
}
the syntax above is only indicative (I've never tried this query), but you 
can work out the syntax easility
Regards
Naso
----------------------------------------------------------
Atanas Kiryakov
Executive Director of Ontotext AD, http://www.ontotext.com
Sirma Group, http://www.sirma.bg
Phone: (+359 2) 974 61 44; Fax: 975 3226
----------------------------------------------------------
link

answered 02 Apr '13, 12:26

Discussion-Board-Archive's gravatar image

Discussion-B...
6.1k143160227
accept rate: 30%

edited 17 Apr '13, 09:45

nkrustev's gravatar image

nkrustev ♦♦
66117

Date: 2009-08-03 03:23:35
From: J.Petrak@dcs.shef.ac.uk
Hi Naso,
thank you for the suggestion -- this was one of the things
I originally tried, but as it turns out, all classes
are subclasses of themselves (which is of course correct
semantics) and therefore no class will have an unbound
?sc in that query.
So far the only alternatives I could come up require
SERQL:
1) find all classes then remove those that have subclasses
that are not the class itself and not subclass of owl:Thing
or rdfs:Resource -- this seems to work only
with SERQL as SPARQL does not have anything that can
be used like MINUS.
2) find all Classes that are "sesame:directSubClassOf"
of owl:Thing.
I suppose that approach 2) would be a lot more efficient
if there are a huge number of classes. However it
obviously can only reliably work if partialRDFS is turned
off because otherwise, owl:Thing would not be inferred
to be a superclass of all classes.
So -- what is the trade-off of not using partialRDFS?
Another issue are all those classes that do not have
URIs and are represented as blank nodes. In order to
find out details about them, one has to find either
all the interesting details (e.g. what kind of
restriction they represent) in the same query that
retrieves them, or has to re-query the repository
for each single node.
The latter approach has two problems:
* it is utterly impossible using SPARQL, right?
* it is clumsy and probably slow using SERQL
Do you have any experiences doing this -- what is
the best approach?
Cheers,
Johann
link

answered 02 Apr '13, 12:26

Discussion-Board-Archive's gravatar image

Discussion-B...
6.1k143160227
accept rate: 30%

Date: 2009-08-03 13:05:57
From: J.Petrak-at-dcs.shef.ac.uk
Hi Marin,
thank you for joining the discussion!
No worries, any help is much apreciated and I think these issues involve
enough subtleties to not be obvious - at least to me - at all :)
Thank you that does indeed work but it only works reliably if
partialRDFS optimizations are turned off, since otherwise there is
no guarantee that something is found to be a subclass of owl:Thing
Actually I think I am interested - but I probably have to deal with
blank and non-blank nodes in two different queries, because for the
blank nodes I want to retrieve the restriction type with the same
query in order to avoid unnecessary re-querying.
Ah yes - just wrote about above. I think there is no way around
turning of partialRDFS in the default case.
I agree, but if we want to deal with as many ontologies correctly
as possible, partialRDFS needs to be disabled, because there is
no guarantee to have explicit assertions for this and users will be
confused as to why they do not get the expected results.
An alternative would be to first check if the repository has
partialRDFS enabled and fall back to the fool-proof SERQL MINUS
query in that case.
Cheers,
Johann
link

answered 02 Apr '13, 12:26

Discussion-Board-Archive's gravatar image

Discussion-B...
6.1k143160227
accept rate: 30%

edited 17 Apr '13, 09:45

nkrustev's gravatar image

nkrustev ♦♦
66117

Date: 2009-08-03 09:09:52
From: naso-at-sirma.bg
Hi Johan
sorry that I have not commented on this. One can fix this in several ways. 
The most general one is to modify the query so that the reflexivity of 
subClassOf do not affect the bindings of ?sc
SELECT ?cl
WHERE {
?cl rdfs:type rdfs:Class
optional { ?cl rdfs:subClassOf ?sc.
filter (?cl != ?sc) }
filter ( NOT bound(?sc) )
}
The second way is to "fix" the ruleset used for inference, so that 
subClassOf is no longer infered to link each class with itself. The third 
way is to exclude implicit statements from consideration in the query, but I 
am not sure what was the precise syntax for this (there are some auxiliary 
named graphs supported in OWLIM for this purpose).
MINUS is by definition an expensive operator (and it is hard to optimize)
you can get the same effect more efficiently by filtering out the unwanted 
bindings as in the query I suggested above
this is fine, but it relies on ad-hoc feature in an old proprietary query 
language
I would rather use SPARQL as suggested above. The speed should be 
comparable.
I lost you here. If you want to filter out <C, subClassOf, owl:Thing>, why 
there is a problem with the fact that with partialRDF=true those will not be 
inferred?
I can hardly think of application where the above statements are useful. 
This is why partialRDFS is switched on by default. The partialRDFS=false 
option is supported only for the sake of standard compliance
I don't think there is a single good way to find out interesting details 
about such "auxiliary" classes. One can do something like:
SELECT ?cl, ?restType, ?restProp
WHERE {
?cl rdfs:type owl:Restriction.
optional { ?cl owl:onProperty ?restrProp}.
optional { ?cl ?restrType ?c2?, rdfs:type ?Class.
filter (?restrType != rdfs:subClassOf)}
}
Again, I haven't tried the above query, so, most likely there will be syntax 
to fix. Obviously, you can combine this query with the one discussed above, 
just introducing the where clause in yet another optional block
Cheers,
Naso
----------------------------------------------------------
Atanas Kiryakov
Executive Director of Ontotext AD, http://www.ontotext.com
Sirma Group, http://www.sirma.bg
Phone: (+359 2) 974 61 44; Fax: 975 3226
----------------------------------------------------------
link

answered 02 Apr '13, 12:26

Discussion-Board-Archive's gravatar image

Discussion-B...
6.1k143160227
accept rate: 30%

edited 17 Apr '13, 09:46

nkrustev's gravatar image

nkrustev ♦♦
66117

Date: 2009-08-03 14:09:28
From: naso-at-sirma.bg
Marin, thanks for taking care to clarify all this!
Few final comments. You say that Johann's task is to get all classes which 
are sub-classes of owl:Thing only. If this is really the task - fine. If one 
simply wants to get all top-classes, i.e. non-system classes, which do not 
have non-system classes as super-classes, the query should look like:
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?cl
WHERE {
?cl rdf:type rdfs:Class .
OPTIONAL {
?cl rdfs:subClassOf ?sc.
filter(?cl != ?sc && ?sc != owl:Thing && ?sc != rdfs:Resource)
}
filter (!bound(?sc) && isURI(?cl))
}
Cheers,
Naso
----------------------------------------------------------
Atanas Kiryakov
Executive Director of Ontotext AD, http://www.ontotext.com
Sirma Group, http://www.sirma.bg
Phone: (+359 2) 974 61 44; Fax: 975 3226
----------------------------------------------------------
link

answered 02 Apr '13, 12:26

Discussion-Board-Archive's gravatar image

Discussion-B...
6.1k143160227
accept rate: 30%

edited 17 Apr '13, 09:46

nkrustev's gravatar image

nkrustev ♦♦
66117

Date: 2009-08-26 12:19:22
From: J.Petrak-at-dcs.shef.ac.uk
Hi Atanas, Marin & fellow OWLIMers,
as it turns out, this query will not work correctly in
all cases: when there are top classes that are defined
to be owl:equivalentClass of each other, none of these
classes will be included in the list of top classes since
they are each mutual subclasses.
So they are subclasses of something that is neither
themselves nor Thing or Resource and will get
filtered out.
So we really should not filter out classes that
are subclasses of any equivalent class that
is also a top class, but I could not come up with
a SPARQL query for that yet.
Can you think of one?
I am not quite sure about the situation when we
are dealing
with ontologies that are really OWL Full and where
classes are asserted to be owl:sameAs: however I
would assume that this would also imply that they
must have same extension when viewed as classes.
Cheers,
Johann
link

answered 02 Apr '13, 12:27

Discussion-Board-Archive's gravatar image

Discussion-B...
6.1k143160227
accept rate: 30%

edited 17 Apr '13, 09:45

nkrustev's gravatar image

nkrustev ♦♦
66117

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×261
×242
×37

Asked: 02 Apr '13, 12:25

Seen: 13,383 times

Last updated: 13 Jun, 06:37

powered by BitNami OSQA