String matching functions in CLIPS

413 views
Skip to first unread message

Jarno

unread,
Jan 21, 2009, 1:14:05 AM1/21/09
to CLIPSESG
Hello.

I am working on a project where I have to do quite a bit of string
matching
in my rules.
And at least from what I can see from the manual CLIPS string matching
capabilities are not
exactly up to speed to other languages.

Is there easy way to do following tasks in CLIPS?

* Matching end of String (like python string.endswith())

* Matching several sub strings inside a string in correct sequence
* For example I need to match 'LABEL' and '.TXT' in
3445LABEL4364.TXT

Or what is the best way to integrate regular expressions in CLIPS so
that it
does not cause performance impact?
I am using PYClips and have been thinking of making Python call that
would
do regex for me.

Jarno

krr...@comcast.net

unread,
Jan 21, 2009, 1:54:35 PM1/21/09
to CLIP...@googlegroups.com

I generally exlpode$ the strings - would that do?

Johan Lindberg

unread,
Jan 22, 2009, 8:26:02 AM1/22/09
to CLIP...@googlegroups.com
Hi Jarno,

> Is there easy way to do following tasks in CLIPS?
>
> * Matching end of String (like python string.endswith())
>
> * Matching several sub strings inside a string in correct sequence
> * For example I need to match 'LABEL' and '.TXT' in
> 3445LABEL4364.TXT

You might be interested in an experiment I did about a year ago.
Inspired by the first chapter in the book Beatiful Code (which talks
about an implementation of a regexp engine in C), I decided to try and
write one in CLIPS. You can read about it here[1].

It is, however, an experiment. It works, but I don't think it will
scale very well if you give it lots of work to do.

> Or what is the best way to integrate regular expressions in CLIPS so
> that it
> does not cause performance impact?
> I am using PYClips and have been thinking of making Python call that
> would
> do regex for me.

If you are worried about performance I think the best way is to call
out to Python. If you make sure to use compiled regexps it should be
sufficiently fast.

BR
Johan Lindberg
jo...@pulp.se

[1] http://commentsarelies.blogspot.com/2007/11/added-some-functionality-in-clips.html
and http://commentsarelies.blogspot.com/2007/10/small-regular-expression-library-for.html

FranzG

unread,
Jan 27, 2009, 6:58:29 PM1/27/09
to CLIPSESG
Hi,

jumping in and out of Python could have some performance issues on
large amount of facts. However, trying to achieve the same goal in
CLIPS without writing appropriately extending it with proper C
functions could also be painful, even as a matter of performance. I'd
use a cleverly coded "python-call", as Johan says, paying attention to
the efficiency of Python code, but I'm biased! ;-)

However, you should keep in mind that both CLIPS and Python are
interpreted languages. But, on the other hand, if you're using PyCLIPS
you're more or less forced to use Python functions instead of possible
C functions, as it could be rather uncomfortable to extend PyCLIPS
with custom C functions.

F.

FranzG

unread,
Jan 27, 2009, 7:03:58 PM1/27/09
to CLIPSESG
Uhm... remove "writing" from the first sentence ("without writing
appropriately" should read "without appropriately").

F.
Reply all
Reply to author
Forward
0 new messages