[Pellet-users] Can you query Pellet using negation?

Evren Sirin evren at clarkparsia.com
Fri May 30 19:28:52 UTC 2008


On 5/30/08 1:08 AM, Margaret A Mitchell wrote:
> I was wondering if it was possible to query Pellet specifying something you *don't* want, and getting all the items that *don't* match a certain value.  Is this possible?
>   

Yes, you can do this using a negated concept (with owl:complementOf). 
But you need to be careful because due to open world assumption you 
might not get expected results if there isn't enough information to 
infer disjointness of concepts (or distinctness of individuals).
> I'm working in the wine domain, so, for example, I'd like to create a SPARQL query that essentially says "return all the wines that are not red".
>   

The following query will do this and return the colors too (though the 
results are duplicated because colors are defined twice, one in wine 
namespace and one in food namespace):

PREFIX wine: <http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>

SELECT * WHERE {
    ?x wine:hasColor ?y .
    ?y owl:differentFrom wine:Red
}

You can also query for the wines which are instance of the negation of 
RedWine. The following query will do this:

PREFIX wine: <http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#>

SELECT * WHERE {
   ?x a wine:Wine, [owl:complementOf wine:RedWine] .
}

Note that if you don't put Wine explicitly in this query you will get 
instances like Duck which is obviously not RedWine.

You can save these queries in a file and directly pass to CLI like this:

pellet.sh -s off -if http://www.w3.org/TR/owl-guide/wine.rdf -qf 
NotRedWine.sparql


> Is this possible?  Or is it entirely dependent on the structure of my ontology?  I will paste code as directed. =)
>   

It dies not depend on the structure but the contents if your ontology. 
If there weren't differentFrom statments between Red, White and Rose or 
hasColor was not defined to be functional the above queries would not 
return any results. DifferentFrom axioms are needed because otherwise 
reasoner would think it is possible for White and Red to refer to same 
color and funcationality is needed because otherwise reasoner would 
think it is possible for these wine instance to have another color 
(which could be red).

Hope this helps.
Evren
>
> Thanks,
> M
>
> _______________________________________________
> Pellet-users mailing list
> Pellet-users at lists.owldl.com
> http://lists.owldl.com/mailman/listinfo/pellet-users
> _______________________________________________
>
> Sponsored by Clark & Parsia, LLC http://clarkparsia.com/
>   



More information about the Pellet-users mailing list