Search code examples
owlontologyreasoningswrl

How to select elements from UNION operation in sqwrl query


I am able to select the size of s3 and it is giving me the correct answer in rule 1. However, I want to select all the elements in s3. I tried Rule 2 but it is giving me the exception "error running SQWRL queries: error running Drools rule engine"

My goal is to retrieve all the diseases that have either symptom vomiting OR fever. Any help will be highly appreciated.

Rule 1:

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) 

Rule 2:

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:select(?s3) 

Solution

  • According to the documentation, you should try to use the binary built-in predicate sqwrl:element(?e, ?sd) with the first element argument ?e beeing unbound, i.e.:

    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)