1

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

  • `differentFrom(?x, ?y)` -> you declared all the individuals **explicitly** to be different from each other in your ontology? Otherwise, this won't work given that OWL doesn't follow the Unique Names Assumption, i.e. two different names (resp. URIs) do not necessarily mean that both are different entities. – UninformedUser Apr 03 '18 at 06:32
  • by the way `differentFrom(?x, ?y)` means both persons are not the same, but this doesn't mean the hair color is not the same. You'd need something like `hasHairColor(?y, ?color), notEquals(?color, "Black")` resp. some kind of negation, not sure if this is possible in SWRL/OWL, see [this](https://github.com/protegeproject/swrlapi/wiki/SWRLLanguageFAQ#Does_SWRL_support_Negation_As_Failure) – UninformedUser Apr 03 '18 at 06:38
  • 2
    SPARQL would work perfectly here... – UninformedUser Apr 03 '18 at 06:38
  • Hi, thx for the reply. Yes, all the individuals are explicitly different from each other. Yes, but i'm using differentFrom with two different individuals sets; X from all male list and Y for black hair males. But it's doing some kind of distributive product in the join comparisson and leaving the differents. (a, b, c) x (b, c) = (ab, ac, bb, bc, cb, cc) -> the different result is (ab, ac, bc, cb) because are different in the comparisson. Leaving the X part without change (a, b, c) and the Y part without change (b, c) – Héctor José Hernández Reinoza Apr 05 '18 at 05:40
  • The issue is still pending. I found and opened an issue in the sqwrl github site and you cand find it following this link https://github.com/protegeproject/swrlapi/issues/43 – Héctor José Hernández Reinoza Aug 02 '18 at 19:13

1 Answers1

0

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