0

我想知道如何组合我的两个规则,例如:

(defrule Rules::pants
  (declare (auto-focus TRUE))
(answer (ident color) (text red))
  (answer (ident pants) (text yes))
  =>
(printout t "you are wearing red pants"))

(defrule Rules::shirt
  (declare (auto-focus TRUE))
(answer (ident shirt) (text blue))
  (answer (ident red) (text yes))
  =>
(printout t "you are wearing blue shirt"))

如果我写这两个规则,例如:

(defrule Rules::pants
  (declare (auto-focus TRUE))
(answer (ident red) (text yes))
  (answer (ident pants) (text yes))
(answer (ident shirt) (text yes))
  (answer (ident blue) (text yes))
  =>
(printout t "you are wearing blue shirt and red pants"))

我希望它像一个OR语句一样,如果满足任何条件就被触发。

4

1 回答 1

0

天真的答案是

(defrule Rules::pants      
  (or (and (answer (ident red) (text yes))
           (answer (ident pants) (text yes)))
      (and (answer (ident shirt) (text yes))
           (answer (ident blue) (text yes)))
  )
 =>
   (printout t "you are wearing blue shirt or red pants")
)

第一个问题是,如果这个人穿着红色裤子蓝色衬衫,这条规则会触发两次。最有可能的是,这无关紧要,因为该人未被识别,因此我们可以假设只有一个人在走秀。

已编辑如果属性不相互关联,即当颜色和项目可以自由组合时,就会发生第二个障碍。考虑一个带有蓝色牛仔裤和红色格子衬衫的乡下人。该规则会触发,因为有“裤子”和“衬衫”以及“红色”和“蓝色”,足以根据模式进行匹配。但是 OP 在评论中断言(见下文)有一些方法可以避免这种情况。

于 2015-04-23T17:16:44.663 回答