(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