2017-10-20 155 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建议。我会努力工作,我的技能。我会查找你提到的网站。我用了很多相同的表达方式,因为我不习惯编码技巧。 –