I'm developing an ontology to model the relations in a manufacturing system. I broke it down to a similar scheme with dishes:
ex:potatoes rdf:type owl:Class .
ex:fish rdf:type owl:Class .
ex:beef rdf:type owl:Class .
ex:rice rdf:type owl:Class ;
owl:disjointWith ex:potatoes .
ex:chicken rdf:type owl:Class ;
owl:disjointWith ex:fish .
ex:pork rdf:type owl:Class ;
owl:disjointWith ex:beef .
ex:dish1 rdf:type owl:Class ;
rdfs:subClassOf ex:dishes ;
owl:unionOf ( ex:pork ex:potatoes ) .
ex:dish2 rdf:type owl:Class ;
rdfs:subClassOf ex:dishes ;
owl:unionOf ( ex:rice ex:chicken ) .
ex:dish3 rdf:type owl:Class ;
rdfs:subClassOf ex:dishes ;
owl:unionOf ( ex:fish ex:potatoes ) .
ex:dish4 rdf:type owl:Class ;
rdfs:subClassOf ex:dishes ;
owl:unionOf ( ex:beef ex:rice ) .
So I have some disjunct classes and I want to query the model like this: If somebody says he wants rice and chicken, exclude every dish which contains the disjunct classes (here fish and potatoes). After some research I have it like this:
"PREFIX ex: <http://example.org/>"+
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>"+
"PREFIX owl: <http://www.w3.org/2002/07/owl#>"+
"PREFIX list: <http://jena.hpl.hp.com/ARQ/list#>"+
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"+
"SELECT ?x "+
"WHERE {"+
"?x rdfs:subClassOf ex:dishes. "+
"FILTER (!isBlank(?x))"+
"FILTER NOT EXISTS { "+
"?x rdfs:subClassOf ?y ."+
"?y rdfs:subClassOf ex:dishes ."+
"FILTER (?x!=?y)"+
"}"+
"FILTER NOT EXISTS {"+
"?z rdfs:subClassOf ?x ." +
"?z owl:disjointWith ex:chicken . }" +
"FILTER NOT EXISTS {"+
"?z rdfs:subClassOf ?x ." +
"?z owl:disjointWith ex:rice . }" +
"}";
It works and I get the correct result:
------------
| x |
============
| ex:dish4 |
| ex:dish2 |
------------
Is there a more efficient way to do this? Seems unnecessary complicated. And do have to add the whole block with "FILTER NOT EXISTS { ?z rdfs:subClassOf ?x . ?z owl:disjointWith ex:chicken . } every time? Any advice?
ex:dish1 ... owl:unionOf (ex:pork ex:potatoes), you're saying that dish1 is the union of pork and potatoes. That means that if something is a pork, then it's a dish1, and that if something is a potatoes, then it's a dish1. That means that, for instance, if something is a potatoes, then it's a dish1, but by the same reasoning, a dish3. So, a boiled potato would be classified as a dish1 and a dish3. Is that really what you're trying to say? - Joshua Taylor