【问题标题】:CLIPS rule unmatch(don't fire) after retract收回后 CLIPS 规则不匹配(不触发)
【发布时间】:2016-10-20 13:35:26
【问题描述】:

我有一个包含三个模块的剪辑项目,在第二个模块的末尾,我询问用户他是否要收回之前的答案之一,如果他收回第二个模块的答案之一,我需要收回第二个模块的所有答案并重新提问。在我收回第二个模块的所有答案后,我希望这条规则被激活

(defrule SECONDMODULE::domanda-esperto
   (declare (salience ?*highest-priority*))
      (livello-utente (livello esperto)) ;;assert in FIRSTMODULE and not retract
      =>
      (something)
      )

但是,如果事实列表中存在与 LHS 匹配的事实,则此规则永远不会被激活,并且它也不会出现在议程中。

对不起,我的英语不好。

编辑。 @Gary 首先我问用户 5 个问题,就是这样:

(defrule starting-rule
 (declare (salience ?*highest-priority*) (auto-focus TRUE))
  => 
 (printout t "***Inizio***" crlf)
 (focus PROFILO)
 (set-strategy random))

(defrule PROFILO::chiedi-se-possiede-auto 
 (not (domanda (nome possiede-auto) (domanda ?) (risposta ?)))
 =>
 (bind ?risposta (si-o-no "L'auto e' tua? "))
 (assert (domanda (nome possiede-auto) (domanda "L'auto e' tua? ") (risposta ?risposta)))
 )

(defrule PROFILO::frequenza-utilizzo-auto
 (not(domanda (nome frequenza-utilizzo-auto) (domanda ?) (risposta ?)))
 =>
 (bind ?risposta (risposte-range "Quante volte a settimana in media utilizzi l'auto? " 0 1-2 3-5 5-7 ))
 (assert (domanda (nome frequenza-utilizzo-auto) (domanda "Quante volte a settimana in media utilizzi l'auto? " ) (risposta ?risposta)))
)

(defrule PROFILO::conoscenza-meccanica-auto
 (not (domanda (nome conoscenza-meccanica-auto) (domanda ?) (risposta ?)))
=>
(bind ?risposta (risposte-range "Quanto ti consideri esperto della meccanica dell'auto?" 0 1 2 3 4 5))
(assert (domanda (nome conoscenza-meccanica-auto) (domanda "Quanto ti consideri esperto della meccanica dell'auto?") (risposta ?risposta)))
)

(defrule PROFILO::kit-riparazione-rapida
 (not (domanda (nome kit-riparazione-rapida) (domanda ?) (risposta ?)))
=>
(bind ?risposta (si-o-no "Possiedi un kit di riparazione rapida?"))
(assert (domanda (nome kit-riparazione-rapida) (domanda "Possiedi un kit di riparazione rapida?") (risposta ?risposta)))
)

(defrule PROFILO::anni-possesso-patente
 (not(domanda (nome anni-possesso-patente) (domanda ?) (risposta ?)))
 =>
 (bind ?risposta (risposte-range "Da quanti anni possiedi la patente? " <1 1-5 >5 ))
 (assert (domanda (nome anni-possesso-patente) (domanda "Da quanti anni possiedi la patente? ") (risposta ?risposta)))
)

在此之后,我触发了一条规则,根据用户要求描述用户的个人资料

(defrule PROFILO::livello-utente 
 ?a<-(domanda (nome possiede-auto) (domanda ?) (risposta ?))
 ?b<-(domanda (nome anni-possesso-patente) (domanda ?) (risposta ?))
 ?c<-(domanda (nome conoscenza-meccanica-auto) (domanda ?) (risposta ?))
 ?d<-(domanda (nome kit-riparazione-rapida) (domanda ?) (risposta ?))
 ?e<-(domanda (nome frequenza-utilizzo-auto) (domanda ?) (risposta ?))
 =>

 (switch (fact-slot-value ?a risposta)
  (case TRUE then (bind ?*punteggio* (+ ?*punteggio* 1)))
 )
 (switch (fact-slot-value ?d risposta)
  (case TRUE then (bind ?*punteggio* (+ ?*punteggio* 1)))
 )
 (switch  (fact-slot-value ?b risposta)
  (case <1 then (bind ?*punteggio* (+ ?*punteggio* 1)))
  (case 1-5 then (bind ?*punteggio* (+ ?*punteggio* 2)))
  (case >5 then (bind ?*punteggio* (+ ?*punteggio* 3)))
 )
 (switch (fact-slot-value ?c risposta)
  (case 1 then (bind ?*punteggio* (+ ?*punteggio* 1)))
  (case 2 then (bind ?*punteggio* (+ ?*punteggio* 2)))
  (case 3 then (bind ?*punteggio* (+ ?*punteggio* 3)))
  (case 4 then (bind ?*punteggio* (+ ?*punteggio* 4)))
  (case 5 then (bind ?*punteggio* (+ ?*punteggio* 5)))
 )
 (switch (fact-slot-value ?e risposta) 
  (case 1-2 then (bind ?*punteggio* (+ ?*punteggio* 1)))
  (case 3-5 then (bind ?*punteggio* (+ ?*punteggio* 2)))
  (case 5-7 then (bind ?*punteggio* (+ ?*punteggio* 3)))
 )
 (bind ?f ?*punteggio*)
 (if (> ?f 9) then (assert (livello-utente (livello esperto))))
 (if (< ?f 6) then (assert (livello-utente (livello principiante))))
 (if (and (> ?f 5) (< ?f 10)) then (assert (livello-utente(livello medio))))

)

之后,我进入第二个模块,根据第一个模块中确定的用户配置文件,这两个规则之一被激活

(defrule DIAGNOSI::domanda-esperto
  (declare (salience ?*highest-priority*))
  (livello-utente (livello esperto))
  =>
  (bind ?risposta (risposte-range "In quale tra le seguenti aree e' presente il problema?" Olio-motore Olio-freni Acqua Carburante Altro))
  (assert (domanda (nome area-problema)  (domanda "In quale tra le seguenti aree e' presente il problema?") (risposta ?risposta)))
  )

(defrule DIAGNOSI::domanda-medio
  (declare (salience ?*highest-priority*))
  (livello-utente (livello medio))
  =>
  (bind ?risposta (si-o-no "Sapresti indicare l'area di provenienza del problema tra le seguenti: Olio motore, Olio freni, Acqua, Carburante, Altro?"))
  (assert (domanda  (nome domanda-area-problema) (domanda "Sapresti indicare l'area di provenienza del problema tra le seguenti: Olio motore, Olio freni, Acqua, Carburante, Altro?") (risposta ?risposta)))
  (if (eq ?risposta TRUE)
    then (bind ?risposta (risposte-range "In quale tra le seguenti aree e' presente il problema?" Olio-motore Olio-freni Acqua Carburante Altro))
          (assert (domanda  (nome area-problema) (domanda "In quale tra le seguenti aree e' presente il problema?") (risposta ?risposta)))
  )

在此之后,我向用户提出了一系列其他问题。之后我问他是否想撤回其中一个,如果他选择两者中的一个(domanda-medio,domanda-esperto),我必须撤回第二个模块的所有答案。在我收回第二个模块的所有答案后,这两条规则永远不会被激活,并且如果与 LHS 匹配的事实存在于事实列表中,它也不会出现在议程中 (liveello-utente (livello ?))

【问题讨论】:

  • 您需要提供一个可重现的问题示例。
  • @GaryRiley 好的,我试试,编辑第一篇文章。

标签: clips


【解决方案1】:

@GaryRiley 好的,我不知道为什么,但添加了`

(not (diagnosi (nome ?)))`

这两条规则有效。

【讨论】:

    猜你喜欢
    • 2020-09-16
    • 1970-01-01
    • 2018-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多