JESS: Problem with getslotvalue

View: New views
3 Messages — Rating Filter:   Alert me  

JESS: Problem with getslotvalue

by Steffen Niermann :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Hello,

I have a problem with getting the slot value from a jess file with java.

 

When fired, the two rules in the Jess code change the fact “Verzug in the values “5” and “2” in the slots “v1” and “v2” .

In the Java Code I want to get these slot values and print them out.

In the console there will be printed the initial values “0”, “0”, which have been defined in the Java Code.

Has anybody an idea, why the changes in the facts, which will be printed in the console, will not take effect on the getSlotValue fuction?

 

Thank you very much for your answers.

With best regards

Steffen Niermann

 

Here is the Java Code:

 

Combobox cb1 = (Combobox)getFellow("cb1");

            Combobox cb2 = (Combobox)getFellow("cb2");

            Combobox cb3 = (Combobox)getFellow("cb3");

           

            System.out.println("Hello from JAVA!");

            String buf;

            Rete engine = new Rete();

            engine.batch("facts.clp");

            engine.reset();

            buf = "(facts)";

            engine.eval(buf);

            /*see facts with new asserted fact*/

            buf = "(facts)";

            engine.eval(buf);

            /* define new fact (template using API*/

            Fact f = new Fact("Werkstueck", engine);

            f.setSlotValue("Name", new Value(cb1.getSelectedItem().getLabel(), RU.STRING));

           

            f.setSlotValue("Einspannungsart", new Value(cb3.getSelectedItem().getLabel(), RU.STRING));

     

            f.setSlotValue("Hauptprozess", new Value(cb2.getSelectedItem().getLabel(), RU.STRING));

           

            engine.assertFact(f);

            Fact v = new Fact("Verzug", engine);

           

            v.setSlotValue("v2", new Value(0, RU.INTEGER));

            engine.assertFact(v);

            /*see facts with new asserted fact*/

            buf = "(facts)";

           

 

            engine.eval(buf);

            engine.run();

 

            engine.eval(buf);

 

Value speicher = v.getSlotValue("v1");

            Value speicher2 = v.getSlotValue("v2");

            System.out.println(speicher);

            System.out.println(speicher2);

 

 

And here is the facts.clp with the Jess Code.

 

(printout t "Hello from Jess!" crlf)

 

(deftemplate Verzug (declare (slot-specific TRUE))

    (slot v1)

    (slot v2)

    )

 

(deftemplate Werkstueck ;Werkstueck, hier wird die Auswahl abgespeichert

(slot Einspannungsart)

(slot Hauptprozess)

(slot Name))

 

 

(deftemplate noloops

    (slot einspannennl)

    )

   

(deffacts initialFacts

    ;(Verzug (v1 1) (v2 2))

    (noloops (einspannennl 0)))

 

(defrule einspannen

    ;(declare (no-loop TRUE))

    (Werkstueck (Einspannungsart "Segmentbackenabdruck"))

    ?r1 <- (noloops (einspannennl 0))

    ?r2 <- (Verzug (v1 ?v1) (v2 ?v2))

    =>

    (retract ?r1)

    (assert (noloops (einspannennl 2)))

    (assert (Verzug (v1 (+ ?v1 2)) (v2 ?v2)))

    (retract ?r2)

    )

 

(defrule einspannen1

    ;(declare (no-loop TRUE))

    (Werkstueck (Hauptprozess "prozess1"))

    ?r1 <- (noloops (einspannennl 2))

    ?r2 <- (Verzug (v1 ?v1) (v2 ?v2))

    =>

    (retract ?r1)

    (assert (noloops (einspannennl 3)))

    (assert (Verzug (v1 (+ ?v1 3)) (v2 2)))

    (retract ?r2)

    )

 

And here is the text in the Eclipse-Console:

 

Hello from JAVA!

Hello from Jess!

f-0   (MAIN::initial-fact)

f-1   (MAIN::noloops (einspannennl 0))

For a total of 2 facts in module MAIN.

f-0   (MAIN::initial-fact)

f-1   (MAIN::noloops (einspannennl 0))

For a total of 2 facts in module MAIN.

f-0   (MAIN::initial-fact)

f-1   (MAIN::noloops (einspannennl 0))

f-2   (MAIN::Werkstueck (Einspannungsart "Segmentbackenabdruck") (Hauptprozess "prozess1") (Name "Ring_10"))

f-3   (MAIN::Verzug (v1 0) (v2 0))

For a total of 4 facts in module MAIN.

f-0   (MAIN::initial-fact)

f-2   (MAIN::Werkstueck (Einspannungsart "Segmentbackenabdruck") (Hauptprozess "prozess1") (Name "Ring_10"))

f-6   (MAIN::noloops (einspannennl 3))

