Search code examples
clipsexpert-system

Delete all words from sentense that are shorter that 4 letters


I want to delete all words from sentense that are shorter that 4 letters. Print result sentence and count of deleted words. Print result on the screen and in the text file.

CLIPS Expert System. There are few guides all over the internet


Solution

  • Here's a start:

    CLIPS> 
    (deftemplate sentence
       (multislot text)
       (slot deleted_count (default 0)))
    CLIPS> 
    (defrule delete
       ?f <- (sentence (text $?b ?word&:(< (str-length ?word) 4) $?e)
                       (deleted_count ?count))
       =>
       (modify ?f (text ?b ?e) (deleted_count (+ 1 ?count))))
    CLIPS> (assert (sentence (text the quick brown fox jumped over the lazy dogs)))
    <Fact-1>
    CLIPS> (run)
    CLIPS> (facts)
    f-0     (initial-fact)
    f-4     (sentence (text quick brown jumped over lazy dogs) (deleted_count 3))
    For a total of 2 facts.
    CLIPS> 
    

    When asking questions on Stack Overflow you should make at a least a token effort to demonstrate that you've read the available documentation and made an effort to solve the problem.