[rules-users] How to do word match in drools?

Wolfgang Laun wolfgang.laun at gmail.com
Thu Mar 27 14:32:48 EDT 2014


See inline.


On 27 March 2014 16:59, Yuan, Stacy [DBA] <stacyy at telenav.com> wrote:

> Hi,
>
> I am new to this area. Thank you very much for your reply!
>
> This is current script
>
> brandName matches
> "(?i)(.*cyber.*|.*internet.*|.*pizza.*|.*restaurant.*|.*sushi.*)
>
> So this  matches every string containing sushi.
>
> Joa Sushie Café
> Java Sushi
> Sushi Blvd
> Japanese Sushi Bar
>

This is to be expected: each of these 4 lines contains "sushi".



>
> But I only want to match the word sushi. This means " Joa Sushie Café"
> will not be included.
>
> Actually I am looking for word match. What is the best way to include
> above words?
>

All regular expressions I know have a way for expressing the concept "word
boundary".
This is a zero-length assumption (or "anchor"), that matches a transition
from a word character
to a non-word character. (Note that the definition of "word character" may
not *always*
meet your expectations, but it should in this case.)



> brandName ==
> "(?i)(.*cyber.*|.*internet.*|.*pizza.*|.*restaurant.*|.*sushi.*)???
>
>
(The "==" is bad: you want to do a pattern match.) OK, to restrict the
"sushi" to the
real thing (assuming the final "???" aren't relevant):

    brandName matches "(?i)(...|... ...|\\bsushi\\b)"

"\b" is the word boundary anchor, and you have to duplicate the backslash,
as in Java.
 If the same borderline case should hold for pizza and others, you could use

    brandName matches
"(?i).*\\b(cyber|internet|pizza|restaurant|sushi)\\b.*"

All of this is untested, but it shouldn't be very far off the mark.
-W


>
> Best
>
> Stacy
>
> -----Original Message-----
> From: rules-users-bounces at lists.jboss.org [mailto:
> rules-users-bounces at lists.jboss.org] On Behalf Of Wolfgang Laun
> Sent: Thursday, March 27, 2014 12:26 AM
> To: Rules Users List
> Subject: Re: [rules-users] How to do word match in drools?
>
> You can use == to compare strings.
>
> For a more comprehensive answer, ask a more detailed question.
>
> -W
>
> On 26/03/2014, Yuan, Stacy [DBA] <stacyy at telenav.com> wrote:
> > For example,  word sushi
> > I do not want sushie show up and shsushi show up when we do drools match.
> >
> > Thanks
> > Stacy
> >
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
> _______________________________________________
> 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/20140327/68738f12/attachment.html 


More information about the rules-users mailing list