2014-09-20 52 views
0

首先模板实例,我宣布:CLIPS计数的事实或匹配的模式

(自定义模板工人 (插槽ID (类型STRING) (默认DERIVE))

(插槽工资 (float型) (?默认DERIVE)))

然后我补充一下:

(断言(工人(ID “A”)(工资30.0)))

(断言(工人(ID “B”)(工资40.0)))

(断言(工人(ID “C”)(工资60.0)))

(断言(工人(ID “d”)(工资70.0)))

(断言(工人(ID的 “e”)(工资10.0)))

我该如何计算有多少工作rs'我有吗?

我怎样才能算出有多少工人的工资超过30?

回答

2

用事实设定的查询功能:

CLIPS> 
(deftemplate worker 
    (slot id (type STRING) (default ?DERIVE)) 
    (slot salary (type FLOAT) (default ?DERIVE))) 
CLIPS> (assert (worker (id "a") (salary 30.0))) 
<Fact-1> 
CLIPS> (assert (worker (id "b") (salary 40.0))) 
<Fact-2> 
CLIPS> (assert (worker (id "c") (salary 60.0))) 
<Fact-3> 
CLIPS> (assert (worker (id "d") (salary 70.0))) 
<Fact-4> 
CLIPS> (assert (worker (id "e") (salary 10.0))) 
<Fact-5> 
CLIPS> (find-all-facts ((?f worker)) (> ?f:salary 30.0)) 
(<Fact-2> <Fact-3> <Fact-4>) 
CLIPS> (length$ (find-all-facts ((?f worker)) (> ?f:salary 30.0))) 
3 
CLIPS> (do-for-all-facts ((?f worker)) (> ?f:salary 30.0) (printout t ?f:id crlf)) 
b 
c 
d 
CLIPS>