[rules-users] Alternative for using a regular expression

Michael Anstis michael.anstis at gmail.com
Thu Oct 21 03:43:19 EDT 2010


Hi Dean,

Is the encoded value used elsewhere within your organisation from the same
object model?

It'd make a compelling reason to suggest your model is enriched to expose
the decoded flags if they are (e.g. reporting).

However all is not lost:-

(1) You can use "matches" regular expressions (as you identified):-

rule "one"
    when
        $c : Claim( claimStatus matches ^.{4}1324.{0,} )
    then
        //Something
end

(2) You can use "eval":-

rule "two"
    when
        Claim( $cs : claimStatus )
        eval($cs.substring(3, 7).equals("1234"))
    then
        //Something
end

(3) You can use "from" and a global helper class:-

global MyDecoder myDecoder

rule "three"
    when
        Claim( $cs : claimStatus )
        String( toString == "1234" ) from myDecoder.decodeClaimStatus($cs)
    then
        //Something
end

See attached example project for the last option.

You could then use DSL to "hide" the technical implementations for your
users.

With kind regards,

Mike

2010/10/20 Dean Whisnant <dean at basys.com>

>  Hello,
>
>
>
> In designing our rules system to allow users and analysts to create and
> edit rules (through Guvnor) we have a requirement that some of the fields be
> able to be evaluated for specific characters in specific positions of the
> string.  See the following examples:
>
>
>
> Example 1: The string named “claimStatus” contains various flags all pushed
> together in a string.  It might look like “ABS1324BB7”.  Together this field
> means about nothing, but position 4-7 (1324) is an important code that they
> want to evaluate. A business rule for this would be if position 4-7 in
> claimStatus = “1324” then we categorize that claims for some reason.
>
>
>
> In loose java syntax I would likely use ‘if claimStatus.substring(3,4) =
> “1324” then do something.
>
>
>
> I could have the user program a formula using the substring method, but
> that would be quite inefficient and a lot of information for them to figure
> out.
>
>
>
> I could have the user say claimStatus matches ^.{4}1324.{0,} but this
> regular expression is quite cryptic.
>
>
>
> While at Rulesfest I ran the topic by a couple folks there and they thought
> that posing it to the community might be a good idea.  Is there another way
> you could see doing this?  Is there a DSL format that might get us to where
> we want?
>
>
>
> Ideas that have been thought of included creating a variable that is
> already just the 4 characters we are after, but there are dozens of fields
> that could hold this info and that would increase our data model which is
> already quite verbose.  We also looked at allowing them to create a variable
> when they need it and then just reuse that in rules, but I’m not certain how
> we would do this with as many fields.
>
>
>
> To add to it, the regular expression I listed is for one of the fields in
> these streams, we also have needs to pull out other positions as well.
>
>
>
> Your thoughts and ideas on this are appreciated.
>
>
>
> Thank you!
>
>
>
> Dean Whisnant
>
> basys, inc.
>
> _______________________________________________
> 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/20101021/a056a23a/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Decoder.zip
Type: application/zip
Size: 5961 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20101021/a056a23a/attachment.zip 


More information about the rules-users mailing list