If you're looking for individuals that have a type that is a complex class expression, and you're doing this in SPARQL, you'll need to know how the OWL class expression is serialized in RDF. As an example, consider the following ontology in which an individual, barrel42 has a complex type:
barrel42 : Barrel ⊓ (hasApple only GoodApple)
It's actually sort of mythical, since there's a bad apple in every barrel, but that's besides the point. Here's the ontology:
@prefix : <https://stackoverflow.com/q/21607859/1281433/example#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
<https://stackoverflow.com/q/21607859/1281433/example>
a owl:Ontology .
:barrel42 a owl:NamedIndividual ;
a [ a owl:Class ;
owl:intersectionOf ( :Barrel [ a owl:Restriction ;
owl:allValuesFrom :GoodApple ;
owl:onProperty :hasApple
] )
] .
:GoodApple a owl:Class ;
rdfs:subClassOf :Apple .
:Apple a owl:Class .
:hasApple a owl:ObjectProperty .
:BadApple a owl:Class ;
rdfs:subClassOf :Apple .
:Barrel a owl:Class .
Now, you've got some options here. You could ask for things that actually have that intersection type, but that's probably not the best route, since if something had been declared as a Barrel and declared as a hasApple only GoodApple, you'd still probably want to select it. Based on the answer to Retrieving superclasses implied by OWL intersection classes, we can write a query like this:
prefix : <https://stackoverflow.com/q/21607859/1281433/example#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix owl: <http://www.w3.org/2002/07/owl#>
select ?individual where {
?individual
a/(owl:intersectionOf/rdf:rest*/rdf:first)*
:Barrel,
[ owl:allValuesFrom :GoodApple ;
owl:onProperty :hasApple ;
a owl:Restriction ] .
}
--------------
| individual |
==============
| :barrel42 |
--------------
The property path
a/(owl:intersectionOf/rdf:rest*/rdf:first)*
is really the important part here. We're looking for types of ?individual
, and we're also will to through intersection classes to find superclasses of the intersection class. There are other "inference paths" that we might want to include too. E.g., we might incorporate rdfs:subClassOf
links:
a/((owl:intersectionOf/rdf:rest*/rdf:first)|rdfs:subClassOf)*
If you look at other class expressions, you can come up with other ways to extend the path. This can't get you all OWL inferences, but you can get more than you might expect initially.
References
As I mentioned in a comment, there have been a number of related questions lately, and it might be useful to at least skim over them to get an idea of what you can do. Here are some that I was able to find quickly: