此请求返回所有带有蘑菇配料的披萨:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX pizza: <http://www.co-ode.org/ontologies/pizza/pizza.owl#>
SELECT ?pizza
WHERE {
?pizza rdfs:subClassOf+ pizza:Pizza .
?pizza rdfs:subClassOf [
a owl:Restriction ;
owl:onProperty pizza:hasTopping;
owl:someValuesFrom pizza:MushroomTopping
]
}
但我想列出所有带有 VegetableTopping 的披萨,它是 PizzaTopping 的子类。另外,MushroomTopping 是 VegetableTopping 的子类。以下查询未提供预期结果:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX pizza: <http://www.co-ode.org/ontologies/pizza/pizza.owl#>
SELECT ?pizza
WHERE {
?pizza rdfs:subClassOf+ pizza:Pizza .
?pizza rdfs:subClassOf [
a owl:Restriction ;
owl:onProperty pizza:hasTopping;
owl:someValuesFrom pizza:VegetableTopping
]
}
正如UninformedUser在评论中所说,你必须将topping设置为变量值,然后声明该变量绑定到
VegetableTopping
的所有子类。
SELECT ?pizza WHERE {
?pizza rdfs:subClassOf+ pizza:Pizza .
?pizza rdfs:subClassOf [
a owl:Restriction ;
owl:onProperty pizza:hasTopping;
owl:someValuesFrom ?topping
] .
?topping rdfs:subClassOf* pizza:VegetableTopping .
}