剪辑:相互比较事实
Clips: comparing facts between each other
我正在尝试创建一个专家系统,每次用户回答问题时都会创建一个新事实(例如):
assert(like accion yes)
assert(like multi yes)
完成后,它会显示描述中包含这些事实的每个游戏的名称:
(deffacts gaming (game Call_of_Duty multi accion)
(game BattleField multi strategy))
我尝试使用此规则,我检查每个 "like-fact" 是否位于特定的 "game-fact" 内,但它不起作用:
(defrule conclusion
(like $?x yes)
(game ?y $?x2)
(test(member$ ?x ?x2))
=>
(printout t "You like the game: " ?y crlf))
您可以通过以下三种不同的方式编写规则。您的原始规则 conclusion-1 将为每个与游戏匹配的类似对象打印一条消息,因此您可以为每个游戏获得多个打印件。规则 conclusion-2 打印一个游戏,如果至少有一个匹配的游戏。最多你会看到一个游戏打印一次。规则 conclusion-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>
我正在尝试创建一个专家系统,每次用户回答问题时都会创建一个新事实(例如):
assert(like accion yes)
assert(like multi yes)
完成后,它会显示描述中包含这些事实的每个游戏的名称:
(deffacts gaming (game Call_of_Duty multi accion)
(game BattleField multi strategy))
我尝试使用此规则,我检查每个 "like-fact" 是否位于特定的 "game-fact" 内,但它不起作用:
(defrule conclusion
(like $?x yes)
(game ?y $?x2)
(test(member$ ?x ?x2))
=>
(printout t "You like the game: " ?y crlf))
您可以通过以下三种不同的方式编写规则。您的原始规则 conclusion-1 将为每个与游戏匹配的类似对象打印一条消息,因此您可以为每个游戏获得多个打印件。规则 conclusion-2 打印一个游戏,如果至少有一个匹配的游戏。最多你会看到一个游戏打印一次。规则 conclusion-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>