我使用firts time clips在剪辑中创建基于规则的指导原则。
(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的关联联接中
我不知道我做错了什么,谁能救我。
发布于 2021-05-20 01:50:17
您所断言的事实没有为life_expectancy指定一个值,因此使用默认值nil:
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不是一个数字,因此会生成一个错误。
(test (<= ?life_expectancy 11))您需要在断言事实时提供一个数字值;在其deftemplate中为槽指定一个数字默认值;或者修改您的规则以使用numberp/integerp函数测试该值是否为数字/整数,以便如果该值不是数字,则不会调用<=函数。
https://stackoverflow.com/questions/67603379
复制相似问题