Jess 匹配规则不触发

Jess matching rule does not fire

我在定义匹配规则时遇到困难。

(defrule set-current  
    ?desAct <- (Actuator (name 0) (StrokeLength ?sl) (Force ?f) 
    (nominalCurrent ?c3)) 
    (test (eq ?c3 0)) ; I have defined this to change only if value is not 
                      ; set yet
    ?act <- (Actuator (inputVoltage ?v1)  ; actuator that has matching slots
    (StrokeLength ?sl1)
    (nominalCurrent ?c1))
    (test (eq ?sl1 ?sl)) ; for same stroke length I want to modify 
                         ; nominalCurrent of ?desAct
    =>
    (modify ?desAct (nominalCurrent ?c1))
    )   

?desAct 表示我想根据基于某些标准的其他现有事实更改哪些插槽值。 我不确定为什么这条规则不会因为以下事实而触发:

f-4   (MAIN::Actuator (name 4) (inputVoltage 12) (Force 17) (StrokeLength 10) (length 62) (width 18) (height 15.1) (motorType DC) (speedAtNomLoad 25) (weight 28) (nominalCurrent 0.46) (highTemp 50) (lowTemp -10) (price 90) (dutyCycle 20))
f-9   (MAIN::Actuator (name 0) (inputVoltage 12) (Force 17) (StrokeLength 10) (length 10) (width 10) (height 10) (motorType DC) (speedAtNomLoad 0) (weight 0) (nominalCurrent 0) (highTemp 0) (lowTemp 0) (price 0) (dutyCycle 0))

我希望使用此规则的名称为 0 的执行器具有与 f-4 相同的标称电流,但规则不会触发。

规则确实触发了,但不止一次。如果您有相同模板的事实,请确保避免 1 或 2 个事实的多次匹配。

(defrule set-current  
  ?act1 <- (Actuator (name ?n1)
                     (inputVoltage ?v1)
                     (StrokeLength ?sl1)
                     (nominalCurrent ?c1&0))
  ?act2 <- (Actuator (name ?n2&~?n1)         ; avoid redundant matches
                     (inputVoltage ?v1)      ; same input voltage
                     (StrokeLength ?sl1)     ; same stroke length
                     (nominalCurrent ?c2))   ; bind current
=>
  (printout t "modify actuator " ?n1 " current=" ?c2 crlf)
  (modify ?act1 (nominalCurrent ?c2))
)   

约束(name ?n2&~?n1) 强制在具有不同名称值的执行器之间进行匹配。重用绑定变量会强制匹配具有该值的插槽。

不要使用 test。与绑定变量的名称更加一致。