[rules-users] Is it possible to Iteriate over a list of string values ?

Wolfgang Laun wolfgang.laun at gmail.com
Wed Mar 9 04:48:35 EST 2011


This is all very well, but why does it have to be so complicated?

rule createFacts
when
then
   for( String s: new String[]{ "one", "two", "three" } ){
      insert( new Fact( s ) );
   }
end

This rule executes once. Presumably you'll use a very high salience. The
condition might contain CEs to make this happen depending on whatever.

It's doable from a spreadsheet, using the "forall" substitution.

-W


On 9 March 2011 09:41, FrankVhh <frank.vanhoenshoven at agserv.eu> wrote:

> Hi all,
>
> The way I understand your question, you want to evaluate some string value
> to a list of Strings, and insert an "alarm" in the form of a new object to
> notify that these values are present.
>
> This is possible. Insert a String into working memory, then call the
> following rule:
>
> #Testing rule
> rule "test"
>        when
>                $vals: String(this in ("help","support","assist"))
>                not Fact(value == $vals )
>        then
>                insert ( new Fact ( $vals ) );
>                System.out.println("This WORKS!");
> end
>
> The rule checks for a String in working memory, and evaluates its contents
> (
> this in ( list ) ) . If a Fact with the corresponding value hasn"t been
> inserted yet, it will be inserted at runtime.
>
> Regards,
> Frank
>
>
> groovenarula wrote:
> >
> > Hello all,
> >
> > In one of my use cases, I need to insert a variable collections of facts
> > into working memory in order to be able to test for those values later :
> >
> > So I was wondering if there's a way to do something like this
> >
> >     when
> >         $vals : String() from [ "A 12345", "B 45678", "C 8695" ]
> >     then
> >          insert ( new Fact ( $vals ) );
> >
> > With the intention that the rule will fire 3 times and insert the 3 new
> > facts with the values " A 12345" and "B 45678" and "C 8695".
> >
> > Is this possible using rules or do I have to resort to using functions.
> > The problem I'm trying to overcome is to see if there's a way to get the
> > "A 12345", "B 45678", "C 8695"  from a single cell of a spreadsheet.
> >
> > Thanks in advance,
> > G
> >
>
>
> --
> View this message in context:
> http://drools-java-rules-engine.46999.n3.nabble.com/Is-it-possible-to-Iteriate-over-a-list-of-string-values-tp2654135p2654347.html
> Sent from the Drools - User 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/20110309/86c59c43/attachment.html 


More information about the rules-users mailing list