2015-04-23 33 views
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声明,如果满足任何条件就会被触发。

回答

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在评论中声称(见下文)有一些方法可以避免这种情况。

+0

谢谢我认为这是有效的,我只是没有得到什么问题,如果可能的话可以请多解释一下吗? –

+0

只要插入(回答衬衫是),(回答红色是),(回答裤子是),(回答蓝色是)穿着红色衬衫和蓝色裤子的绅士。 – laune

+0

哦不,我会添加一些其他信息,使其意味着什么,这只是我有问题的部分,谢谢 –