ontologyprotegeswrlsqwrl

SQWRL Query to Select Difference of Grouped Sets


Let's say that I have this information

Individual  |   Sex     |   HairColor
---------------------------------------
Joseph      |   Male    |   Black
Peter       |   Male    |   Black
Kevin       |   Male    |   Blonde
Andrew      |   Male    |   Brown
Boris       |   Male    |   Brown
Chistine    |   Female  |   Black
Julia       |   Female  |   Black
Julieth     |   Female  |   Brown
Judith      |   Female  |   Brown
Mary        |   Female  |   Blonde

My individuals are all different. I have the class Male and Female asserted to each one. And I also have the property hasHairColor asserted to everyone with its value.

The question is, how can I query all the males with hair color different from black (the ontology may have many other hair colors)?

So far, I have tryied this queries with faulty results...

1. Male(?x) ^ Male(?y) ^ hasHairColor(?y, "Black") ^ differentFrom(?x, ?y) -> sqwrl:select(?x)
2. Male(?x) ^ Male(?y) ^ hasHairColor(?y, "Black")  .  sqwrl:makeSet(?males, ?x) ^ sqwrl:groupBy(?males, ?x) ^ sqwrl:makeSet(?blacks, ?y) ^ sqwrl:groupBy(?blacks, ?y)  .  sqwrl:notEqual(?males, ?blacks) -> sqwrl:select(?x)
3. Male(?x) ^ Male(?y) ^ hasHairColor(?y, "Black")  .  sqwrl:makeSet(?males, ?x) ^ sqwrl:groupBy(?males, ?x) ^ sqwrl:makeSet(?blacks, ?y) ^ sqwrl:groupBy(?blacks, ?y)  .  sqwrl:difference(?diff, ?males, ?blacks) -> sqwrl:select(?x)

I'm missing something in the way the joins are made. The result works but only when one of the sets has only one element (i.e. if I try to remove blondes)

I'm using Protege 5.2 with the SWRL and SQWRL Tab 2.0.5

Thanks in advance


Solution

  • The issue is still pending, but the solution was to use SPARQL to achieve what I wanted.

    If you need more information about the open issue. You can find it here https://github.com/protegeproject/swrlapi/issues/43