FernandoRT
FernandoRT

Reputation: 1

Why does this error occur when creating an expert system in Python using clipspy?

When I run the code I get this error:

clips.common.CLIPSError: [CSTRNCHK1] 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))).

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.run()   

Clips file:

(defrule r1
   ?d <- (dormitorio
            (Presencia Si)
            (Iluminación Apagada))
   =>
   (printout t "Encender la iluminación del dormitorio." crlf)
   (modify ?d (Iluminación Encendida)))

Why does this error occur?

Upvotes: 0

Views: 134

Answers (2)

noxdafox
noxdafox

Reputation: 15060

As Gary Riley said, your rule is expecting SYMBOL type but your deftemplate is declaring the type as STRING.

Either you modify the rule to match a string:

(defrule r1
   ?d <- (dormitorio
            (Presencia "Si")
            (Iluminación "Apagada"))
   =>
   (printout t "Encender la iluminación del dormitorio." crlf)
   (modify ?d (Iluminación Encendida)))

Or you pass the values as SYMBOL.

DEFTEMPLATE_STRING = """
(deftemplate dormitorio
    (slot Presencia (type SYMBOL))
    (slot Iluminación (type SYMBOL)))
"""

...

fact_Dormitorio = Dormitorio.assert_fact(Presencia = clips.Symbol('Si'),
                                         Iluminación = clips.Symbol('Apagada'))

Upvotes: 0

Gary Riley
Gary Riley

Reputation: 10757

Si and Apagada are symbols. Strings are enclosed in quotation marks. Declare the types in the deftemplate as SYMBOL.

Upvotes: 0

Related Questions