joyling
joyling

Reputation: 3

CLIPS find-all-facts return value

I tried this by adapting from the WineDemo.clp example with CLIPSJNI.

(defmodule SEVERITY (import MAIN ?ALL)
                (export deffunction get-dengue-list))

(deffacts any-attributes
          (attribute (name clinical-prediction) (value any))
          (attribute (name lab-prediction) (value any)))

(deftemplate SEVERITY::dengue
      (slot name (default ?NONE))
      (multislot clinical (default any))
      (multislot lab (default any)))

(deffacts SEVERITY::the-dengue-list
     (dengue (name "DF") (clinical dengue-f) (lab positive))
     (dengue (name "DHF") (clinical dengue-hf) (lab positive))
     (dengue (name "DSS") (clinical dengue-ss) (lab positive)))

(defrule SEVERITY::generate-severity
   (dengue (name ?name)
      (clinical $? ?c $?)
      (lab $? ?l $?))
   (attribute (name clinical-prediction) (value ?c) (certainty ?certainty-1))
   (attribute (name lab-prediction) (value ?l) (certainty ?certainty-2))
     =>
    (assert (attribute (name dengue) (value ?name)
                 (certainty (min ?certainty-1 ?certainty-2)))))

(deffunction SEVERITY::dengue-sort (?w1 ?w2)
   (< (fact-slot-value ?w1 certainty)
      (fact-slot-value ?w2 certainty)))

(deffunction SEVERITY::get-dengue-list ()
  (bind ?facts (find-all-facts ((?f attribute))
                           (and (eq ?f:name dengue) (>= ?f:certainty 20))))
  (sort dengue-sort ?facts))

However, I am not able to return any facts when I try to print it out in Java as below.

String evalStr = "(SEVERITY::get-dengue-list)";
MultifieldValue pv = (MultifieldValue)clips.eval(evalStr);
System.out.println(pv);

The list I got when I use this:

(find-all-facts ((?f attribute)) TRUE)

I can't seem to get just the details from the-dengue-list. I don't want all the attributes to be displayed. I'm still quite new to this and I'm stuck. Can anyone please help me?

Thanks!

Upvotes: 0

Views: 2175

Answers (1)

Gary Riley
Gary Riley

Reputation: 10757

The generate-severity rule never executes, so an attribute fact with name dengue is never generated and the get-dengue-list function will return an empty list. In order for the rule to execute there must be clinical-prediction and lab-prediction attributes that match the lab and clinical slot values from the dengue fact. The lab value of 'positive' does not match the clinical-prediction value of 'any'. The clinical values of 'dengue-f', 'dengue-hf', and 'dengue-ss' do not match the lab-prediction value of 'any'.

If you want the symbol 'any' to have special significance when matching, you need to adjust the constraints you're using in your pattern. For example:

   (attribute (name clinical-prediction) (value ?c | any) (certainty ?certainty-1))
   (attribute (name lab-prediction) (value ?l | any) (certainty ?certainty-2))

The other issue you may encounter is that the query you're using will only return dengue attribute facts with a certainty of at least 20.

Upvotes: 1

Related Questions