A template is in many ways like a class in Java and other languages. Here are a few true and relevant statements about a template:
- It defines a datatype. - It must be defined before it can be used - If it is defined multiple times in a program, those definitions must match exactly. So the exact template that your rules will use must be defined before the rules are defined; that's the problem you're having here. The add() function *will* automatically define a template for you, but in your program, but you need the template earlier than that, before you try to define the rules. So do it explicitly in your rules file: (deftemplate Patient (declare (from-class "edu.utah.cdmcc.entities.Patient"))) or, equivalently (defclass Patient "edu.utah.cdmcc.entities.Patient") Get rid of that unrelated "patient" deftemplate, and use Patient in your rules. I think mdean77 wrote: > I have a Jess file with a simple template for a patient: > (deftemplate patient > "Patient object - has age and weight" > (slot age) > (slot weight) > (slot miscellaneous)) > > and a simple template for a glucose measurement: > (deftemplate currentGlucoseValue > "Glucose level at current timepoint" > (slot measurementTime) > (slot value)) > > and a rule: > (defrule current-glucose-range > "Define current glucose status" > (currentGlucoseValue (value ?value)) > (patient) > => > (if (and (>= ?value ?*lowTargetLimit*) (<= ?value ? > *highTargetLimit*)) > then (assert(currentGlucoseInRange)) > else (if (< ?value ?*lowTargetLimit*) > then (assert(currentGlucoseBelowRange)) > (printout t "The patient is hypoglycemic." crlf) > else (assert(currentGlucoseAboveRange)) > (printout t "The patient is hyperglycemic." crlf) > > ))) > > When I include the following in my file and execute this as a Jess > program, the rule > fires and "The patient is hyperglycemic" is displayed (because the > glucose level is high). > > (assert (patient (age 33) (weight 3))) > (assert (currentGlucoseValue (value 245))) > > But when I have embedded the rule file in Java, eliminating the two > assertions shown above, and > instantiate patient from a Java Bean that is more complicated than > the simple patient template shown > above, the rule current-glucose-range does not activate. The actual > patient object is instantiated with > rete.add(object) and Jess has constructed it thus: > > ==> f-1 (MAIN::Patient (age 36) (birthdate <Java- > Object:java.util.GregorianCalendar>) (birthdateString "December 15, > 1969") (class <Java-Object:java.lang.Class>) (decisions <Java- > Object:org.hibernate.collection.PersistentBag>) (firstName > "HypoButInsulinOn") (gender <Java- > Object:edu.utah.cdmcc.entities.Gender>) (height 72.86) (id 5) > (lastName "Adult") (medRecNum "56-34-56") (miscellaneous nil) (name > "Adult, HypoButInsulinOn") (trialDbCode "ST02CHOM0005") (version 0) > (weight 67.8) (OBJECT <Java-Object:edu.utah.cdmcc.entities.Patient>)) > > In the example rule, I only am asserting that a patient exists at > all, but looking at this shadow fact, it is named for the Java object > class Patient. But the shadow fact is not really identified as a > patient fact, I am guessing. > > I tried changing the Jess file to capitalize Patient, but then I > received a Jess error in routine definstance, stating unknown object > class Patient. > > Any comments will be appreciated. > > - Mike --------------------------------------------------------- Ernest Friedman-Hill Advanced Software Research Phone: (925) 294-2154 Sandia National Labs FAX: (925) 294-2234 PO Box 969, MS 9012 [EMAIL PROTECTED] Livermore, CA 94550 http://herzberg.ca.sandia.gov -------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED] --------------------------------------------------------------------
