剪辑专家系统

问题描述

我正在尝试创建一个专家系统,该系统决定您是否可以购买房屋。我想知道如何写一条规则,允许某人超过一定年龄来购买房屋。例如,如果您输入的年龄已超过40岁,系统将返回并告知您不允许购买房屋。 我已经在下面尝试过此代码,但无法正常工作

(defrule age-over-forty
    (student yes)
    (income low)
    (credit excellent)
    (age 40>)
    =>
    (printout t "You can not buy a house" crlf))

编辑:我的意思是“它不起作用”;当我运行它时,您输入一个年龄,可以说我输入了46。它会将其添加到事实中,但是应该打印出“您不能买房”,因此不符合(年龄) 40>)部分代码

解决方法

使用谓词约束(CLIPS 6.3基本编程指南的5.4.1.5节)或测试条件元素进行数值比较。

         CLIPS (6.31 6/12/19)
CLIPS> 
(defrule age-over-forty
   (student yes)
   (income low)
   (credit excellent)
   (age ?age&:(> ?age 40))
   =>
   (printout t "You can not buy a house" crlf))
CLIPS> 
(assert (student yes)
        (income low)
        (credit excellent)
        (age 46))
<Fact-4>
CLIPS> (agenda)
0      age-over-forty: f-1,f-2,f-3,f-4
For a total of 1 activation.
CLIPS> (run)
You can not buy a house
CLIPS> 

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...