- Previous thread: rules-users - 5.1.0
- Next thread: rules-users - Possible concurrency issue in Drools
- Threads sorted by date: jboss-rules-users 201007
does anybody know if there is a way to do for loops in drools ?.
I am trying to loop through a list of string to see if one of the strings
matches a pattern e.g.
def listOfStrings = ['a','a.b','a.b.c']
for(String s:listOfStrings){
if(s matches "^a.b.*$"){
return true
}
}
I have written the following rule based on what documentation I could find,
but I dont think the syntax is correct
rule "Matcher"
when
TestClass : TestClass(($s matches "^a.b.*$") from listOfStrings,
count($s))
then
TestClass.setResponse( "Condition is True !!" );
end
I am finding it hard to find good documentation on the drl language
I would appreciate any help that anybody can give me
Try:
when
TestClass( $list : listOfStrings )
Number( $count : intValue ) from accumulate(
String( this matches "^a.b.*$" ) from $list,
count(1) )
then
// $count has number of matching strings
end
[]s
Edson
2010/7/31 ceemh3
Try:when TestClass( $list : listOfStrings ) Number( $count : intValue ) from accumulate( String( this matches "^a.b.*$" ) from $list,
count(1) )then // $count has number of matching stringsend []s Edson2010/7/31 ceemh3 <martin-henderson@hotmail.com>
does anybody know if there is a way to do for loops in drools ?.
I am trying to loop through a list of string to see if one of the strings
matches a pattern e.g.
def listOfStrings = ['a','a.b','a.b.c']
for(String s:listOfStrings){
if(s matches "^a.b.*$"){
return true
}
}
I have written the following rule based on what documentation I could find,
but I dont think the syntax is correct
rule "Matcher"
when
TestClass : TestClass(($s matches "^a.b.*$") from listOfStrings,
count($s))
then
TestClass.setResponse( "Condition is True !!" );
end
I am finding it hard to find good documentation on the drl language
I would appreciate any help that anybody can give me
Sent from the Drools - User mailing list archive at Nabble.com.
when
TestClass( $list : listOfStrings )
Number( $count : intValue ) from accumulate(
String( this matches "^a.b.*$" ) from $list,
count(1) )
then
// $count has number of matching strings
end
[]s
Edson
2010/7/31 ceemh3
Try:when TestClass( $list : listOfStrings ) Number( $count : intValue ) from accumulate( String( this matches "^a.b.*$" ) from $list,
count(1) )then // $count has number of matching stringsend []s Edson2010/7/31 ceemh3 <martin-henderson@hotmail.com>
does anybody know if there is a way to do for loops in drools ?.
I am trying to loop through a list of string to see if one of the strings
matches a pattern e.g.
def listOfStrings = ['a','a.b','a.b.c']
for(String s:listOfStrings){
if(s matches "^a.b.*$"){
return true
}
}
I have written the following rule based on what documentation I could find,
but I dont think the syntax is correct
rule "Matcher"
when
TestClass : TestClass(($s matches "^a.b.*$") from listOfStrings,
count($s))
then
TestClass.setResponse( "Condition is True !!" );
end
I am finding it hard to find good documentation on the drl language
I would appreciate any help that anybody can give me
Sent from the Drools - User mailing list archive at Nabble.com.
Thanks for the response
Since I dont actually need to keep a count of the number of strings that
match the pattern in the list, I have changed your solution to the code
below to make it simpler.
rule "Matcher"
when
TestClass( $list : listOfStrings )
String( this matches "^a.b.*$" ) from $list
then
TestClass.setResponse( "Condition is True !!" );
end
However, when I run this I get the following error because it doesnt
recognize the 'this' keyword
[43,197]: unknown:43:197 Unexpected token 'this'
Do you know what the problem could be ?
Hi,
I faced a similar problem. This thread helped me to solve the issue. this
keyword is working fine for me. U can check whether it is supported in your
version. I am using 5.0.1
But even this keyword works for me, I am facing another problem.
The then block executed for every success in the block
i.e., say there are 10 items in the list and 5 of the matches the regex,
then the when block executed 5 times.
Is this the only way to iterate a loop..?
My business scenario involves nested for loops. Is it possible in drools..?
How do I write a nested for loop. Remember that my inner for loop requires
values from the outer loops and this inner loops will go up to 3 or 4
levels. Is it possible and even if it is possible, will the coding become so
complex so that the business user who is going to use it may not understand
??
Kindly advice.
Regards,
Dinesh
Related Threads
- PATCH - V4L/DVB: OMAP_VOUT: Remove unneseccasry code in omap_vout_calculate_offset - linux-media
- Server problem C 0.6.5 - cassandra-user
- Plone-developers - Plone Tests: 3 OK, 2 Failed - plone-developers
- Re: SELinux - fedora-users
- android-developers - How do i switch to new activity from a custom listview ? - android-developers
- asterisk-users - ITSP with DDIs (or DIDs) from India - asterisk-users
- C++ broker - determine ip address of clients by queue - qpid-users
- rate of traffic that mach a rule - linux-netfilter
- Full-disclosure - DLL hijacking with ZIP files in email? - full-disclosure
- Forcing Vim to use findstr as 'grepprg' on Windows - vim-use
- POST with empty body - w3c-ietf-http-wg
- GENERAL - coping with failing disks - postgresql-general