Well, you could certainly patch up the cloned facts from your Java
code. Where you're current calling clone(), call your own
cloneFact(fact, Map) routine which looks something like this (messy
pseudocode, but you get the idea -- WARNING, this won't properly
handle a fact which points to itself from one of its slots!)

Fact cloneFact(Fact fact, Map map) {
  fact = fact.clone();
  Integer i = new Integer(fact.getFactId());
  if (map.get(i) == null)
    map.put(i, fact);

  for each slot "i" in fact {
    Value v = fact.getSlotValue(i);
    if (v.type() == RU.FACT_ID) {
      Fact slotFact = v.factValue();
      Integer i2 = new Integer(slotFact.getFactId());
      if (map.get(i2) == null)
        map.put(i2, cloneFact(slotFact, map));

      fact.setSlotValue(i, new Value(map.get(i2)));
    }
  }
  return fact;
}


I think =?iso-8859-1?q?Moderator?= wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
> Hi,
> 
> So essentially the solution is to use either a name
> slot or an id slot and use it to store in other facts.
> 
> This was a dummy test example. I am using a more
> complicated rule set wherein i dont have numeric ids
> or names for all the facts. Hence the only option is
> to use the fact-id's for joining.
> 
> thanks,
> 
> 
> 
> 
>  --- [EMAIL PROTECTED] wrote: > 
> > This was an interesting one. OK, here's the deal.
> > 
> > 1) You create a bunch of facts. In particular,
> > there's a "class" fact
> > whose "course-id" slot contains a reference to a
> > "course" fact whose
> > "title" slot is "History". This is an actual Java
> > reference to the
> > "course" jess.Fact object.
> > 
> > 2) You clone all the facts, and store the clones in
> > an array
> > list. Here's where things start to go wrong: the
> > cloned "class" fact's
> > course-id slot still contains a reference to the
> > *non-cloned* course fact.
> > 
> > 3) You reset the engine and assert the cloned facts.
> > Now there's a
> > slot in a class fact containing a reference to a
> > course fact that
> > isn't in working memory.
> > 
> > 4) When Jess does the pattern matching for
> > 
> > 
> >    (defrule change-professor
> >         (class (course-id ?course1))
> >         ?course1 <- (course (title "History"))
> > 
> > Jess binds the ?course1 variable to the slot
> > contents, which is a
> > reference to the old fact. Then it checks if the
> > "course" fact in
> > working memory is "equal" to this one. In this
> > context, the equality
> > check is just a comparison to see that the numeric
> > fact-id's are the
> > same -- under normal circumstances, this suffices.
> > Jess actually can't
> > use an identity test (for reasons that I won't go
> > into now) so this is
> > unlikely to change. Anyway, this test passes, even
> > though the two
> > variables refer to different fact objects, because
> > they have the same
> > ID, and normally two facts in working memory can't
> > have the same ID,
> > so these look like the same fact.
> > 
> > 5) Then when the RHS of this rule tries to modify
> > ?course1, you get an
> > exception because, essentially, you're passing a
> > Fact to (modify)
> > which is not in working memory.
> > 
> > So, what should you do? Well, if "course" had an
> > "ID" slot that held a
> > numeric ID for a course, then you could put that
> > into the course-id
> > slot of class and your general scheme would then
> > work fine. Just do
> > the joining using the id slot rather than the
> > fact-id of the course.
> > 
> > 
> > 
> > 
> > I think =?iso-8859-1?q?Moderator?= wrote:
> > [Charset iso-8859-1 unsupported, filtering to
> > ASCII...]
> > > Hi,
> > > 
> > > i want to store the facts from the rete engine,
> > fire
> > > the rule and load back the previous facts and fire
> > the
> > > rule again.
> > > heres a briefing of what i am doing
> > > 
> > > 1. clone each fact and store it in the arraylist
> > > 2. fire the rule. 
> > > 3. Assert the fact one by one from the arraylist
> > using
> > > rete.assertFact(fact) method.
> > > 4. fire the rule.
> > > 
> > > The rule is very simple: it modifies a slot of one
> > of
> > > the facts. First time the rule fires properly
> > without
> > > any errors. How ever when the rule fires second
> > time
> > > following exception is thrown.
> > > 
> > > Jess reported an error in routine Funcall.execute
> > >   while executing (modify ?course1 (professor ABC))
> > >   while executing defrule MAIN::change-professor.
> > >   Message: Error during execution.
> > >   at jess.Funcall.execute(Funcall.java:273)
> > >   at jess.Defrule.fire(Defrule.java:215)
> > >   at jess.Activation.fire(Activation.java:84)
> > >   at jess.Agenda.run(Agenda.java:203)
> > >   at jess.Agenda.run(Agenda.java:183)
> > >   at jess.Rete.run(Rete.java:1097)
> > >   at Test.main(Test.java:32)
> > > Caused by: java.lang.NullPointerException
> > >   at jess.FactList.assignTime(FactList.java:40)
> > >   at jess.Rete.processToken(Rete.java:952)
> > >   at jess.FactList.finishModify(FactList.java:347)
> > >   at
> > jess.FactList.modifyRegularFact(FactList.java:382)
> > >   at jess.FactList._modify(FactList.java:303)
> > >   at jess.Rete._modify(Rete.java:433)
> > >   at jess.Modify.call(Funcall.java:971)
> > >   at
> > jess.FunctionHolder.call(FunctionHolder.java:30)
> > >   at jess.Funcall.execute(Funcall.java:266)
> > >   ... 6 more
> > > 
> > > I am attaching the .clp file and also the .java
> > file
> > > herewith.
> > > I  guess the problem is occuring as i am asserting
> > the
> > > facts with the rete.assertFact() method. Hence the
> > > rule is not able to modify the fact slots.
> > > 
> > > How do i put the facts back in the rete engine?
> > > 
> > > thanks in advance,
> > > 
> > > sanket.
> > > 
> > >
> >
> ________________________________________________________________________
> > > Send free SMS using the Yahoo! Messenger. Go to
> > http://in.mobile.yahoo.com/new/pc/
> > Content-Description: Test.java
> > 
> > [Attachment, skipping...]
> > Content-Description: test.clp
> > 
> > [Attachment, skipping...]
> > 
> > 
> > 
> >
> ---------------------------------------------------------
> > Ernest Friedman-Hill  
> > Distributed Systems 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]
> >
> --------------------------------------------------------------------
> >  
> 
> ________________________________________________________________________
> Send free SMS using the Yahoo! Messenger. Go to http://in.mobile.yahoo.com/new/pc/
> 
> --------------------------------------------------------------------
> 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]
> --------------------------------------------------------------------
> 



---------------------------------------------------------
Ernest Friedman-Hill  
Distributed Systems 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]
--------------------------------------------------------------------

Reply via email to