(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来评估它,如果预算范围匹配,我会检查用户正在购买的自行车的用途。在此之后,我想使用事实发送推荐消息。我该如何解决这个问题?
发布于 2017-10-20 20:05:20
除了打字错误,这应该或多或少会起作用。我看到了许多这样的例子,比如“tyle”而不是“type”,“user_for”而不是“use_for”,以及数字500的大多数实例前面都有一个零散的“<”。当您运行这段代码时,Jess至少应该报告这三个错误中的第一个。
现有的大多数文档都可以在Jess网站www.jessrules.com上找到。如果你搜索一下,会发现有一些YouTube视频,还有一本名为“杰西在行动”的书;虽然已经绝版,但不难找到用过的副本。
https://stackoverflow.com/questions/46847985
复制相似问题