(deftemplate bikelife
(slot name)
(slot type))
(deffacts bike
(bikelife (name Strida) (type low_lifestyle))
(bikelife (name Brompton) (type med_lifestyle))
(bikelife (name Molton) (type high_lifestyle))
(bikelife (name Specialized_AlleComp) (type low_sport))
(bikelife (name Specialized_Tarmac) (type medium_sport))
(bikelife (name Pinarello_DOGMA_F8) (type high_sport)))
(defrule rule-1
(budget ?x)
(test (< ?x 300))
(use_for lifestyle)
=>
(assert (recommend low_lifestyle)))
(defrule rule-2
(budget ?x)
(test (< ?x 300))
(use_for sport)
=>
(assert (recommend low_sport)))
(defrule rule-3
(budget ?x)
(test (and (> ?x 300) (< ?x <500)))
(use_for lifestyle)
=>
(assert (recommend med_lifestyle)))
(defrule rule-4
(budget ?x)
(test (and (> ?x 300) (< ?x <500)))
(use_for sport)
=>
(assert (recommend med_sport)))
(defrule rule-5
(budget ?x)
(test (> ?x 500))
(use_for lifestyle)
=>
(assert (recommend high_lifestyle)))
(defrule rule-6
(budget ?x)
(test (and (> ?x 300) (< ?x <500)))
(use_for sport)
=>
(assert (recommend med_sport)))
(defrule rule-7
(budget ?x)
(test (> ?x 500))
(use_for sport)
=>
(assert (recommend high_sport)))
(defrule recommend-rule
(recommend ?type)
(bikelife (name ?x) (type ?type))
=>
(printout t crlf "I recommend " ?x " for you." crlf crlf))
(defrule ask-1
=>
(printout t crlf "================================ ")
(printout t crlf " testing testing testing. ")
(printout t crlf "================================ " crlf crlf)
(printout t "* How much are you going to spend on bike? ")
(assert (budget (read)))
(printout t "* what purpose? (lifestyle, sport)")
(assert (use_for (read))))
(reset)
(run)
這是我推薦自行車的Jess碼。我在代碼中看不到任何錯誤。我已經嘗試了數百次,來到堆棧溢出以獲得一些 幫助。如何調試這個非常簡單的Jess代碼?
該代碼運作,因爲我得到的預算價值和評估300,500,如果預算範圍匹配我檢查用戶購買自行車的目的。之後,使用事實我想發送推薦信息。我怎麼解決這個問題?
修復你的錯誤:'tyle','user_for'。 – laune
啊..這是問題..抱歉在StackOverflow發佈一個愚蠢的問題。我曾經想過,如果我設置了「test(<?x 500)」,那麼x的值就會持續到問題結束,我認爲這是問題所在。非常感謝! –
您有更多的錯別字:med_或medium?還有一個重複的「中型運動」規則。還有幾個「<500」。 – laune