Wednesday, 22 April 2015

Using Active Rules on Fluent Editor

Active rules is the mechanism Fluent Editor provides for executing custom imperative code in C# upon meeting certain criteria described as SWRL rules. Considering that standard SWRL rule axioms consist of two parts, an antecedent (body) and consequent (head), the body part of active rules exactly follows the standard format of SWRL rules. The difference from standard SWRL lies on the head part, on which you can add your custom C# code as a set of execution commands. We provide some mechanism to deal with the nature of distributed environments through a set of core built-ins. Available functions to use in active rules are as follows:
 
  • KnowledgeInsert(string knowledge) : Inserts knowledge into your ontology.
  • KnowledgeDelete(string knowledge) : Deletes knowledge into your ontology.
  • WriteMessage(string msg) : Prints msg on Active Rules Output window. 



To illustrate the use of Active Rules, we will use 'Simple IT with Active Rules' template on File > New.

As shown below, there are two active rules defined in this ontology: the first rule inserts knowledge, and the second one deletes it. Let's start by running the first active rule. In order to run active rules,   the antecedent (body) part of rule axiom should be satisfied, just as in standard SWRL rules. For the active rule 1, the following two sentences will fulfill the condition :
  • Line 76: 'Powernode-1 connects Server-1.'  
  • Line 121: 'Powernode-1 has-status Inoperable.'.

Having a rule with a fulfilling condition, you can execute the rule by clicking 'Run Active Rules' button on Tools tab.


Before the rule output appears, you will see the below message. As in SWRL Debugger, execution of Active Rules is based on materialization, which will be performed only in OWL2-RL+ mode, and OWL-DL mode is not supported yet. Click 'OK' button,


Then the active rule 1 will be executed. As shown in below image, you will find two changes.
  1. A new knowledge is added on the bottom of ontology. The new knowledge is generated by the string format passed to the KnowledgeInsert() function. 
  2. 'Show Active Rules Output' window will show up with the printed messages. The messages are strings passed to the WriteMessage() function. 


Now let's try running the other active rule. The mechanism is the same, that the body part of the rule axiom should be fulfilling. We can make this by the following steps :
  • Keep line 76: 'Powernode-1 connects Server-1.'  
  • Delete or comment out line 121: 'Powernode-1 has-status Inoperable.'.
  • Add or uncomment line  124: 'Powernode-1 has-status Operable.'.

Then click 'Run Active Rules' again on the modified ontology.

This time active rule 2 will be executed and you will find two different changes.
  1. The new knowledge added on the bottom after executing active rule 1 is now deleted. This is because the function KnowledgeDelete() was executed, the knowledge of which to delete is actually equivalent to one for KnowledgeInsert() in active rule 1. 
  2. 'Show Active Rules Output' window will print messages. The messages are strings passed to the WriteMessage() function. 

An interesting point here is, whichever active rule is executed it will be also retrieved by SWRL debugger, since active rules are processed by the same materialization process. To check the output, click 'Run Active Rules' and open 'SWRL Debug' window.

To open the Active Rules Output window again after closing it or visiting other window tabs, click 'Active Rules' button on Tools tab.  

No comments:

Post a Comment