剪辑:比较彼此之间的事实

时间:2016-12-21 04:39:10

标签: clips

我试图创建一个专家系统,每当用户回答问题时,它就会创建一个新事实(例如):

assert(like accion yes)
assert(like multi yes)

一旦完成,它会显示每个游戏的名称,其描述中包含这些事实:

(deffacts gaming (game Call_of_Duty multi accion)
(game BattleField multi strategy))

我尝试使用这个规则,在那里我检查每个" like-fact"位于一个特定的"游戏事实"内,但它不起作用:

(defrule conclusion
   (like $?x yes)
   (game ?y $?x2)
   (test(member$ ?x ?x2))
   =>
   (printout t "You like the game: " ?y crlf))

1 个答案:

答案 0 :(得分:0)

您可以通过以下三种方式编写规则。您的原始规则-1结论将为每个匹配游戏的消息打印一条消息,这样您就可以为每个游戏获得多个打印件。规则结论-2如果存在至少一个与游戏相匹配的游戏则打印游戏。最多只会打印一次游戏。规则结论-3只有在匹配该游戏的每个类似时才会打印游戏。

CLIPS> 
(deffacts gaming 
   (like accion yes)
   (like multi yes)
   (game Call_of_Duty multi accion)
   (game BattleField multi strategy))
CLIPS>    
(defrule conclusion-1
   (like $?x yes)
   (game ?y $?x2)
   (test(member$ ?x ?x2))
   =>
   (printout t "1 You like the game: " ?y crlf))
CLIPS>    
(defrule conclusion-2
   (game ?y $?x2)
   (exists (like $?x yes)
           (test (member$ ?x ?x2)))
   =>
   (printout t "2 You like the game: " ?y crlf))
CLIPS>    
(defrule conclusion-3
   (game ?y $?x2)
   (forall (like $?x yes)
           (test (member$ ?x ?x2)))
   =>
   (printout t "3 You like the game: " ?y crlf))
CLIPS> (reset)
CLIPS> (run)
1 You like the game: BattleField
2 You like the game: BattleField
1 You like the game: Call_of_Duty
1 You like the game: Call_of_Duty
2 You like the game: Call_of_Duty
3 You like the game: Call_of_Duty
CLIPS>