I think Bob Stewart wrote:
> Hi,
>
> I want to be able to have a rule that
> handles wild cards. I can handle the
> simple case of matching Bo* or *ob, using
> the ?: with a call to startsWith or endsWith.
> But how can I handle the case of *Bob*?
> It says in the jess manual that the ?: matches
> on a TRUE value(which these first two do),
> and the ?= will match if the return value of the
> call is equal to the variable. I was thinking I
> could use String.indexOf() to see if the string1
> is a substring of string2, but that will return an
> int that is the index, or -1 if no match.
> How can I use this -1 in my defrule? Or is there
> a better or another way?
There's -always- another way :) In general, you can always wrap an
awkward java method in a userfunction or deffunction; here you might
use something like
(deffunction is-substr (?str ?substr)
(return (not (eq (?str indexOf ?substr) -1))))
(defrule foo
(foo ?x&:(is-substr ?str "foo"))
=>
...
As it turns out, a function quite similar to is-substr already comes
with Jess; it's called str-index, which you could plug right into the
rule above.
If you want even more control over matching, you'd need regexps. There
are a number of free regexp packages out there, and there's
the official "java.util.regex" in JDK 1.4. Any of these could be
wrapped a Userfunctions or deffunctions, too.
>
> Thanks,
> Bob Stewart
>
---------------------------------------------------------
Ernest Friedman-Hill
Distributed Systems Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
Org. 8920, MS 9012 [EMAIL PROTECTED]
PO Box 969 http://herzberg.ca.sandia.gov
Livermore, CA 94550
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------