1

I´m using for firts time clips to create a rule based guideline in 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)))

And receiving the error: [ARGACCES5] Function <= expected argument #1 to be of type integer or float

[DRIVE1] This error occurred in the join network The problem resides in associated join Of pattern #1 in rule average-risk-women-over-75

I do not know what I did wrong, can anybody save me.

Gary Riley
  • 10,130
  • 2
  • 19
  • 34

1 Answers1

0

The fact you have asserted does not have a value specified for life_expectancy and so a default value of nil is used:

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>

The rule average-risk-women-over-75 compares this value to a number using the <= function and since nil is not a number an error is generated.

(test (<= ?life_expectancy 11))

You need to either supply a numeric value when you assert the fact; specify a numeric default value for the slot in its deftemplate; or modify your rule to test that the value is a number/integer using the numberp/integerp function so that the <= function is not called if the value is non numeric.

Gary Riley
  • 10,130
  • 2
  • 19
  • 34