首页 > 解决方案 > 剪辑:匹配(或不匹配空字符串)

问题描述

我正在尝试逐段翻译字符串,所以我知道原始字符串何时为空,然后我们就完成了。问题是,当“输入”字符串中没有任何内容时,CLIPS 怎么知道?

(defrule check-if-empty
    ?phase <- (phase CONVERT)
    (input "code here possibly")
    =>
    (retract ?phase ?input)
    (assert (phase PRINT))
    (return))

标签: clipsexpert-system

解决方案


CLIPS 中的空字符串是“”,所以只需将“code here possible”替换为“”。除非您正在使用模块并希望在当前焦点的模块中结束规则的执行,否则也无需在规则的末尾放置 return。

(defrule check-if-empty
    ?phase <- (phase CONVERT)
    ?input <- (input "")
    =>
    (retract ?phase ?input)
    (assert (phase PRINT)))

推荐阅读