如何在此示例中触发规则?

问题描述 投票:0回答:1

我正在尝试构建一个简单的专家系统来推荐课程,并希望在我的程序中实现确定性因素,但是我一直在寻找一种简单的集成方法。

我偶然发现了this example,但似乎无法弄明白如何让它成功。

; Allow facts that are duplicates:
(defrule start
(declare (salience 1000))
(initial-fact)
=>
(set-fact-duplication TRUE))

(defrule combine-certainities-both-positive
?fact1 <- (organism ?attribute ?value ?C1&:(>= ?C1 0))
?fact2 <- (organism ?attribute ?value ?C2&:(>= ?C2 0))
(test (neq ?fact1 ?fact2))
=>
(retract ?fact1 ?fact2)
(bind ?C3 (- (+ ?C1 ?C2) (* ?C1 ?C2)))
(assert (organism ?attribute ?value ?C3)))

(defrule combine-certainities-both-negative
?fact1 <- (organism ?attribute ?value ?C1&:(< ?C1 0))
?fact2 <- (organism ?attribute ?value ?C2&:(< ?C2 0))
(test (neq ?fact1 ?fact2))
=>
(retract ?fact1 ?fact2)
(bind ?C3 (+ (+ ?C1 ?C2) (* ?C1 ?C2)))
(assert (organism ?attribute ?value ?C3)))

(defrule combine-certainities-with-opposite-signs
?fact1 <- (organism ?attribute ?value ?C1)
?fact2 <- (organism ?attribute ?value ?C2)
(test (< (* ?C1 ?C2) 0))
(test (neq ?fact1 ?fact2))
=>
(retract ?fact1 ?fact2)
(bind ?C3 (/ (+ ?C1 ?C2) (- 1 (min (abs ?C1) (abs ?C2)))))
(assert (organism ?attribute ?value ?C3)))

我试图断言两个新的有机体事实来启动第一条规则:

CLIPS> (assert (organism morpholgy1 rod1 0.25)
(organism morpholgy2 rod2 0.25))
==> f-4     (organism morpholgy1 rod1 0.25)
==> f-5     (organism morpholgy2 rod2 0.25)
<Fact-5>
CLIPS> (run)
<== Focus MAIN
0 rules fired        Run time is 0.00300693511962891 seconds.
0.0 rules per second.
2 mean number of facts (2 maximum).
0 mean number of instances (0 maximum).
0 mean number of activations (0 maximum).

并使用匹配,但仍然没有得到如何使它匹配在这里..

CLIPS> (matches combine-certainities-both-positive)
Matches for Pattern 1
f-4
f-5
Matches for Pattern 2
f-4
f-5
Partial matches for CEs 1 - 2
 None
Activations
 None
(4 0 0)
clips
1个回答
1
投票

属性和值必须匹配(morpholgy1!= morpholgy2和rod1!= rod2)。这就是为什么必须启用事实重复才能允许相同属性/值的多个副本。

CLIPS> (set-fact-duplication TRUE)
FALSE
CLIPS> 
(assert (organism morpholgy rod 0.25)
        (organism morpholgy rod 0.25))
<Fact-2>
CLIPS> (watch facts)
CLIPS> (run)
<== f-2     (organism morpholgy rod 0.25)
<== f-1     (organism morpholgy rod 0.25)
==> f-3     (organism morpholgy rod 0.4375)
CLIPS> 
© www.soinside.com 2019 - 2024. All rights reserved.