CLIPS如何将文本分成单词?

时间:2018-04-02 09:19:29

标签: clips

我需要编写一个执行以下操作的函数方法:

  • 将文字分为单词;
  • 打印与第一个单词不同的单词;
  • 然后根据以下规则转换每个单词:

    如果单词是奇数,则删除其中间字母。

结果显示在屏幕上和文本文件中。

2 个答案:

答案 0 :(得分:0)

我建议您先从一些基本文档开始。

一个例子:

  

http://www2.cs.siu.edu/~rahimi/cs537/slides/big-2.pdf

您应该查看多字段内置函数。

答案 1 :(得分:0)

这是一个函数,它将为您提供不同单词的列表:

CLIPS> 
(deffunction munge (?text)
   (bind ?w1 (explode$ ?text))
   (bind ?w2 (create$))
   (progn$ (?w ?w1)
      (bind ?len (str-length ?w))
      (if (oddp ?len)
         then
           (bind ?nw (str-cat (sub-string 1 (div ?len 2) ?w)
                               (sub-string (+ (div ?len 2) 2) ?len ?w)))
           (bind ?w2 (create$ ?w2 ?nw))
         else
           (bind ?w2 (create$ ?w2 (str-cat ?w)))))
    (bind ?first (nth$ 1 ?w2))
    (bind ?rest (rest$ ?w2))
    (bind ?w3 (create$))
    (progn$ (?w ?w2)
      (if (neq ?w ?first)
         then
         (bind ?w3 (create$ ?w3 ?w))))
    ?w3)
CLIPS> (munge "red green blue purple brown green white red black blue")
("gren" "blue" "purple" "brwn" "gren" "whte" "blck" "blue")
CLIPS>