Hi,
I encountered a problem when using my own Java functions in Jess
5.1. Basically, my program has its own agenda of Jess facts and
asserts them to the Jess KB step by step. Some of these facts are
clones of other existing facts.
The problem now is that my Java function mc-top sometimes cannot find
facts by id although exactly these facts have been matched on a rule
lhs. For example
(defrule rule
?sig <- (sign ...)
=>
(mc-top ?sig ...))
This happens very rarely. In most cases everything works fine so that
I cannot make any sense out of it. When a fact has already matched on
a rule lhs, how can it be possible that that very fact cannot be
located by its id? It may be related to the cloning of Jess facts, but
on the other hand these clones are added to the Jess KB by a normal
assert.
Anyway, since fact-ids will disappear in Jess 6x there hope. But where
should I look at in Jess 5.1?
Many thanks for any help
-- Sebastian
* ================================ *
* Sebastian Varges
* Language Technology Group & ICCS
* Division of Informatics
* University of Edinburgh
* Scotland, UK
* ================================ *
-----
This is the mc-top function which is a modification of the Jess modify-code:
public class ModifyCopyTop implements Userfunction, Serializable
{
public String getName() { return "mc-top"; }
public Value call(ValueVector vv, Context context) throws JessException
{
Rete engine = context.getEngine();
Fact fact;
int factId = vv.get(1).factIDValue(context);
if ((fact = engine.findFactByID(factId)) == null) // THIS IS WHERE IT GOES
WRONG ALREADY
throw new JessException("mc-top", "mc-top: no such fact",
String.valueOf(factId));
Deftemplate dt = fact.getDeftemplate();
// Making a clone of the existing fact
Fact fact1 = (Fact) fact.clone();
for (int i= 2; i < vv.size(); i++)
{
// fetch the slot, value subexp, stored as a List
ValueVector svp = vv.get(i).listValue(context);
String slotName = getSlotName(svp, context);
int idx = dt.getSlotIndex(slotName);
int type = dt.getSlotType(idx);
// Set the value in the fact
fact1.setSlotValue(slotName, getSlotValue(svp, context, type));
}
// and store new fact as single "top"-fact (without actually asserting to KB)
// Another function takes the stored fact later and asserts it to KB
engine.store("top",fact1);
return Funcall.TRUE;
}
}
---------------------------------------------------------------------
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]
---------------------------------------------------------------------