Result of group by contains unexpected rows
Hi,
I'm using latest Protege 5.5.0 and the installed SWRL Tab plugin version is 2.0.6
Let's assume the following data just consisting of 3 classes and 5 individuals.
@prefix : <http://www.semanticweb.org/me/ontologies/2019/4/untitled-ontology-543#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
<http://www.semanticweb.org/me/ontologies/2019/4/untitled-ontology-543> rdf:type owl:Ontology .
:C1 rdf:type owl:Class .
:C2 rdf:type owl:Class .
:C3 rdf:type owl:Class .
:a rdf:type owl:NamedIndividual ,
:C1 .
:b rdf:type owl:NamedIndividual ,
:C1 , :C2 .
:c rdf:type owl:NamedIndividual ,
:C1 , :C2 , :C3 .
:d rdf:type owl:NamedIndividual ,
:C1 , :C2 , :C3 .
:e rdf:type owl:NamedIndividual ,
:C2 .
The task of the SQWRL query is to compute the number of classes each individual belongs to.
The query I tried is
abox:caa(?cls, ?ind) . sqwrl:makeBag(?bag, ?cls) ^ sqwrl:groupBy(?bag, ?ind) . sqwrl:size(?n, ?bag) -> sqwrl:select(?ind, ?n)
it works mostly as expected except that it also returns some results that shouldn't occur:
+-------------+------------+
| ind | n |
+-------------+------------+
| autogen0:C1 | autogen0:a |
| autogen0:C1 | autogen0:b |
| autogen0:C1 | autogen0:c |
| autogen0:C1 | autogen0:d |
| autogen0:C2 | autogen0:b |
| autogen0:C2 | autogen0:c |
| autogen0:C2 | autogen0:d |
| autogen0:C2 | autogen0:e |
| autogen0:C3 | autogen0:c |
| autogen0:C3 | autogen0:d |
| autogen0:a | 1 |
| autogen0:b | 2 |
| autogen0:c | 3 |
| autogen0:d | 3 |
| autogen0:e | 1 |
+-------------+------------+
So the last 5 rows are indeed what I'd expect, but I can't explain the other rows. Any ideas what I'm doing wrong?
I assume it has something to do with the "meta-axioms" like :C1 rdf:type owl:Class, am I right? Is there any chance to omit those entity declaration axioms? And also, the number n for those cases is clearly not a number so it looks like the size built-in fails somehow?
This is very odd. I will take a look.
Works fine for me. See enclosed file containing your classes and individuals and a SQWRL query.
Strange. Looks like I'm misusing the plugin somehow. Maybe it happened because I changed a rule after getting some result from a previous run. Is the state of the table somewhere not refreshed?
I have some steps to reproduce an issue:
- load the ontology open the SQWRL tab, select the rule
S1and "run" it -> result as expected - edit the rule to
abox:caa(?cls, ?ind) -> sqwrl:select(?cls, ?i) ^ sqwrl:orderby(?i), selectS1and "rerun" it - revert the changes, i.e. edit the rule to
abox:caa(?cls, ?ind) . sqwrl:makeBag(?bag, ?cls) ^ sqwrl:groupBy(?bag, ?ind) . sqwrl:size(?n, ?bag) -> sqwrl:select(?ind, ?n), selectS1and "rerun" it
This time I'm getting again what I got last time (screenshot to prove I'm not crazy):

So basically, what you can see here is that result from previous run is still in the table.
While further changed the rule back and forth I got also into a state where neither "run" nor "rerun" (from S1 Tab) do change anything - I guess at this point the plugin crashed completely:
See the S1 tab to review results of the SQWRL query.
The query took 870 milliseconds. 5 rows were returned.
Exception running SQWRL query 'S1': error running SQWRL queries: Internal error comparing rows
Exception running SQWRL query S1: error running SQWRL queries: Internal error comparing rows: Internal error comparing rows: attempt to compare a org.swrlapi.factory.DefaultSQWRLLiteralResultValue with a org.swrlapi.factory.DefaultSQWRLClassResultValue