1

For AND operation in sqwrl query, it is like :

Symptom(fever) ^ Symptom(vomiting) ^ Disease(?y) ^ hasSymptom(?y,fever) ^ hasSymptom(?y,vomiting) -> sqwrl:select(?y)

From the above rule, it is selecting the diseases that have both symptoms. What about OR operation in sqwrl query? I want to select the diseases that has either symptom fever or symptom vomiting? Any help will be highly appreciated.

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
Muzogeek
  • 53
  • 7

2 Answers2

3

The correct answer to select diseases that have either symptom vomiting or fever.

Symptom(fever) ^ Symptom(vomiting) ^ Disease(?x) ^ Disease(?y) ^ has_symptom(?x, fever) ^ has_symptom(?y, vomiting)˚sqwrl:makeSet(?s1, ?x) ^ sqwrl:makeSet(?s2, ?y)˚sqwrl:union(?s3, ?s1, ?s2) ^ sqwrl:element(?e, ?s3) -> sqwrl:select(?e)

Muzogeek
  • 53
  • 7
1

I think, what you are searching for can be done with collections. With them you can define a disjunction. I am not sure but maybe your desired query looks like this:

Symptom(?fever) ^ Symptom(?vomiting) ^ Disease(?x) ^ Disease(?y) ^
hasSymptom(?x, ?fever) ^ hasSymptom(?y, ?vomiting) ˚
sqwrl:makeSet(?s1, ?x) ^ sqwrl:makeSet(?s2, ?y) ˚
sqwrl:union(?s3, ?s1, ?s2)
-> sqwrl:select(?s3)
marli
  • 529
  • 10
  • 19
  • I am getting this exception : error running SQWRL queries: error running Drools rule engine: – Muzogeek Feb 03 '17 at 19:52
  • However, I read the documentation on collections and I build another rule: Symptom(fever) ^ Symptom(vomiting) ^ Disease(?x) ^ Disease(?y) ^ has_symptom(?x, fever) ^ has_symptom(?y, vomiting)˚sqwrl:makeSet(?s1, ?x) ^ sqwrl:makeSet(?s2, ?y)˚sqwrl:union(?s3, ?s1, ?s2) ^ sqwrl:size(?n, ?s3) -> sqwrl:select(?n) I ain`t getting any exception and it is returning me the correct result for the size. BUT it is not working when selecting s3. – Muzogeek Feb 03 '17 at 19:57