f-7   (MAIN::Verzug (v1 5) (v2 2))

For a total of 4 facts in module MAIN.

0

0



BIBA - Bremer Institut fuer Produktion und Logistik GmbH
Postanschrift: Postfach P.O.B. 33 05 60, D-28335 Bremen / Germany
Geschaeftssitz: Hochschulring 20, D-28359 Bremen / Germany
USt-ID: DE814890109, Amtsgericht Bremen HRB 24505 HB
Tel: +49(0)421/218-5576, Fax: +49(0)421/218-5640
E-Mail: info@..., Internet: www.biba.uni-bremen.de
Geschaeftsfuehrer: Prof. Dr.-Ing. Bernd Scholz-Reiter



Re: JESS: Problem with getslotvalue

by Ernest Friedman-Hill :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Oct 5, 2009, at 10:42 AM, Steffen Niermann wrote:

> Has anybody an idea, why the changes in the facts, which will be  
> printed in the console, will not take effect on the getSlotValue  
> fuction?
>  ....

I'm not quite sure why you think the changes *would* be visible  
through the variable "v" in your Java code. Your rules *don't* modify  
the Verzug fact -- they retract it (i.e., delete it) after asserting a  
completely separate one. The changes aren't reflected in the fact  
pointed to by "v" because that fact isn't even in working memory.

> (defrule einspannen
>     ;(declare (no-loop TRUE))
>     (Werkstueck (Einspannungsart "Segmentbackenabdruck"))
>     ?r1 <- (noloops (einspannennl 0))
>     ?r2 <- (Verzug (v1 ?v1) (v2 ?v2))
>     =>
>     (retract ?r1)
>     (assert (noloops (einspannennl 2)))
>     (assert (Verzug (v1 (+ ?v1 2)) (v2 ?v2)))
>     (retract ?r2)
>     )


If you were to actually modify the existing fact, e.g.,

=>
     (assert (noloops (einspannennl 2)))
     (modify ?r1 (v1 (+ ?v1 2)) (v2 ?v2))

then of course you'd see the changes in that variable.




---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences          Phone: (925) 294-2154
Sandia National Labs
PO Box 969, MS 9012                            ejfried@...
Livermore, CA 94550                             http://www.jessrules.com





--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------


AW: JESS: Problem with getslotvalue

by Steffen Niermann :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thank you very much for your quick answer.
The problem is solved

-----Ursprüngliche Nachricht-----
Von: owner-jess-users@... [mailto:owner-jess-users@...] Im Auftrag von Ernest Friedman-Hill
Gesendet: Montag, 5. Oktober 2009 17:02
An: jess-users
Betreff: Re: JESS: Problem with getslotvalue


On Oct 5, 2009, at 10:42 AM, Steffen Niermann wrote:

> Has anybody an idea, why the changes in the facts, which will be  
> printed in the console, will not take effect on the getSlotValue  
> fuction?
>  ....

I'm not quite sure why you think the changes *would* be visible  
through the variable "v" in your Java code. Your rules *don't* modify  
the Verzug fact -- they retract it (i.e., delete it) after asserting a  
completely separate one. The changes aren't reflected in the fact  
pointed to by "v" because that fact isn't even in working memory.

> (defrule einspannen
>     ;(declare (no-loop TRUE))
>     (Werkstueck (Einspannungsart "Segmentbackenabdruck"))
>     ?r1 <- (noloops (einspannennl 0))
>     ?r2 <- (Verzug (v1 ?v1) (v2 ?v2))
>     =>
>     (retract ?r1)
>     (assert (noloops (einspannennl 2)))
>     (assert (Verzug (v1 (+ ?v1 2)) (v2 ?v2)))
>     (retract ?r2)
>     )


If you were to actually modify the existing fact, e.g.,

=>
     (assert (noloops (einspannennl 2)))
     (modify ?r1 (v1 (+ ?v1 2)) (v2 ?v2))

then of course you'd see the changes in that variable.




---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences          Phone: (925) 294-2154
Sandia National Labs
PO Box 969, MS 9012                            ejfried@...
Livermore, CA 94550                             http://www.jessrules.com





--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------


------------------------------------------------------------------------
BIBA - Bremer Institut fuer Produktion und Logistik GmbH
Postanschrift: Postfach P.O.B. 33 05 60, D-28335 Bremen / Germany
Geschaeftssitz: Hochschulring 20, D-28359 Bremen / Germany
USt-ID: DE814890109, Amtsgericht Bremen HRB 24505 HB
Tel: +49(0)421/218-5576, Fax: +49(0)421/218-5640
E-Mail: info@..., Internet: www.biba.uni-bremen.de
Geschaeftsfuehrer: Prof. Dr.-Ing. Bernd Scholz-Reiter


--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------