Artificial intelligence 从剪辑中的定义访问值
我正在为一项处理电路的作业编写CLIPS程序。我使用Protege创建了我的本体,从那里我创建了clp文件并将其加载到剪辑中。结果如下:Artificial intelligence 从剪辑中的定义访问值,artificial-intelligence,ontology,protege,clips,Artificial Intelligence,Ontology,Protege,Clips,我正在为一项处理电路的作业编写CLIPS程序。我使用Protege创建了我的本体,从那里我创建了clp文件并将其加载到剪辑中。结果如下: (defclass systemEntity (is-a USER) (role abstract) (single-slot suspect (type SYMBOL) (allowed-values yes no) (default no) (create-access
(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)
(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_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))
([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_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))
)
我试图弄清楚如何使用defrules打印出一个类的特定输入的所有输入和输出,比如加法器a1。我将通过展示几个定义来说明我在下面的意思:
([a1] of adder
(input1 [input_1])
(input2 [input_1])
(output
[m1]
[p1])
(short-out 0)
(suspect no))
a1加法器将输入_1实例作为input1和input2,即:
([command_1_inp1] of command_data
(clock 1)
(object [input_1])
(value 21))
([reading_1_m1] of reading_data
(clock 1)
(object [m1])
(value 10))
以及输出到m1和p1,从中可以通过m1实例获得输出,即:
([command_1_inp1] of command_data
(clock 1)
(object [input_1])
(value 21))
([reading_1_m1] of reading_data
(clock 1)
(object [m1])
(value 10))
然而,当我试图访问实例的值(例如,第一个输入的值)时,我得到一个错误现有类的任何对象都不能满足对象模式中的is-a限制。
(defrule find-input-1
(object (is-a command_data)
(clock ?clock)
(value ?value))
=>
(printout t ?clock " " ?value crlf))
我做错了什么?如何访问实例的值?您需要在规则中使用object关键字,否则CLIPS会将内部组件视为事实
(defrule print-sensor
(object (is-a internal-component) (input1 ?input1) (input2 ?input2))
=>
(printout t ?input1 " " ?input2 crlf))
您还需要将内部组件类声明为被动的,以便在规则中使用它
(defclass internal-component
(is-a component)
(role concrete)
(pattern-match reactive)
.
.
.
)
谢谢你的回答,加里先生。我试过了,但在控制台上看不到任何打印内容。我也意识到,也许我没有很好地解释我想要实现的目标。我想做的是,例如,能够获得输入值(输入值_1和输入值_1)以及输出值(输出值为m1和p1),然后能够打印它们。输入值包含在command_data的
([command_1_inp2])中,输出值包含在reading_data的([reading_1_m1])中。使用您发布的代码和我建议的更改对我来说效果很好。