[rules-users] Better ways to write left hand sides

Dave Schweisguth dave at schweisguth.org
Tue Sep 29 15:54:50 EDT 2009


Wolfgang,

On Tue, Sep 29, 2009 at 08:34:54AM +0200, Wolfgang Laun wrote:
> On Tue, Sep 29, 2009 at 12:43 AM, Dave Schweisguth <dave at schweisguth.org>wrote:
> > 1) One of my facts' properties is a set of strings. The goal is to "grep"
> >   them for some search string. The most convenient syntax I've come up with
> >   so far is to give the fact a method anyTextContains which loops over the
> >   set and calls contains(searchString) on each member, and then use
> >
> > fact: Fact() eval(fact.anyTextContains("searchString"))
> >
> > in my LHS. It's compact enough, but I wondered whether it could be done
> > without a custom method or eval. "from" seems not to be a possibility since
> > the collection is of strings, not objects. Any suggestions?
> 
> But any java.lang.String is an Object, although without a field (in the
> usual sense), Nevertheless, try
> 
> rule "Match John"
>      when
>          Vote( $names : names ) // Set<String> names
>          String( this matches "John" ) from $names
>      then
>          System.out.println( "Hi John" );
> end

Thanks! That solves my (first) problem exactly. It does require my rule,
which modifies the fact it matches, to be lock-on-active, but that seems
fine in my case.

Thanks,

-- 
| Dave Schweisguth                           http://schweisguth.org/~dave/ |
| Home: dave at schweisguth.org            Work: http://www.nileguide.com/ |
| For compliance with the NJ Right to Know Act: Contents partially unknown |



More information about the rules-users mailing list