【问题标题】:asserting string in clips在剪辑中断言字符串
【发布时间】:2020-07-27 04:18:46
【问题描述】:

我正在尝试将 name 的值声明到变量中,但是当我声明它时,值会出现在引号中,并且末尾还有一个额外的空格。

   (defrule discount_amt_group 
    (exists (Student (age 14)(marks ?q&:(> ?q 40))))
    =>
    (bind ?name "")
    (do-for-all-facts ((?p Student))
                  (or (eq ?p:marks 80)
                     (eq ?p:marks 75)
                     (eq ?p:marks 90))
    (bind ?name (str-cat ?name ?p:name " "))
    (bind ?totalMarks (+ ?totalMarks ?p:marks)))
    (assert (StudOut(names ?name)))

预期值将是(名称 Harry Ron Ginger),但现在它变为(名称“Harry Ron Ginger”) 请提出建议。

【问题讨论】:

    标签: rules rule-engine clips


    【解决方案1】:

    将名称表示为多字段值而不是字符串。您可以使用 create$ 函数最初创建一个空的多字段值,然后再次对其附加值。

             CLIPS (6.31 6/12/19)
    CLIPS> 
    (deftemplate Student
       (slot name)
       (slot age)
       (slot marks))
    CLIPS>    
    (deftemplate StudOut
       (multislot names)
       (slot totalMarks))
    CLIPS>    
    (deffacts Students
       (Student (name Harry) (age 14) (marks 80))
       (Student (name Ron) (age 15) (marks 75))
       (Student (name Ginger) (age 14) (marks 90))
       (Student (name Sally) (age 12) (marks 95)))
    CLIPS>    
    (defrule discount_amt_group 
       (exists (Student (age 14)(marks ?q&:(> ?q 40))))
       =>
       (bind ?name (create$))
       (bind ?totalMarks 0)
       (do-for-all-facts ((?p Student))
                         (or (eq ?p:marks 80)
                             (eq ?p:marks 75)
                             (eq ?p:marks 90))
          (bind ?name (create$ ?name ?p:name))
          (bind ?totalMarks (+ ?totalMarks ?p:marks)))
       (assert (StudOut (names ?name)
                        (totalMarks ?totalMarks))))
    CLIPS> (reset)
    CLIPS> (run)
    CLIPS> (facts)
    f-0     (initial-fact)
    f-1     (Student (name Harry) (age 14) (marks 80))
    f-2     (Student (name Ron) (age 15) (marks 75))
    f-3     (Student (name Ginger) (age 14) (marks 90))
    f-4     (Student (name Sally) (age 12) (marks 95))
    f-5     (StudOut (names Harry Ron Ginger) (totalMarks 245))
    For a total of 6 facts.
    CLIPS> 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-17
      • 2019-07-30
      • 1970-01-01
      • 1970-01-01
      • 2016-11-05
      • 1970-01-01
      相关资源
      最近更新 更多