I have data that describes sub-type relationships. In Turtle it could look like this:
@prefix a: <#>
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
a:test1
a a:A ;
a a:B ;
a a:C ;
.
a:test2
a a:A ;
a a:D ;
.
a:B rdfs:subClassOf a:A .
a:C rdfs:subClassOf a:B .
a:D rdfs:subClassOf a:A .
In the above example, a:C is a subtype of a:B, which in turn is a subtype of a:A. a:D also is a subtype of a:A. I want to select the least upper bound of a:test1, which is a:C. I can write a query, which selects all upper bounds of a:test1, which would be:
prefix a: <#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select distinct ?type where {
a:test1 a ?type .
}
But I'm not able to restrict ?type any further. In a functional language with a Java like syntax I would write:
setOfTypes.filter(type =>
not setOfTypes.exists(subtype =>
subtype.isSubClassOf(type) && subtype != type))
My translation to SPARQL looks like this:
prefix a: <#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select distinct ?type where {
a:test1 a ?type .
filter not exists {
?subtype rdfs:subClassOf ?type .
filter (?subtype in ?type && ?subtype != ?type)
}
}
Unfortunately, ?subtype in ?tpe is invalid syntax. Can someone show me a query that would only select a:C?