75 
 
inverses, defined classes, etc. Go back to the Individuals by class tab and look at various Customers. For 
example, Customer1 has ordered more than one Pizza and hasSpicinessPreference of Hot so she 
has a discount of .2. Note that as with any information asserted by the reasoner, there is a ? next to the 
assertion which you can click on and it will provide an explanation about why the value was asserted. 
This explanation will list the appropriate rule that fired and the values that caused it to fire. If you look at 
Customer6, you will see that he has no discount because he has only purchased one Pizza. Finally, if 
you look at Customer2, she has a discount of .1 because she has purchased more than one Pizza but her 
spiciness preference isMilderThan Hot.  
In this case the consequent of our rule was to add a data property assertion to an individual. Another 
possible outcome is to make an individual be an instance of a new class. E.g., if we had a subclass of 
Customer called PreferredCustomer and we wanted the result of a rule be to make a Customer an 
instance of  PreferredCustomer we could have -> PreferredCustomer(?c) as the consequent 
of the rule.  
A tool that is useful to debug SWRL rules is the Semantic Query-Enhanced Web Rule Language or 
SQWRL (pronounced squirrel). SQWRL rules look just like SWRL rules except in the consequent there 
is a sqwrl:select statement that lists every parameter that we want to know the value of every time the 
rule fires.  
Exercise 36: Write a SQWRL Rule  
_____________________________________________________________________________________ 
1. Bring up the SQWRLTab  if it doesn’t already exist using Windows>Tabs>SQWRLTab. You will see 
it looks almost identical to the SWRLTab.  
2. Let’s say we want to see how often the HotDiscountRule fires. We can find this out very easily. To 
start select the HotDiscountRule and clone it. This creates a copy of the rule called S1. Select that rule 
and then select the Edit button.  
3. Change the name of the rule to TestHotDiscountRule.   Replace the consequent (the expression after 
the arrow) with the following:  sqwrl:select(?c, ?np) and select OK. Your SQWRL rule should look like: 
Customer(?c) ^ numberOfPizzasPurchased(?c, ?np) ^ hasSpicinessPreference(?c, pizza:Hot) ^ 
swrlb:greaterThan(?np, 1) -> sqwrl:select(?c, ?np).  Synchronize the reasoner.  
4. Select TestHotDiscountRule then select the Run button at the bottom of the tab. This will create a new 
tab in the lower view called TestHotDiscountRule. You should see that the rule fired 3 times with ?c 
equal to Customer4, Customer1, and Customer8 and with ?np equal to 3, 2, and 2.  
_____________________________________________________________________________________ 
 
This has been a very brief introduction to SWRL. For a somewhat more interesting example based on 
process modeling see: https://www.michaeldebellis.com/post/swrl_tutorial