【问题标题】:How to debug this very simple Jess code?如何调试这个非常简单的 Jess 代码?
【发布时间】:2017-10-20 11:15:35
【问题描述】:
(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 评估时运行,如果预算范围匹配,我会检查用户购买自行车的用途。之后使用事实我想发送推荐消息。我该如何解决这个问题?

【问题讨论】:

  • 修正您的拼写错误:tyle, user_for
  • 啊.. 这就是问题所在.. 很抱歉在 StackOverflow 上发布一个愚蠢的问题。我曾经想过如果我设置“test(
  • 您有更多错别字:med_ 还是 medium?还有一个“中等运动”的重复规则。还有几个&lt;500

标签: jess


【解决方案1】:

这应该或多或少的工作,除了错别字。我看到了其中的一些,例如“tyle”而不是“type”,“user_for”而不是“use_for”,以及在数字 500 的大多数实例之前的杂散“

现有的大部分文档都可以在 Jess 网站 www.jessrules.com 上找到。如果您搜索它们,有一些 YouTube 视频,还有《Jess in Action》一书;它已绝版,但不难找到二手副本。

【讨论】:

  • 感谢您的真诚建议。我会努力提高我的技能。我会查找你提到的网站。我使用了许多相同的表达方式,因为我不习惯编码技能。
猜你喜欢
  • 1970-01-01
  • 2015-09-30
  • 1970-01-01
  • 1970-01-01
  • 2017-08-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多