如何调试这个非常简单的Jess代码?

时间:2017-10-20 11:15:36

标签: jess

(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代码。我没有看到代码中有任何错误。我已经尝试了数百次并且来到Stack Overflow来获得一些 帮助它。

代码按照我的预算值运行并按300,500评估,如果预算范围匹配,我会检查用户购买的自行车的用途。之后使用事实我想发送推荐消息。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

除了拼写错误之外,这应该或多或少地起作用。我看到其中的一些,比如“tyle”而不是“type”,“user_for”而不是“use_for”,并且在数字500的大多数实例之前有一个迷路的“&lt;”。至少这三个错误中的第一个应该是当你运行这段代码时,Jess会报告。

Jess网站www.jessrules.com上提供了大多数存在的文档。如果你搜索它们,有一些YouTube视频,那里有“Jess in Action”一书;它已绝版,但找到旧拷贝并不难。