对象模式中未定义的类“command_data” - CLIPS

问题描述

我在第一个代码块上使用这个 Protege 导出的代码

(defclass systemEntity
    (is-a USER)
    (role abstract)
    (single-slot SUSPECT
        (type SYMBOL)
        (allowed-values yes no)
        (default no)
        (create-accessor read-write))
    (single-slot out
        (type INTEGER)
        (range 0 31)
        (create-accessor read-write)))

(defclass command
    (is-a systemEntity)
    (role concrete))

(defclass component
    (is-a systemEntity)
    (role abstract))

(defclass sensor
    (is-a component)
    (role concrete)
    (single-slot theoretical
        (type INTEGER)
        (range 0 31)
        (create-accessor read-write))
    (single-slot out
        (type INTEGER)
        (range 0 31)
        (create-accessor read-write))
    (single-slot reading
        (type INTEGER)
        (range 0 31)
        (create-accessor read-write))
    (single-slot input
        (type INSTANCE)
        (allowed-classes internal-component)
        (create-accessor read-write)))

(defclass internal-component
    (is-a component)
    (role concrete)
    (single-slot short-out
        (type INTEGER)
        (range 0 0)
        (default 0)
        (create-accessor read-write))
    (multislot output
        (type INSTANCE)
        (allowed-classes component)
        (create-accessor read-write))
    (single-slot msb-out
        (type INTEGER)
        (range 0 15)
        (create-accessor read-write))
    (single-slot input2
        (type INSTANCE)
        (allowed-classes systemEntity)
        (create-accessor read-write))
    (single-slot input1
        (type INSTANCE)
        (allowed-classes systemEntity)
        (create-accessor read-write)))

(defclass adder
    (is-a internal-component)
    (role concrete))

(defclass multiplier
    (is-a internal-component)
    (role concrete))

(defclass circuit
    (is-a systemEntity)
    (role concrete)
    (multislot outputs
        (type INSTANCE)
        (allowed-classes sensor)
        (create-accessor read-write))
    (multislot has-components
        (type INSTANCE)
        (allowed-classes component)
        (create-accessor read-write))
    (multislot inputs
        (type INSTANCE)
        (allowed-classes command)
(create-accessor read-write)))

(defclass data
    (is-a USER)
    (role abstract)
    (single-slot clock
        (type INTEGER)
        (range 1 ?VARIABLE)
        (create-accessor read-write))
    (single-slot object
        (type INSTANCE)
        (allowed-classes systemEntity)
        (create-accessor read-write))
    (single-slot value
        (type INTEGER)
        (create-accessor read-write)))

(defclass command_data
    (is-a data)
    (role concrete)
    (single-slot object
        (type INSTANCE)
        (allowed-classes command)
        (create-accessor read-write)))

(defclass reading_data
    (is-a data)
    (role concrete)
    (single-slot object
        (type INSTANCE)
        (allowed-classes sensor)
        (create-accessor read-write)))
        
