[rules-users] string replace collision problem

Wolfgang Laun wolfgang.laun at gmail.com
Fri Nov 18 10:52:15 EST 2011


In addition to what Frank has stated, it should be noted that the sequence
of
transformations
   SF -> S
   S -> VOL
performed by String.replace() can be simplified to a single transformation
using replaceAll with a pattern:

rule "Rule12 for parameter 1"
when
   $plan : plan( $p1: parameter1 matches ".*S.*" )
then
   modify( $plan ){
      setParameter1( $p1.replaceAll( "SF?", "VOL" ) )
  }
end

-W


On 18 November 2011 16:20, FrankVhh <frank.vanhoenshoven at agserv.eu> wrote:

> Cautionç This is answered after only a quick look.
>
> You must notify the engie that a change has occured by calling
> update(plan);
> in the RHS. Not calling update will modify the object, but the engine will
> not take these changes into account.
>
> Regards,
> Frank
>
>
> fiitkar wrote:
> >
> > Hello,
> >
> > I've problem with string replacement.
> > See the following example.
> > Input string: SF
> > I've written two simple rules:
> > The first one transforms SF to S
> > The second one transforms S to VOL.
> > The expected output after the transformation should be  S, but I get VOL.
> > (as for example for the rules: A->Z, Z->K,  input A, output will be Z and
> > not K).
> > So my question is how to avoid this problem (I suppose the problem is
> that
> > the first transformation returns substring of the input and moreover does
> > exist another transformation rule for it).
> >
> > rule "Rule1 for parameter 1"
> > salience 2
> > when
> >       plan : plan( parameter1 matches ".*SF.*" )
> > then
> >       plan.setParameter1(plan.getParameter1().replace("SF","S"));
> >
> > end
> >
> >
> > rule "Rule2 for parameter 1"
> > salience 1
> > when
> >       plan : plan( parameter1 matches ".*S.*" )
> > then
> >       plan.setParameter1(plan.getParameter1().replace("S","VOL"));
> > end
> >
> > Thank you for your response.
> > Peter
> >
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/string-replace-collision-problem-tp3518826p3518860.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20111118/90c40ce1/attachment.html 


More information about the rules-users mailing list