You'll need 2 rules, one for truncating a key that does not match and another one for handling the match. If you have to handle absolute failure (not even "a" matches) you'll need a third rule and a more complex fact for storing the original and the truncated string.
These 2 rules are untested: rule "truncate when not found" when $s: String( length > 0 ) $m: Map( keySet not contains $s ) then retract( $s ); insert( $s.substring( 0, $s.length() -1 ); end rule "found" when $s: String() $m: Map( keySet contains $s ) then System.out.println( "key " + $s + " is in the Map" ); end -W On 4 October 2011 15:41, rahulkrishnan <rahulkrishn...@gmail.com> wrote: > Hi > I want to match a string with the contents of hashmap. The process is like > this. > > Let the string is "abcd" > First it will search for abcd in the map > if found i have to assign it to a variable else i has to remove the last > alphabet ("abc") and have to match with hashmap like is the process. > > My Problem is iam not able to do that iteration in when part > What i have done is i will check the condition in when part if it matches > the hashmap then it will exit. Else it will satisfies the condition(String > not matching any of hashmap contents) and goes in then and update the > string > by removing the last alphabet and loops . > > rule "somerule" > no-loop false > when > condition for checking that hashmap has no key of String s and > s.length>0 > then > modify the String s by removing last alphabet > end > > > is there any option to do the looping in the when part itself > > > -- > View this message in context: > http://drools.46999.n3.nabble.com/Looping-in-When-part-tp3393236p3393236.html > Sent from the Drools: User forum mailing list archive at Nabble.com. > _______________________________________________ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users >
_______________________________________________ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users