(definstances facts 
    
    
    ([a1] of  adder
    
        (input1 [input_1])
        (input2 [input_1])
        (output
            [m1]
            [p1])
        (short-out 0)
        (SUSPECT no))
    
    ([a2] of  adder
    
        (input1 [p1])
        (input2 [p2])
        (output [out1])
        (short-out 0)
        (SUSPECT no))
    
    ([circuit_1] of  circuit
    
        (has-components
            [m1]
            [m2]
            [m3]
            [out1]
            [a1]
            [a2]
            [p1]
            [p2])
        (inputs
            [input_1]
            [input_2]
            [input_3]
            [input_4])
        (outputs [out1])
        (SUSPECT no))
    
    ([command_10_inp1] of  command_data
    
        (clock 10)
        (object [input_1])
        (value 6))
    
    ([command_10_inp2] of  command_data
    
        (clock 10)
        (object [input_2])
        (value 4))
    
    ([command_10_inp3] of  command_data
    
        (clock 10)
        (object [input_3])
        (value 25))
    
    ([command_10_inp4] of  command_data
    
        (clock 10)
        (object [input_4])
        (value 12))
    
    ([command_1_inp1] of  command_data
    
        (clock 1)
        (object [input_1])
        (value 21))
    
    ([command_1_inp2] of  command_data
    
        (clock 1)
        (object [input_2])
        (value 28))
    
    ([command_1_inp3] of  command_data
    
        (clock 1)
        (object [input_3])
        (value 10))
    
    ([command_1_inp4] of  command_data
    
        (clock 1)
        (object [input_4])
        (value 25))
    
    ([command_2_inp1] of  command_data
    
        (clock 2)
        (object [input_1])
        (value 7))
    
    ([command_2_inp2] of  command_data
    
        (clock 2)
        (object [input_2])
        (value 25))
    
    ([command_2_inp3] of  command_data
    
        (clock 2)
        (object [input_3])
        (value 13))
    
    ([command_2_inp4] of  command_data
    
        (clock 2)
        (object [input_4])
        (value 15))
    
    ([command_3_inp1] of  command_data
    
        (clock 3)
        (object [input_1])
        (value 11))
    
    ([command_3_inp2] of  command_data
    
        (clock 3)
        (object [input_2])
        (value 17))
    
    ([command_3_inp3] of  command_data
    
        (clock 3)
        (object [input_3])
        (value 24))
    
    ([command_3_inp4] of  command_data
    
        (clock 3)
        (object [input_4])
        (value 31))
    
    ([command_4_inp1] of  command_data
    
        (clock 4)
        (object [input_1])
        (value 18))
    
    ([command_4_inp2] of  command_data
    
        (clock 4)
        (object [input_2])
        (value 11))
    
    ([command_4_inp3] of  command_data
    
        (clock 4)
        (object [input_3])
        (value 28))
    
    ([command_4_inp4] of  command_data
    
        (clock 4)
        (object [input_4])
        (value 21))
    
    ([command_5_inp1] of  command_data
    
        (clock 5)
        (object [input_1])
        (value 25))
    
    ([command_5_inp2] of  command_data
    
        (clock 5)
        (object [input_2])
        (value 24))
    
    ([command_5_inp3] of  command_data
    
        (clock 5)
        (object [input_3])
        (value 30))
    
    ([command_5_inp4] of  command_data
    
        (clock 5)
        (object [input_4])
        (value 10))
    
    ([command_6_inp1] of  command_data
    
        (clock 6)
        (object [input_1])
        (value 12))
    
    ([command_6_inp2] of  command_data
    
        (clock 6)
        (object [input_2])
        (value 19))
    
    ([command_6_inp3] of  command_data
    
        (clock 6)
        (object [input_3])
        (value 11))
    
    ([command_6_inp4] of  command_data
    
        (clock 6)
        (object [input_4])
        (value 19))
    
    ([command_7_inp1] of  command_data
    
        (clock 7)
        (object [input_1])
        (value 1))
    
    ([command_7_inp2] of  command_data
    
        (clock 7)
        (object [input_2])
        (value 31))
    
    ([command_7_inp3] of  command_data
    
        (clock 7)
        (object [input_3])
        (value 7))
    
    ([command_7_inp4] of  command_data
    
        (clock 7)
        (object [input_4])
        (value 22))
    
    ([command_8_inp1] of  command_data
    
        (clock 8)
        (object [input_1])
        (value 0))
    
    ([command_8_inp2] of  command_data
    
        (clock 8)
        (object [input_2])
        (value 31))
    
    ([command_8_inp3] of  command_data
    
        (clock 8)
        (object [input_3])
        (value 3))
    
    ([command_8_inp4] of  command_data
    
        (clock 8)
        (object [input_4])
        (value 23))
    
    ([command_9_inp1] of  command_data
    
        (clock 9)
        (object [input_1])
        (value 31))
    
    ([command_9_inp2] of  command_data
    
        (clock 9)
        (object [input_2])
        (value 1))
    
    ([command_9_inp3] of  command_data
    
        (clock 9)
        (object [input_3])
        (value 6))
    
    ([command_9_inp4] of  command_data
    
        (clock 9)
        (object [input_4])
        (value 8))
    
    ([input_1] of  command
    
        (SUSPECT no))
    
    ([input_2] of  command
    
        (SUSPECT no))
    
    ([input_3] of  command
    
        (SUSPECT no))
    
    ([input_4] of  command
    
        (SUSPECT no))
    
    ([m1] of  sensor
    
        (input [a1])
        (SUSPECT no))
    
    ([m2] of  sensor
    
        (input [p1])
        (SUSPECT no))
    
    ([m3] of  sensor
    
        (input [p2])
        (SUSPECT no))
    
    ([out1] of  sensor
    
        (input [a2])
        (SUSPECT no))
    
    ([p1] of  multiplier
    
        (input1 [input_2])
        (input2 [a1])
        (output
            [m2]
            [a2])
        (short-out 0)
        (SUSPECT no))
    
    ([p2] of  multiplier
    
        (input1 [input_3])
        (input2 [input_4])
        (output
            [m3]
            [a2])
        (short-out 0)
        (SUSPECT no))
    
    ([reading_10_m1] of  reading_data
    
        (clock 10)
        (object [m1])
        (value 12))
    
    ([reading_10_m2] of  reading_data
    
        (clock 10)
        (object [m2])
        (value 31))
    
    ([reading_10_m3] of  reading_data
    
        (clock 10)
        (object [m3])
        (value 12))
    
    ([reading_10_out] of  reading_data
    
        (clock 10)
        (object [out1])
        (value 28))
    
    ([reading_1_m1] of  reading_data
    
        (clock 1)
        (object [m1])
        (value 10))
    
    ([reading_1_m2] of  reading_data
    
        (clock 1)
        (object [m2])
        (value 24))
    
    ([reading_1_m3] of  reading_data
    
        (clock 1)
        (object [m3])
        (value 26))
    
    ([reading_1_out] of  reading_data
    
        (clock 1)
        (object [out1])
        (value 18))
    
    ([reading_2_m1] of  reading_data
    
        (clock 2)
        (object [m1])
        (value 0))
    
    ([reading_2_m2] of  reading_data
    
        (clock 2)
        (object [m2])
        (value 0))
    
    ([reading_2_m3] of  reading_data
    
        (clock 2)
        (object [m3])
        (value 3))
    
    ([reading_2_out] of  reading_data
    
        (clock 2)
        (object [out1])
        (value 3))
    
    ([reading_3_m1] of  reading_data
    
        (clock 3)
        (object [m1])
        (value 22))
    
    ([reading_3_m2] of  reading_data
    
        (clock 3)
        (object [m2])
        (value 6))
    
    ([reading_3_m3] of  reading_data
    
        (clock 3)
        (object [m3])
        (value 8))
    
    ([reading_3_out] of  reading_data
    
        (clock 3)
        (object [out1])
        (value 14))
    
    ([reading_4_m1] of  reading_data
    
        (clock 4)
        (object [m1])
        (value 4))
    
    ([reading_4_m2] of  reading_data
    
        (clock 4)
        (object [m2])
        (value 12))
    
    ([reading_4_m3] of  reading_data
    
        (clock 4)
        (object [m3])
        (value 12))
    
    ([reading_4_out] of  reading_data
    
        (clock 4)
        (object [out1])
        (value 0))
    
    ([reading_5_m1] of  reading_data
    
        (clock 5)
        (object [m1])
        (value 18))
    
    ([reading_5_m2] of  reading_data
    
        (clock 5)
        (object [m2])
        (value 16))
    
    ([reading_5_m3] of  reading_data
    
        (clock 5)
        (object [m3])
        (value 12))
    
    ([reading_5_out] of  reading_data
    
        (clock 5)
        (object [out1])
        (value 12))
    
    ([reading_6_m1] of  reading_data
    
        (clock 6)
        (object [m1])
        (value 8))
    
    ([reading_6_m2] of  reading_data
    
        (clock 6)
        (object [m2])
        (value 24))
    
    ([reading_6_m3] of  reading_data
    
        (clock 6)
        (object [m3])
        (value 17))
    
    ([reading_6_out] of  reading_data
    
        (clock 6)
        (object [out1])
        (value 9))
    
    ([reading_7_m1] of  reading_data
    
        (clock 7)
        (object [m1])
        (value 2))
    
    ([reading_7_m2] of  reading_data
    
        (clock 7)
        (object [m2])
        (value 0))
    
    ([reading_7_m3] of  reading_data
    
        (clock 7)
        (object [m3])
        (value 26))
    
    ([reading_7_out] of  reading_data
    
        (clock 7)
        (object [out1])
        (value 26))
    
    ([reading_8_m1] of  reading_data
    
        (clock 8)
        (object [m1])
        (value 0))
    
    ([reading_8_m2] of  reading_data
    
        (clock 8)
        (object [m2])
        (value 0))
    
    ([reading_8_m3] of  reading_data
    
        (clock 8)
        (object [m3])
        (value 0))
    
    ([reading_8_out] of  reading_data
    
        (clock 8)
        (object [out1])
        (value 0))
    
    ([reading_9_m1] of  reading_data
    
        (clock 9)
        (object [m1])
        (value 30))
    
    ([reading_9_m2] of  reading_data
    
        (clock 9)
        (object [m2])
        (value 30))
    
    ([reading_9_m3] of  reading_data
    
        (clock 9)
        (object [m3])
        (value 0))
    
    ([reading_9_out] of  reading_data
    
        (clock 9)
        (object [out1])
        (value 30))


)

