I am creating an expert system using clipspy, when I run the code in Python it throws nothing in the output and I have not been able to find the reason.
Python code:
import clips
DEFTEMPLATE_STRING = """
(deftemplate dormitorio
(slot Presencia (type STRING))
(slot Iluminación (type STRING)))
"""
env = clips.Environment()
env.build(DEFTEMPLATE_STRING)
env.load('test.CLP')
Dormitorio = env.find_template('dormitorio')
fact_Dormitorio = Dormitorio.assert_fact(Presencia = 'Si',
Iluminación = 'Apagada')
env.reset()
env.run()
Clips file:
(defrule dormitorio
(Presencia Si)
(Iluminación Apagada)
=>
(printout t "Encender la iluminación del dormitorio." crlf)
(modify 1 (Iluminación Encendida))
)
What is expected is to output the print and modify the variable (Iluminación)?
mkrieger1
24.2k7 gold badges68 silver badges84 bronze badges
1 Answer 1
You used dormitorio as the rule name when it needs to come after the rule name and an opening parenthesis for a fact pattern.
Don't use an integer constant with the modify command in the actions of the rule. Bind the fact matching the pattern to a variable and use that with the modify command.
(defrule r1
?d <- (dormitorio
(Presencia Si)
(Iluminación Apagada))
=>
(printout t "Encender la iluminación del dormitorio." crlf)
(modify ?d (Iluminación Encendida)))
answered Dec 20, 2022 at 1:47
Gary Riley
10.8k2 gold badges22 silver badges37 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
FernandoRT
When I run the code with the modified rule I get this error: test.CLP, Line 7: A literal restriction value found in CE #1 does not match the allowed types for slot 'Presencia'. ERROR: (defrule MAIN::r1 ?d <- (dormitorio (Presencia Si) (Iluminación Apagada)) => (printout t "Encender la iluminación del dormitorio." crlf) (modify ?d (Iluminación Encendida))). @Gary Riley
Gary Riley
If you use Si and Apagada, you need to declare the type in the deftemplate as SYMBOL.