首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Clip新手,不知道如何处理这个初级项目

Clip新手,不知道如何处理这个初级项目
EN

Stack Overflow用户
提问于 2016-12-18 22:45:37
回答 1查看 87关注 0票数 0

我被这个剪辑项目困住了。我真的不知道如何解决我的问题。有帮助吗?this is the project

下面是我的代码:

代码语言:javascript
复制
     CLIPS> (assert (saving 30000))
<Fact-1>
CLIPS> (assert (income 50000))
<Fact-2>
CLIPS> (assert (job steady))
<Fact-3>
CLIPS> (assert (expenses 10000))
<Fact-4>
CLIPS> (defglobal ?*s* = 30000)
CLIPS> (defglobal ?*i* = 50000)
CLIPS> (defglobal ?*e* = 10000)
CLIPS> (defglobal ?*x* = 0.5)
CLIPS> (defrule rule1
   (test (> ?*s* (* ?*x* ?*i*)))
   =>
   (assert (savingst good)))
CLIPS> (defrule rule2
(job steady) 
(test(> ?*i* ?*e*))
=> (assert (incomest good))
)
CLIPS> (defrule rule3
(and (savingst good)(incomest good))
=>
(printout t "Advise is invest money in stocks" crlf)
(assert (investment ok))
)
CLIPS> (run)
Advise is invest money in stocks
CLIPS> (bsave "C:/Users/Home/Desktop/pro")
TRUE
CLIPS> (save file.clp)

首先,我不知道如何导出*.clp文件。但是我按照上面所示的那样做了。当我加载这个文件并运行它时,它只运行rule1。有谁能帮我吗?

EN

回答 1

Stack Overflow用户

发布于 2016-12-19 07:50:27

如果打开file.clp,您将看到assert语句不存在。save函数仅保存构造(如defrule、defglobal、deftemplate等),而不保存函数/命令。使用deffacts结构来指示每次使用(重置)命令时应断言的事实:

代码语言:javascript
复制
(deffacts initial
   (saving 30000)
   (income 50000)
   (job steady)
   (expenses 10000))

不必在CLIPS命令提示下输入构件,然后保存它们。只需使用文本编辑器(可以是单独的纯文本编辑器,也可以是剪辑Windows和Mac中包含的编辑器)。这使得创建/复制/编辑构造变得更容易。然后,您可以将命令提示符主要用于执行/调试命令。

这里有一个更好的方法来解决你的问题:

代码语言:javascript
复制
CLIPS> 
(deftemplate client
   (slot name)
   (slot income (default 0))
   (slot savings (default 0))
   (slot job (allowed-values steady part-time unemployed unknown))
   (slot expenses (default 0)))
CLIPS> 
(deftemplate analysis
   (slot client)
   (slot attribute)
   (slot value))
CLIPS>          
(deffacts clients
   (client (name "John Doe")
           (income 50000)
           (savings 30000)
           (job steady)))
CLIPS>            
(defrule advise-stock-investment
   (analysis (client ?client)
             (attribute income)
             (value good))
   (analysis (client ?client)
             (attribute savings)
             (value good))
   =>
   (assert (analysis (client ?client)
                     (attribute advice)
                     (value "invest money in stocks"))))   
CLIPS> 
(defrule good-saver
   (client (name ?client)
           (savings ?savings)
           (income ?income))
   (test (> ?savings (* 0.5 ?income)))
   =>
   (assert (analysis (client ?client)
                     (attribute savings)
                     (value good))))
CLIPS>            
(defrule good-income
   (client (name ?client)
           (job ?status)
           (income ?income)
           (expenses ?expenses))
   (test (or (eq ?status steady)
             (> ?income ?expenses)))
   =>
   (assert (analysis (client ?client)
                     (attribute income)
                     (value good))))
CLIPS>                      
(defrule print-advice
   (analysis (client ?client)
             (attribute advice)
             (value ?text))
   =>
   (printout t ?client " should " ?text "." crlf))
CLIPS> (watch rules)
CLIPS> (reset)
CLIPS> (run)
FIRE    1 good-saver: f-1
FIRE    2 good-income: f-1
FIRE    3 advise-stock-investment: f-3,f-2
FIRE    4 print-advice: f-4
John Doe should invest money in stocks.
CLIPS> 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41209477

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档