LHS 中值的可变顺序,OR/AND 运算符

Variable Order of values in LHS, OR/AND operators

我正在尝试通过这种形式定义规则:


;Plantilla Ficha de paciente
(deftemplate FichaPaciente
    (multifield Nombre)
    (field Casado)
    (field Direccion))

;Plantilla DatosExploración
(deftemplate DatosExploracion
    (multifield Nombre)
    (multifield Sintomas)
    (field GravedadAfeccion))

;Regla para diagnóstico de Eccema
(defrule DiagnosticoEccema
    (DatosExploracion
        (and
        (Nombre $?Nombre)
            (or
            (Sintomas $? picor $? vesiculas $?)
            (Sintomas $? vesiculas $? picor $?)
            )
        )
    )
    (FichaPaciente
        (Nombre $?Nombre))
=>
    (printout t "Posible diagnóstico para el paciente " $?Nombre ": Eccema " crlf)
)

目标是 DatosExploracion 事实是否具有值为 (... picor ... vesicula ...) 或 (... vesicula ... picor) 的 Sintomas 字段并不重要。 Vesicula 和 picor 顺序并不重要。

我正在尝试使用“and”和“or”运算符,但收到错误消息:相应的 deftemplate 'DatosExploracion'.

中未定义无效插槽 'and'

1 - 为什么 CLIPS 不能像我想要的那样识别 AND 和 OR 运算符?

2 - 是否有更好或更有效的方法来获取不重要的字段 Sintomas 上的值顺序?

提前致谢。

我已经通过这种方式实现了目标


(defrule DiagnosticoEccema
    (or (DatosExploracion
        (Nombre $?Nombre)
        (Sintomas $? picor $? vesiculas $?))
        (DatosExploracion
        (Nombre $?Nombre)
        (Sintomas $? vesiculas $? picor $?))
    )        
    (FichaPaciente
        (Nombre $?Nombre))
=>
    (printout t "Posible diagnóstico para el paciente " $?Nombre ": Eccema " crlf)
)

但如果是多字段Sintomas的3,4或5个Values的无序组合,那就太乏味了。我想是否有更好的方法来使用连接词 |或 & 以更有效的方式。

这是您可以做到的一种方法:

(defrule DiagnosticoEccema
   (DatosExploracion
      (Nombre $?Nombre)
      (Sintomas $?Sintomas&:(and (member$ picor ?Sintomas)
                                 (member$ vesiculas ?Sintomas))))
   (FichaPaciente
      (Nombre $?Nombre))
   =>
   (printout t "Posible diagnóstico para el paciente " $?Nombre ": Eccema " crlf))

另一个使用辅助函数来减少出现多种症状时的打字量:

(deffunction all-present (?set1 $?set2)
   (foreach ?s ?set2
      (if (not (member$ ?s ?set1))
         then (return FALSE)))
   (return TRUE))    
   
(defrule DiagnosticoEccema
   (DatosExploracion
      (Nombre $?Nombre)
      (Sintomas $?Sintomas&:(all-present ?Sintomas picor vesiculas)))
   (FichaPaciente
      (Nombre $?Nombre))
   =>
   (printout t "Posible diagnóstico para el paciente " $?Nombre ": Eccema " crlf))