views:

996

answers:

2

I am developing an ontology and I have a problem with my Dl query

there is a class called "flower"

and this class has subclasses which are some flowers names

and also there is another class called "flowersColor"

and it has these values ("red","green" and "blue") as individuals-not subclass-

every flower has one color or more

I want to search for a flower that has red color and only red

my DL Query is :

"flower and hasColor value red"

this query will give me all flowers that has the color red even if it has other colors

however I want all flowers that has ONLY the color red

I want to write something like this

"flower and hasColor only value red" <- this is not correct grammatically

I main if the color has a combination of "red" and "green" then I don't want to see it in my result

I hope you can help me in my query

Thanks

A: 

The query that you are after is:

flower and (hasColor only {red})

Note that the {.} constructor creates a class from an individual, or a list of individuals. So you can use it everywhere where a class is syntactically required, e.g.

(not {blue}) subClassOf
             {red} and {green,blue} or (hasColor max 10 ({red} or {blue}))
Kaarel
+1  A: 

Remember that OWL uses the open world assumption, so you are somewhat limited in what can be inferred via description logic.

So your "query", as Kaarel mentions, could be:

flower and (hasColor only {red})

Yet this is unprovable in the open world assumption. There could be statement, somewhere in the universe, which asserts:

<RedRose> :hasColor :StackOverflow .

Which, when combined with your assertions (which you're trying to query):

<RedRose> :hasColor :Red .
<RedRose> a :Flower .

Will cause the DL query to return no results. So due to the open world assumption, and the theoretical existence of wild, inaccurate, and irrelevant assertions (at least from your perspective), the DL query will fail, since it can only infer statements it can prove are true.

However, your example query can be used in an OWL restriction to determine if something is not something else. As an example, if you have a class (:OnlyRedFlower) which must only have the color red, but it has the color blue (you've asserted this additional color), then you can infer that this new flower is not in the set of :OnlyRedFlower.

Update: For those that are interested in trying this themselves, here's the ontology I created based on this question:

<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [
    <!ENTITY owl "http://www.w3.org/2002/07/owl#" >
    <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
    <!ENTITY owl2xml "http://www.w3.org/2006/12/owl2-xml#" >
    <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
    <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
    <!ENTITY onto "http://www.elastra.com/onto/2009/5/30/onto.owl#" >
]>
<rdf:RDF xmlns="http://stackoverflow.com/users/64881/ontology_842588.rdf#"
     xml:base="http://stackoverflow.com/users/64881/ontology_842588.rdf"
     xmlns:owl2xml="http://www.w3.org/2006/12/owl2-xml#"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:owl="http://www.w3.org/2002/07/owl#"
     xmlns:onto="http://www.elastra.com/onto/2009/5/30/onto.owl#"&gt;
    <owl:Ontology rdf:about="">
        <rdfs:comment xml:lang="en"
            >Example for http://stackoverflow.com/questions/842588/in-owl-dl-query-how-to-use-advanced-valu-query-in-protege&lt;/rdfs:comment&gt;
    </owl:Ontology>
    <owl:ObjectProperty rdf:about="&onto;hasColor"/>
    <owl:Class rdf:about="&onto;Color"/>
    <owl:Class rdf:about="&onto;ExampleFlower">
        <rdfs:subClassOf rdf:resource="&onto;Flower"/>
    </owl:Class>
    <owl:Class rdf:about="&onto;Flower"/>
    <owl:Class rdf:about="&onto;OnlyRedFlower">
        <owl:equivalentClass>
            <owl:Class>
                <owl:intersectionOf rdf:parseType="Collection">
                    <rdf:Description rdf:about="&onto;Flower"/>
                    <owl:Restriction>
                        <owl:onProperty rdf:resource="&onto;hasColor"/>
                        <owl:allValuesFrom>
                            <owl:Class>
                                <owl:oneOf rdf:parseType="Collection">
                                    <rdf:Description rdf:about="&onto;Red"/>
                                </owl:oneOf>
                            </owl:Class>
                        </owl:allValuesFrom>
                    </owl:Restriction>
                </owl:intersectionOf>
            </owl:Class>
        </owl:equivalentClass>
        <rdfs:subClassOf rdf:resource="&onto;Flower"/>
    </owl:Class>
    <owl:Class rdf:about="&onto;OtherFlower">
        <rdfs:subClassOf rdf:resource="&onto;Flower"/>
    </owl:Class>
    <onto:Color rdf:about="&onto;Blue">
        <rdf:type rdf:resource="&owl;Thing"/>
    </onto:Color>
    <onto:Flower rdf:about="&onto;BlueOrchid">
        <rdf:type rdf:resource="&owl;Thing"/>
        <onto:hasColor rdf:resource="&onto;Blue"/>
    </onto:Flower>
    <onto:Color rdf:about="&onto;Red">
        <rdf:type rdf:resource="&owl;Thing"/>
    </onto:Color>
    <onto:Flower rdf:about="&onto;RedRose">
        <rdf:type rdf:resource="&owl;Thing"/>
        <onto:hasColor rdf:resource="&onto;Red"/>
    </onto:Flower>
</rdf:RDF>
Phil M