CLIPS:如何在句子中添加换行符

时间:2017-08-26 14:00:56

标签: clips expert-system

我正在使用bind函数,但要绑定的文本非常大。

我想将文本分成更多行,所以当我使用print out命令时,它会正确地适合屏幕。

有任何建议吗?

1 个答案:

答案 0 :(得分:1)

定义一个deffunction:

PlayerManager.cs

或消息处理程序

CLIPS>    
(deffunction print-to-width (?log-name ?width ?str)
  (if (<= ?width 0)
     then 
     (printout ?log-name ?str crlf)
     (return))
  (bind ?w ?width)
  (while (neq ?str "")
     (bind ?pos (str-index " " ?str))
     (if (or (not ?pos)
             (> ?pos (+ ?w 1))) 
        then 
        (if (and (not ?pos) (<= (str-length ?str) ?w))
           then
           (printout ?log-name ?str)
           (bind ?str "")
           else
           (if (!= ?w ?width)
              then 
              (printout ?log-name crlf)
              (bind ?w ?width)
              else
              (printout ?log-name (sub-string 1 ?w ?str))
              (bind ?str (sub-string (+ ?w 1) (str-length ?str) ?str))
              (if (neq ?str "") then (printout ?log-name crlf))
              (bind ?w ?width)))
        else
        (printout ?log-name (sub-string 1 ?pos ?str))
        (bind ?str (sub-string (+ ?pos 1) (str-length ?str) ?str))
        (bind ?w (- ?w ?pos)))
     (if (eq ?str "") then (printout ?log-name crlf)))
     (return))
CLIPS> (print-to-width t 0 "the quick brown fox jumped over the lazy dogs")
the quick brown fox jumped over the lazy dogs
CLIPS> (print-to-width t 80 "the quick brown fox jumped over the lazy dogs")
the quick brown fox jumped over the lazy dogs
CLIPS> (print-to-width t 40 "the quick brown fox jumped over the lazy dogs")
the quick brown fox jumped over the lazy 
dogs
CLIPS> (print-to-width t 20 "the quick brown fox jumped over the lazy dogs")
the quick brown fox 
jumped over the lazy 
dogs
CLIPS> (print-to-width t 10 "the quick brown fox jumped over the lazy dogs")
the quick 
brown fox 
jumped 
over the 
lazy dogs
CLIPS>