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
24.2k7 gold badges68 silver badges84 bronze badges
asked Dec 19, 2022 at 23:18

1 Answer 1

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)))
answered Dec 20, 2022 at 1:47
Sign up to request clarification or add additional context in comments.

2 Comments

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
If you use Si and Apagada, you need to declare the type in the deftemplate as SYMBOL.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.