Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQWRL Difference of Grouped Sets Not Working #43

Open
hekutoru2kx opened this issue Apr 11, 2018 · 4 comments
Open

SQWRL Difference of Grouped Sets Not Working #43

hekutoru2kx opened this issue Apr 11, 2018 · 4 comments

Comments

@hekutoru2kx
Copy link

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)

The difference operations should be doing something like:
set1 (a, b, c, d) - set2 (c, d) = set3 (a, b)
Instead they are doing some kind of distribution product to compare the differences. They are joining each value of the sets and then comparing the pair of values and letting the difference pairs only.

(x,y)
(a,c) = diff
(a,d) = diff
(b,c) = diff
(b,d) = diff
(c,c) = equal
(c,d) = diff
(d,c) = diff
(d,d) = equal

All the x different from the y according to the previous table are (a, a, b, b, c, d) giving the same distinct result of the original set1 (a, b, c, d).

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

@martinjoconnor
Copy link
Member

You do not need to use the group operator .

Take a look at this query:

https://github.com/protegeproject/swrlapi/wiki/SQWRLCollections#negation-as-failure

@hekutoru2kx
Copy link
Author

I'm using that information as a reference. If I use the sqwrl:size(?n, ?s3) and sqwrl:select(?n) I get the right lenght answer but if I sqwrl:select(?x) the result doesn't match the lenght of the size.

For the hair color example: (Joseph, Peter, Kevin, Andrew, Boris) - (Joseph, Peter)
using the sqwrl:size(?n, ?s3) -> sqwrl:select(?n) I get the leght [3], but if I do a -> sqwrl:select(?x) I'm getting five individuals. The result should be (Kevin, Andrew, Boris) but I'm getting all five again.

Thanks for replying Martin

@martinjoconnor
Copy link
Member

Can you post the ontology (change .owl to .owl.txt because GitHub does not support the .owl extension) and I can take a look.

@hekutoru2kx
Copy link
Author

I'm attaching the ontology owl file.
testontology.owl.txt

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants