【问题标题】:How can I use deftemplate to store results in CLIPS?如何使用 deftemplate 将结果存储在 CLIPS 中?
【发布时间】:2012-03-16 11:48:20
【问题描述】:

我试图构建一个模板来存储我计算的一些结果,所以我做了这个用于初始化:

(deftemplate tempAlumne
    (slot nota-media-total)
    (slot nota-media-obligatorias)
    (slot nota-media-optativas)
    (slot nota-media-ales)
)

(deffacts tempAlumneFacts
    (tempAlumne 
        (nota-media-total -1)
        (nota-media-obligatorias -1)
        (nota-media-optativas -1)
        (nota-media-ales -1)
    )
)

然后我尝试使用该结构来存储值,但我需要它可以从许多规则中访问,因此我决定将其设为全局。所以我尝试存储这样的值:

(defrule calcula-nota-media ""
    (not calcula-nota-media ok)
    ?*tmpA* <- (tempAlumne )

    =>
    (bind ?llista_convocs (send ?*alumne* get-IConvocatoria))
    (bind ?suma 0)
    (bind ?i 0) 
    (while(< ?i (length$ ?llista_convocs)) do
        (bind ?convoc_actual (nth$ ?i ?llista_convocs))
        (bind ?suma (+ ?suma (send ?convoc_actual get-Nota)))
        (bind ?i (+ ?i 1))
    )   
    (/ )    
    (modify (?*tmpA* (nota-media-total (/ ?suma ?i))
    (assert calcula-nota-media ok)
)

因为我希望 ?*tmpA* 具有初始值,然后为每个值分配 modify(这里我分配 nota-media-total),但它显示“[PRNTUTIL2] 语法错误:检查 defrule 的适当语法。” ,所以我不知道哪里出了问题,或者我是否走错了路。

【问题讨论】:

    标签: artificial-intelligence clips


    【解决方案1】:

    通读用户指南会很有帮助,因为它涵盖了基本语法。我已经更正了你的一些错误:

    (defrule calcula-nota-media ""
        (not (calcula-nota-media ok))
        ?tmpA <- (tempAlumne)
        =>
        (bind ?llista_convocs (send ?*alumne* get-IConvocatoria))
        (bind ?suma 0)
        (bind ?i 0) 
        (while(< ?i (length$ ?llista_convocs)) do
            (bind ?convoc_actual (nth$ ?i ?llista_convocs))
            (bind ?suma (+ ?suma (send ?convoc_actual get-Nota)))
            (bind ?i (+ ?i 1))
        )   
        ; (/ )  What's this for?  
        (modify ?tmpA (nota-media-total (/ ?suma ?i)))
        (assert (calcula-nota-media ok))
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-17
      • 1970-01-01
      • 2021-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-01
      相关资源
      最近更新 更多