question about jess templates

Would welcome suggestions on how to represent a complex data structure with Deftemplates if one is working with a data record structure made up of single-occurring data elements combined with repeating sub-structures. It seems to me that multi-slots are insufficient as the sub-structures are not simple lists, unless one can create lists in Jess whose members have their own Deftemplates (?).

The task I am trying to accomplish is to represent an hierarchical xml document or document segments containing repeating complex elements as Jess facts.

A Jess template is just like a Java class: it has a set of members (slots), some of which may be arrays (multislots). The individual members of a Java class can hold instances of other classes; the same is true for templates.

How to populate the "transHistory" multi-slot with values obtained from "tHist" objects given that one has a variable number of java objects of type "tHist" and "tHist" has these instance methods: tHist.getDate().getTimeInMillis() (long) and tHist.getState() (String)

It's as if we changed your person example from (slot address) to (multislot address) and tried to populate address using a list of addressObj[i] java objects.

Originally posted by Ernest Friedman-Hill: Hi,

Welcome to JavaRanch!

A Jess template is just like a Java class: it has a set of members (slots), some of which may be arrays (multislots). The individual members of a Java class can hold instances of other classes; the same is true for templates.

If you leave out the (actually not useful) slot types, it's even smaller; and if you put the Jess code in a separate file and execute it with "batch", it looks even neater (and then you can use the Eclipse-based Jess IDE to write the code.) I don't know why some people try so hard to do everything with the Java API when using the Jess language itself is so much easier.

Secondly, it looks like you're doing some tedious things by hand that Jess can do automatically. In particular, Jess can build templates from your Java classes using the "defclass" function (or the "from-class" declaration in Jess 7). One nice feature of this is that if your classes add, remove, or change properties, the Jess templates are updated automatically.

Thirdly, and finally before we get to the answer, this problem has been solved many times. Here is an especially elegant solution using Jess's backward chaining facility along with defclass to do pretty much all of what you're doing here automatically, without writing Java code.

But in any case, the slot value for a multislot is a Jess list -- an instance of the jess.ValueVector class. You can wrap a jess.Value directly around a Fact object, and then put that into the ValueVector. So what you'd do, if you're doing this from the Java API, would be to