Or option 4 is you could write a custom operator (substring) to do it for you.

 

From: rules-users-bounces@lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Michael Anstis
Sent: 21 October 2010 08:43
To: Rules Users List
Subject: Re: [rules-users] Alternative for using a regular expression

 

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@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@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

 




**************************************************************************************
This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmaster@nds.com and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary.

NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00
**************************************************************************************