2017-10-20 157 views
0
(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,如果預算範圍匹配我檢查用戶購買自行車的目的。之後,使用事實我想發送推薦信息。我怎麼解決這個問題?

+0

修復你的錯誤:'tyle','user_for'。 – laune

+0

啊..這是問題..抱歉在StackOverflow發佈一個愚蠢的問題。我曾經想過,如果我設置了「test(<?x 500)」,那麼x的值就會持續到問題結束,我認爲這是問題所在。非常感謝! –

+0

您有更多的錯別字:med_或medium?還有一個重複的「中型運動」規則。還有幾個「<500」。 – laune

回答

0

這應該或多或少的工作,除了錯別字。在數字500的大多數情況下,我會看到它們中的一些,例如「tyle」而不是「type」,「user_for」而不是「use_for」,以及流浪的「<」。至少這三個錯誤中的第一個應該是當您運行此代碼時由Jess報告。

存在的大多數文件可在Jess網站www.jessrules.com上找到。如果你搜索它們,有幾個YouTube視頻,並且有「Jess in Action」這本書。它已經絕版,但不難找到使用的副本。

+0

謝謝你的sencere建議。我會努力工作,我的技能。我會查找你提到的網站。我用了很多相同的表達方式,因爲我不習慣編碼技巧。 –