首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何解决clips错误来构建规则?

如何解决clips错误来构建规则?
EN

Stack Overflow用户
提问于 2021-05-19 20:34:31
回答 1查看 28关注 0票数 1

我使用firts time clips在剪辑中创建基于规则的指导原则。

代码语言:javascript
复制
(deftemplate personal-data
   (slot name)
   (slot age)
   (slot gender)
   (slot personal_history_breast_cancer)
   (slot previosly_diagnosed_high-risk_breast_lesion)
   (slot genetic_mutation_increase_risk_breast_cancer)
   (slot history_exposure_radiation_chest_childhood)
   (slot life_expectancy)
)

;add the rules

;R1

(defrule average-risk-women-between-40-and-49
   (personal-data (name ?name)
                  (age ?age) 
                  (gender ?gender) 
                  (personal_history_breast_cancer ?personal_history_breast_cancer) 
                  (previosly_diagnosed_high-risk_breast_lesion ?previosly_diagnosed_high-risk_breast_lesion) 
                  (genetic_mutation_increase_risk_breast_cancer ?genetic_mutation_increase_risk_breast_cancer)
                  (history_exposure_radiation_chest_childhood ?history_exposure_radiation_chest_childhood))
   (and (test (>= ?age 40))
        (test (< ?age 49))
        (and (test (eq ?gender female))
        (and (test (eq ?personal_history_breast_cancer no))
        (and (test (eq ?previosly_diagnosed_high-risk_breast_lesion no))
        (and (test (eq ?genetic_mutation_increase_risk_breast_cancer no))
   (and (test (eq ?history_exposure_radiation_chest_childhood no))))))))
   =>
   (printout t ?name " should discuss the benefits and risks of breast cancer screening. [1, p. I‐18]" crlf)
)

;R2

(defrule average-risk-women-between-50-and-74
   (personal-data (name ?name)
                  (age ?age) 
                  (gender ?gender) 
                  (personal_history_breast_cancer ?personal_history_breast_cancer) 
                  (previosly_diagnosed_high-risk_breast_lesion ?previosly_diagnosed_high-risk_breast_lesion) 
                  (genetic_mutation_increase_risk_breast_cancer ?genetic_mutation_increase_risk_breast_cancer)
                  (history_exposure_radiation_chest_childhood ?history_exposure_radiation_chest_childhood))
   (and (test (>= ?age 50))
        (test (< ?age 74))
        (and (test (eq ?gender female))
             (and (test (eq ?personal_history_breast_cancer no))
                  (and (test (eq ?previosly_diagnosed_high-risk_breast_lesion no))
                       (and (test (eq ?genetic_mutation_increase_risk_breast_cancer no))
                            (and (test (eq ?history_exposure_radiation_chest_childhood no))))))))
   =>
   (printout t ?name " should be offered breast cancer screening with a mamogram every 2 years. [1, p. I‐18]" crlf)
)

;R3

(defrule average-risk-women-over-75
   (personal-data (name ?name)
                  (gender ?gender)
                  (age ?age)
                  (personal_history_breast_cancer ?personal_history_breast_cancer)
                  (previosly_diagnosed_high-risk_breast_lesion ?previosly_diagnosed_high-risk_breast_lesion)
                  (genetic_mutation_increase_risk_breast_cancer ?genetic_mutation_increase_risk_breast_cancer)
                  (history_exposure_radiation_chest_childhood ?history_exposure_radiation_chest_childhood)
                  (life_expectancy ?life_expectancy))
   (and (test (eq ?gender female))
        (or (test (>= ?age 75))
            (and (test (eq ?personal_history_breast_cancer no)) 
                 (and (test (eq ?previosly_diagnosed_high-risk_breast_lesion no))
                      (and (test (eq ?genetic_mutation_increase_risk_breast_cancer no)) 
                           (and (test (eq ?history_exposure_radiation_chest_childhood no))
                                (test (<= ?life_expectancy 11))))))))

   => 
   (printout t ?name " should stop screening for breast cancer. [1, p. I‐18]" crlf)
)

; add facts
; Fact1
(assert (personal-data (name "Maria")
                       (age 45)
                       (gender female)
                       (personal_history_breast_cancer no)
                       (previosly_diagnosed_high-risk_breast_lesion no)
                       (genetic_mutation_increase_risk_breast_cancer no)
                       (history_exposure_radiation_chest_childhood no)))

接收到错误: ARGACCES5函数<=参数#1应为整型或浮点型

DRIVE1此错误发生在联接网络中。问题存在于规则average-risk- pattern over-75中模式#1的关联联接中

我不知道我做错了什么,谁能救我。

EN

回答 1

Stack Overflow用户

发布于 2021-05-20 01:50:17

您所断言的事实没有为life_expectancy指定一个值,因此使用默认值nil:

代码语言:javascript
复制
CLIPS> (ppfact 1)
(personal-data 
   (name "Maria") 
   (age 45) 
   (gender female) 
   (personal_history_breast_cancer no) 
   (previosly_diagnosed_high-risk_breast_lesion no) 
   (genetic_mutation_increase_risk_breast_cancer no) 
   (history_exposure_radiation_chest_childhood no) 
   (life_expectancy nil))
CLIPS>

规则average-risk- number over-75使用<=函数将这个值与一个数字进行比较,由于nil不是一个数字,因此会生成一个错误。

代码语言:javascript
复制
(test (<= ?life_expectancy 11))

您需要在断言事实时提供一个数字值;在其deftemplate中为槽指定一个数字默认值;或者修改您的规则以使用numberp/integerp函数测试该值是否为数字/整数,以便如果该值不是数字,则不会调用<=函数。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67603379

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档