On UCR Document as on May 18 2008

May I suggest a more "object-oriented" encoding for rules in UC 2.1? In 
many cases (Drools, JRules, F-Logic, Jess) people uses object oriented 
rule languages to encode their rules.

Assuming  John has rules in F-Logic (here is the basic syntax of 
F-Logic) the rule "If an item is perishable and it is delivered more 
than 10 days after the scheduled delivery date then the item will be 
rejected" looks like:

RULE R1 I:item[status -> "rejected"] <- I:item[isPerishable -> true] AND
                              I[actualDeliveryDate -> A] AND 
                              I[scheduledDeliveryDate -> S] AND 
                              R is (A - S) AND R > 10.


Then a  RIF encoding (abridged syntax) is:

Rule ("http://john.com/R1"
      ?i#<j:Item>[(<j:isRejected>->"true"^^xs:boolean) :-
                   And(
                     ?i#Item[(<j:isPerishable>->"true"^^xs:boolean) 
                             (<j:actualDeliveryDate>->?actualDeliveryDate ) 
                             (<j:scheduledDeliveryDate> ->?scheduledDeliveryDate)
                     ]
                     External(<fn:subtract-dateTimes-yielding-dayTimeDuration>(?actualDeliveryDate ?scheduledDeliveryDate ?diffduration))
                     External(<fn:get-days-from-dayTimeDuration>(?diffduration ?diffdays))
                     External(<op:numeric-greater-than>(?diffdays "10"^^xs:int))
                   )
)

which can be easily translated to Drools such as:

rule "R1"
 when
  i : Item(isPerishable==true, actualDeliveryDate : actualDeliveryDate, 
           scheduledDeliveryDate : scheduledDeliveryDate 
      )
  eval( actualDeliveryDate.getDay() - scheduledDeliveryDate.getDay() > 10)
 then
  i.isRejected(true);
  modify(i);
end

I maintain a number of documents  on rule interchange our wiki: 
http://hydrogen.informatik.tu-cottbus.de/wiki/index.php/Category:Rule_Interchange 


-Adrian G

Received on Tuesday, 20 May 2008 11:01:15 UTC