Added some functionality in the Clips regexp library
Today I spent about three hours on a train between Stockholm and Gothenburg. That was nearly enough to complete the functionality in the small regexp library for Clips I wrote a few weeks ago.
I've added findall, split and sub(stitute) functions which work likeso:
CLIPS> (load "regexp.clp")Ok, my examples might not be the best but you get the idea. Both split and sub also take an optional parameter ?max which allows you to limit the number of splits and substitutions:
:!!!!!!
CLIPS> (findall "a" "Today I spent about three hours on a train between Stockholm and Gothenburg")
("4 4 "a"" "15 15 "a"" "36 36 "a"" "40 40 "a"" "62 62 "a"")
CLIPS> (split "a" "Today I spent about three hours on a train between Stockholm and Gothenburg")
("Tod" "y I spent " "bout three hours on " " tr" "in between Stockholm " "nd Gothenburg")
CLIPS> (sub "a" "A" "Today I spent about three hours on a train between Stockholm and Gothenburg")
"TodAy I spent About three hours on A trAin between Stockholm And Gothenburg"
CLIPS> (sub "a" "A" "Today I spent about three hours on a train between Stockholm and Gothenburg" 2)The library consists of two files: regexp.clp and regexp-test.bat (requires unittest.clp).
"TodAy I spent About three hours on a train between Stockholm and Gothenburg"
[2007-11-30] Update: I found a bug in the search function which caused a string not to be properly searched (the search ended too early). Apparently my test cases are not very good...
Inga kommentarer:
Skicka en kommentar