Ernest,
Thanks for the reply. How does one actually code for what you described using the Java Jess constructs of Deftemplate, Facts and their methods?
I have the following code snippet with which I have not been able to get Jess to populate the multi-slot item.
Deftemplate transHistory_T =
new Deftemplate("transHistory", "Transaction States", engine);
transHistory_T.addSlot("date", Funcall.NIL, "LONG");
transHistory_T.addSlot("state", Funcall.NIL, "STRING");
engine.addDeftemplate(transHistory_T);
Deftemplate myTransaction_T =
new Deftemplate("myTransaction", "My Transaction Record", engine);
myTransaction_T.addSlot("transID", Funcall.NIL, "STRING");
myTransaction_T.addSlot("transDate", Funcall.NIL, "LONG");
myTransaction_T.addSlot("transType", Funcall.NIL, "STRING");
myTransaction_T.addSlot("pAmount", Funcall.NIL, "FLOAT");
myTransaction_T.addMultiSlot("transHistory", Funcall.NILLIST);
.
.
.
etc.
engine.addDeftemplate(myTransaction_T);
.
.
.
Fact myTransaction_F = new Fact("myTransaction", engine);
myTransaction_F.setSlotValue("transID", new Value(myTrans.getTransactionID(), RU.STRING));
long lDate = myTrans.getTransactionDate().getTimeInMillis();
myTransaction_F.setSlotValue("transDate", myEngine.toJessLong(lDate));
myTransaction_F.setSlotValue("transType", new Value(myTrans.getTransactionType(), RU.STRING));
double pAmount = myTrans.getProcurementAmount().doubleValue();
myTransaction_F.setSlotValue("pAmount", myEngine.toJessFloat(pAmount));
myTransaction_F.setSlotValue("transHistory", ???);
.
.
.
engine.assertFact(myTransaction_F);
Question:
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.
So, for example