Writing transformation rules

Now that all objects are in the knowledge session, we can start writing some transformation rules. Let's imagine that in the legacy system there are many duplicate addresses. We can write a rule that removes such duplication:

rule twoEqualAddressesDifferentInstance
    $addressMap1 : Map( this["_type_"] == "Address" )
    $addressMap2 : Map( this["_type_"] == "Address", 
      eval( $addressMap1 != $addressMap2 ), 
      this == $addressMap1 )
    retract( $addressMap2 );
      kcontext.getRule().getName(), $addressMap2));

Code listing 4: Rule that loads all Addresses for a Customer into the rule session (file dataTransformation.drl)

The rule matches two addresses. ...

Get Drools JBoss Rules 5.X Developer's Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.