0

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
  • 19,194
  • 5
  • 54
  • 65

1 Answers1

0

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)))
Gary Riley
  • 10,130
  • 2
  • 19
  • 34
  • 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 – FernandoRT Dec 21 '22 at 22:06
  • If you use Si and Apagada, you need to declare the type in the deftemplate as SYMBOL. – Gary Riley Dec 22 '22 at 04:33