2016-05-04 25 views
0

不確定爲什麼這不起作用。短片或聲明未觸發

(defrule contain-red? 
(initial-fact) 
=> 
(bind ?reply (get-text-from-user "Does it contain x (y/n?")) 
(assert (existing-text ?reply))) 

(defrule partOne 
(existing-text "y") 
=> 
(bind ?reply (get-text-from-user "give me a number")) 
(assert (credit-value-bsc-first-result (explode$ ?reply)))) 

(defrule partTwo 
(existing-text "n") 
=> 
(bind ?reply (get-text-from-user "give me a number")) 
(assert (credit-value-bsc-second-result (explode$ ?reply)))) 

(defrule learn-about-120? 
(credit-value-bsc-first-result ?n) 
(credit-value-bsc-second-result ?x) 
(test (or (<= ?n 20) (<= ?x 20))) 
=> 
(bind ?reply (get-text-from-user "Reponse here)")) 
(assert (learn-about-120-response ?reply))) 

我可以得到使用和在不同的情況下工作的最終規則。將此加載到wxCLIPS中時不會出現錯誤,但是當我運行它並輸入相關數據時,最終規則不會觸發。

回答

0

事實上,僅當現有文本爲「y」時,纔會創建credit-value-bc-first-result。事實上,credit-value-bc-second-result僅在現有文本爲「n」時纔會創建。如果只存在一個現有文本事實,則這些條件是相互排斥的。由於規則學習約120?要求這兩個事實都不會觸發。

寫你想要什麼規則這種方式可能是:

(defrule learn-about-120? 
    (or (credit-value-bsc-first-result ?n) 
     (credit-value-bsc-second-result ?n)) 
    (test (<= ?n 20)) 
    => 
    (bind ?reply (get-text-from-user "Reponse here)")) 
    (assert (learn-about-120-response ?reply))) 
+0

謝謝!我有一種感覺,變量是空的可能是一個問題。 – Joe