Re: [rules-users] Is it possible to Iteriate over a list of string values ?
ok ! It looks like Wolf, your idea of using 'for' in the RHS worked using rule templates. It's still 'java' code though. I just wish there was a cleaner way to load facts into WM without going through java. Declaring types in rules is a very nice feature. If there's a cleaner way to 'load' these from different sources like spreadsheets without using java, I would like to know that so that I can allow drools to be used in a 'stand alone' mode and let the business users to 'play' with different rules before IT needs to be pulled in to integrate the model with enterprise systems. If anyone has any ideas on how to do, please send it across. Thanks 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-tp2654135p2660559.html Sent from the Drools - User mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Is it possible to Iteriate over a list of string values ?
I was hoping to be able to give the Business Analysts an overall process to use Drools by avoiding as much java code as possible. If there was some way to do this, I could have just had them create different templates they would need (based on the format of the spreadsheets they currently use) and minimize interactions between the B.A.s and the developers. I'll just keep digging for a bit -- 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-tp2654135p2655825.html Sent from the Drools - User mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Is it possible to Iteriate over a list of string values ?
On 9 March 2011 13:07, groovenarula wrote: > >XXX YYY "one,two,three" > > where XXX, YYY will be in 2 individual cells that will hold the values for > one fact, and the "one,two,three" will be in a third cell will from which I > need to create separate instances for each value of fact #2. > > I'm trying to see if there's a way to use the current spreadsheet without > changing it drastically. That will make the solution a lot more acceptable. > > Looks like reading the cells and generating Java code to insert the facts is the cheapest solution. I see no point in constructing rules just to get some facts into WM. > W - Can you please elaborate on your last statement : > > It's doable from a spreadsheet, using the "forall" substitution. > > If I'm not mistake that's what I would use if it's a decision table - Would > I be able to use 'forall' even if I'm using a template to insert the facts > ? > Yes, I was referring to decision tables. No, that "forall" is done by the DT parser/expander. -W ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Is it possible to Iteriate over a list of string values ?
All, Thanks for the quick responses. Mantis, I did try using from [ "one","two","three" ] syntax, but it did not work. It gave me a parser error. Basically I need to create a spreadsheet reader that inserts values into WM before reasoning over them. The spreadsheet that the users are currently using for their own internal use look something like this : XXX YYY "one,two,three" where XXX, YYY will be in 2 individual cells that will hold the values for one fact, and the "one,two,three" will be in a third cell will from which I need to create separate instances for each value of fact #2. I'm trying to see if there's a way to use the current spreadsheet without changing it drastically. That will make the solution a lot more acceptable. W - Can you please elaborate on your last statement : It's doable from a spreadsheet, using the "forall" substitution. If I'm not mistake that's what I would use if it's a decision table - Would I be able to use 'forall' even if I'm using a template to insert the facts ? I'll try the different solution and see what fits the best. But if you can please elaborate on this, it will help. Thanks 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-tp2654135p2654934.html Sent from the Drools - User mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Is it possible to Iteriate over a list of string values ?
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 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@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
Re: [rules-users] Is it possible to Iteriate over a list of string values ?
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@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Is it possible to Iteriate over a list of string values ?
The Expert documentation states "The expression used to define the object source is any expression that follows regular MVEL syntax." Therefore "from" should be able to use the MVEL syntax for arrays ["one", "two", "three"] however I've not tried and never seen it used. Normally people use "from" to iterate over a dynamic list created elsewhere (another Fact pattern, a global etc). Since you say you need to handle "variable collections" I'd have thought the latter use-case more suitable for yor needs. something like:- when $pch : ParsedCellHolder( ) $val : String( ) from $pch.getStrings( ) then insert( new Fact( $val ) ); end Of course one begs to ask why you don't simply insert the individual values into WM as the spreadsheet is parsed? You'll be doing something like that to either construct the static MVEL in your example or a list. With kind regards, Mike On 9 March 2011 06:19, 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-tp2654135p2654135.html > Sent from the Drools - User 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