这些是我写的一个函数一个规则。 我想从 command_data 对象的槽值中获取值,并在对象模式错误获取未定义的类“command_data”。 我还从 CLIPS 的控制台附加了一个打印屏幕。 有什么帮助吗?

enter image description here

(deffunction calculate-adder (?r ?z)
    (bind ?g (+ ?z ?r))
    (bind ?f (* 2 2 2 2 2))
    (mod ?g ?f)
     )
 
(defrule initial-rule
?x <- (initial-fact)
(bind ?temp =1)
(object (is-a command_data)
    (clock ?temp)
    (object [input_1])
    (value ?l))
(object (is-a command_data)
    (clock ?temp)
    (object [input_2])
    (value ?z))
=>
(retract ?x)

(bind ?w (calculate-adder (?l ?z)))
)

编辑:我更改了一些内容,现在出现新错误

enter image description here

解决方法

allowed-classes 属性非常积极地执行其限制。例如,如果实例存在,您可以在对象槽中放置一个实例名称,以便确定其类:

         CLIPS (6.31 6/12/19)
CLIPS> (clear)
CLIPS> 
(defclass command
   (is-a USER))
CLIPS>     
(defclass command_data
   (is-a USER) 
   (slot object
      (allowed-classes command)))        
CLIPS> (make-instance [c1] of command)
[c1]
CLIPS> 
(defrule no-error
   (object 
      (is-a command_data)
      (object [c1]))
   =>)
CLIPS> 

但是,如果您为尚未创建的实例使用实例名称,因此无法确定其类,则会出现错误:

CLIPS> 
(defrule triggers-static-error
   (object 
      (is-a command_data)
      (object [c2]))
   =>)

[CSTRNCHK1] A literal restriction value found in CE #1
does not match the allowed classes for slot object.

ERROR:
(defrule MAIN::triggers-static-error
   (object (is-a command_data)
           (object [c2]))
   =>)
CLIPS>

解决此问题的最简单方法是禁用静态约束检查:

CLIPS> (set-static-constraint-checking FALSE)
TRUE
CLIPS> 
(defrule no-longer-triggers-static-error
   (object 
      (is-a command_data)
      (object [c2]))
   =>)
CLIPS> 

您还可以从您的类中删除 allowed-classes 属性或修改您的规则,以便在插槽模式中不引用实例名称常量:

CLIPS> (set-static-constraint-checking TRUE)
FALSE
CLIPS> 
(defrule no-longer-triggers-static-error
   (object 
      (is-a command_data)
      (object ?o))
      (test (eq ?o [c2]))
   =>)
CLIPS> 

相关问答

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