Felix,

The error is happening during pattern-matching, which is driven by
working memory changes (i.e., all matching involving a given fact
happens whenever that fact is asserted, retracted, or modified.)

The problems are happening during calls to fact-slot-value. It's easy
enough to fix this: don't do that, ever. There is never a reason to
call fact-slot-value on the left hand side of a rule -- you've already
got ahold of a fact (or if you don't, you can get it) and so you can
match the slots directly. Your problem is that you're calling fact-id
to get ahold of some nonexistent fact, then passing that nonexistent
fact's id (-1) to fact-slot-value, which is reporting that, indeed,
there's no such fact.

As an aside, the fact-id function is virtually never needed: it turns
a real integer into a Fact by doing a slow lookup. It's useful when
debugging from the command line, but there's never a need to use it
during normal Jess coding (although you might use it to restore links
when loading interconnected facts in from a flat file of some kind.)
If you're actually got a number and need a jess.Fact object, then use
it. But if you're got a fact binding, then it's already a jess.Fact
object.

I untangled your code extract into this, which *really* doesn't belong
on the LHS of a rule. Apparently this is part of a deffunction that
you're calling from a test CE -- i.e., from the LHS of a rule.

(if (or (eq (fact-slot-value (fact-id ?fact) template) imple-method)
        (eq (fact-slot-value (fact-id ?fact) template) global-method))
 then
    (return ?fact)
 else 
    (if (eq (fact-slot-value (fact-id ?fact) template) class)
     then (return "-1")
 else
    (bind ?p-id (fact-slot-value (fact-id ?fact) parent-id))
    (get-method-id ?p-id)))

Now, you *could* simply add some "guard clauses." Just as in Java
code, you'd check things for null before using them, here you need to
check that ?fact isn't "-1" before continuing with this routine. But
the right thing to do is to break this all up and do it as pattern
matching instead. It would not only be vastly simpler, but it'd
probably be vastly more efficient, too.

I can't tell you exactly what to do, because you really need to
rethink the fundamental design. You've got this whole system designed
in a procedural way. Instead of using if-then logic on the LHS of a
rule, you instead what to write multiple rules, one for each case you
need to handle.

Something like

  (if (or (eq (fact-slot-value (fact-id ?fact) template) imple-method)
          (eq (fact-slot-value (fact-id ?fact) template) global-method))

could instead be written as something like

  (call-method (template imple-method | global-method))

if you followed my advice.

I think =?iso-8859-1?Q?F=E9lix_G=F3mez_Cordero?= wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
> Hi Jason,
> 
> thanks for your answer, one of errors I get is throwed when I try to assert 
> the next fact: (MAIN::call-method (id "13") (template call-method) 
> (parent-method-id "9") (parent-id "12") (params "10")). 
> 
> Error Message is: 
> Jess reported an error in routine factid
> 
> while executing (fact-id ?fact)
> 
> while executing deffunction fact-slot-value
> 
> while executing (fact-slot-value (fact-id ?fact) template)
> 
> while executing (eq (fact-slot-value (fact-id ?fact) template) imple-method)
> 
> while executing (or (eq (fact-slot-value (fact-id ?fact) template) 
> imple-method) (eq (fact-slot-value (fact-id ?fact) template) global-method))
> 
> while executing (if (or (eq (fact-slot-value (fact-id ?fact) template) 
> imple-method) (eq (fact-slot-value (fact-id ?fact) template) global-method)) 
> then (return ?fact) else (if (eq (fact-slot-value (fact-id ?fact) template) 
> class) then (return "-1") else (bind ?p-id (fact-slot-value (fact-id ?fact) 
> parent-id)) (get-method-id ?p-id)))
> 
> while executing deffunction get-method-id
> 
> while executing (get-method-id ?p-id)
> 
> while executing (if (eq (fact-slot-value (fact-id ?fact) template) class) 
> then (return "-1") else (bind ?p-id (fact-slot-value (fact-id ?fact) 
> parent-id)) (get-method-id ?p-id))
> 
> while executing (if (or (eq (fact-slot-value (fact-id ?fact) template) 
> imple-method) (eq (fact-slot-value (fact-id ?fact) template) global-method)) 
> then (return ?fact) else (if (eq (fact-slot-value (fact-id ?fact) template) 
> class) then (return "-1") else (bind ?p-id (fact-slot-value (fact-id ?fact) 
> parent-id)) (get-method-id ?p-id)))
> 
> while executing deffunction get-method-id
> 
> while executing (get-method-id ?parent-id)
> 
> while executing (str-compare (get-method-id ?parent-id) (get-method-id 
> ?param-id))
> 
> while executing (= (str-compare (get-method-id ?parent-id) (get-method-id 
> ?param-id)) 0)
> 
> while executing 'test' CE
> 
> // The above functions are part of my rules, but the engine should not be 
> running.... 
> 
> while executing rule LHS (Node2)
> 
> while executing rule LHS (MTELN)
> 
> while executing rule LHS (TECT).
> 
> Message: No such fact-id: -1.
> 
> at jess.MakeFactID.call(MiscFunctions.java:817)
> 
> at jess.FunctionHolder.call(FunctionHolder.java:30)
> 
> at jess.Funcall.execute(Funcall.java:266)
> 
> at jess.FuncallValue.resolveValue(FuncallValue.java:33)
> 
> at jess.Deffunction.call(Deffunction.java:164)
> 
> at jess.FunctionHolder.call(FunctionHolder.java:30)
> 
> at jess.Funcall.execute(Funcall.java:266)
> 
> at jess.FuncallValue.resolveValue(FuncallValue.java:33)
> 
> at jess.Eq.call(Funcall.java:1072)
> 
> .........
> 
> on the follow engine status:
> 
> ID: 0 (MAIN::initial-fact)
> 
> ID: 1 (MAIN::default-type (id "1") (template default-type) (parent-id "-2") 
> (name "E"))
> 
> ID: 2 (MAIN::default-type (id "2") (template default-type) (parent-id "-2") 
> (name "R"))
> 
> ID: 3 (MAIN::default-type (id "3") (template default-type) (parent-id "-2") 
> (name "N"))
> 
> ID: 4 (MAIN::default-type (id "4") (template default-type) (parent-id "-2") 
> (name "Cadena"))
> 
> ID: 5 (MAIN::default-type (id "5") (template default-type) (parent-id "-2") 
> (name "Objeto"))
> 
> ID: 6 (MAIN::global-method (id "6") (parent-id "-1") (template global-method) 
> (name "imprimir") (returned-type "-1") (params "7"))
> 
> ID: 7 (MAIN::parameter (id "7") (template parameter) (parent-id "6") (name 
> "cadena") (type "4") (value nil))
> 
> ID: 8 (MAIN::class (id "8") (template class) (name "Clase") 
> (implementation-method "9") (field "11"))
> 
> ID: 9 (MAIN::imple-method (id "9") (template imple-method) (method "-1") 
> (name "metodo") (parent-id "8") (returned-type "1") (params "10") (body ))
> 
> ID: 10 (MAIN::parameter (id "10") (template parameter) (parent-id "9") (name 
> "param") (type "1") (value nil))
> 
> ID: 11 (MAIN::imple-field (id "11") (template imple-field) (name "field") 
> (parent-id "8") (type "1") (value nil))
> 
> 
> I get similar errors messages sometimes (these errors are not shown always) 
> when I modify facts. I modify and add facs from the next java methods:
> 
> // To assert facts
> public static void assertFact(Fact f){
>   try {
>      
>    // This call is not outstanding
>    f.setSlotValue("id",new 
> Value(FactIdProvider.INSTANCE.getNewFactId(),RU.STRING));
>    
>    
>      engine.assertFact(f);
>    
>      facts.addFact(f);
>    
>   } catch (JessException e) {
>    
>    System.err.println(
>     "Se produjo un error afirmando el hecho: "
>      + f.toString());
>    e.printStackTrace();
>   }
>  }
> 
> // To modify slot values
> public static void setSlotValue(
>   int factId,
>   String slotName,
>   String slotValue) {
>   try {
>    // Si esta vacio se establece a 'espacio en blanco'
>    if (slotValue.equals("")){
>     slotValue = " ";
>     
>    }
> 
>    // Se ejecuta la sentencia
>    engine.executeCommand(
>        "(modify " + factId + " (" + slotName + " " + slotValue + "))"); 
>    
>   
>   } catch (JessException e) {
>    System.err.println(
>     "FactID como int: Se ha producido un error estableciendo el valor del 
> slot "
>      + slotName
>      + " del hecho con id "
>      + factId
>      + " al valor "
>      + slotValue);
>    e.printStackTrace();
>   }
>  }
> 
> 
> I hope this source code to help you to understand what I'm trying to do, 
> thanks againg,
> 
>                                                                               
>               Felix.
> 
> 
> 
>   ----- Original Message ----- 
>   From: Jason Morris 
>   To: jess-users@sandia.gov 
>   Sent: Saturday, August 27, 2005 8:21 AM
>   Subject: Re: JESS: How to stop firing rules (again)
> 
> 
> 
> 
> 
>   On 8/26/05, F_lix G_mez Cordero <[EMAIL PROTECTED]> wrote: 
>     Hi all,
> 
>     I posted the same question some weeks ago. I thought at that time that my 
> problem was fixed... but it seems now that I was wrong! So I will explain it 
> again...
> 
> 
>   Hi Flelix,
> 
>   An ounce of source code is worth a pound of explanation.  :-D
>   Please post your actual code, and I bet the group can help you much faster.
> 
>   Cheers,
>   Jason Morris
>   Co-Moderator Jess Listserver
> 
>    
>   -----------------------------------------------------
>   Morris Technical Solutions LLC
>   www.morristechnicalsolutions.com 
>   [EMAIL PROTECTED]
>   phone/fax: 503.692.1088 



---------------------------------------------------------
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]
--------------------------------------------------------------------

Reply via email to