JESS: Combining JESS.clp and normal Java GUI

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

JESS: Combining JESS.clp and normal Java GUI

Flogger
Hi Community,

not long ago I asked you how to store rules in an excel sheet. Me and my
tutor are totally ok with the apache api for accessing our rules.
I programmed a small GUI were all the input can be made.
My question right now is:
Is it possible to link my input fields to my seperated jess-file called
Bachelorarbeit.clp?
And my other question is:
How do I have to write the rules in Bachelorarbeit.clp so they can
handle input?
I tried working with the examples from "Jess in Action" but so far I was not successful.
At the moment my "program" looks like this:

(bind ?beta_sz 52.5)
(bind ?b_sz 2.5)
(bind ?l_sz 3)
(bind ?r_sz_2 0.6)
(bind ?r_sz_3 0.3)


(progn (bind ?TEPS_linear (+     (* ?b_sz -0.216)
                                  (* ?l_sz 0.685)
                                  (* ?r_sz_2 0.392)
                                   0.867 ))
      (printout t "TEPS_linear ist " ?TEPS_linear crlf))


(progn (bind ?TEPS_poly (+    (* +0.000 (** ?beta_sz 4))
                                 (* +0.035 (** ?b_sz 1))
                              (* -0.103 (** ?l_sz 3))
                              (* -0.163 (** ?r_sz_2 5))
                              (* -0.002 (** ?r_sz_3 5))
                              -0.126)
          )
      (printout t "TEPS_polynomial ist " ?TEPS_poly crlf)
   )

I declared my variables to check if i can handle the formulas. What i
want to do now is to write a piece of code to catch the variables from
the GUI (?beta_sz to ?r_sz_3). When this is done I finally want to
outsource the rule part to excel and only have the GUI and the catcher
for my variables in the code.
Thank you in advance guys.
I am happy for every little piece of help.
Greetings from good old cloudy cold Germany
Florian




--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [hidden email]'
in the BODY of a message to [hidden email], NOT to the list
(use your own address!) List problems? Notify [hidden email].
--------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: JESS: Combining JESS.clp and normal Java GUI

Jason Morris
Hi Florian,

Rules "handle" input by activating and firing in response to the assertion of facts that match their LHS patterns.  If you want a rule to "handle" some input data, simply write a rule that matches a fact containing that data.

Just have the event handler code for your "OK" button (or whatever GUI control starts your processing) assert all of your variables wrapped as Jess facts.  Then, when your rules "see" those facts containing your data, their RHS code can process it.

An example fact template would be:

  (deftemplate datum
  "A linear regression variable"
    (slot variable)
    (slot value) )


Using the Jess language, you can then assert facts like so...

    (assert (datum (variable beta_sz)(value 52.5)))

From Java proper, this would be something like:
 Rete engine = new Rete();
engine.eval("(deftemplate datum \"A linear regression variable\" (slot variable) (slot value))");

Fact datum = new Fact("datum", engine);
datum.setSlotValue("variable", new Value("beta_sz", RU.SYMBOL));
datum.setSlotValue("value", new Value(52.5, RU.FLOAT));
engine.assertFact(f);
...
  • If you are really ambitious, use a grid control on a form to act as the input/output control to a backend spreadsheet. For example, you could write an I/O widget that extends javax.swing.JTable and is databound to an Excel file via Apache Poi.  You will have to rig all the plumbing, but it can be done.  Better to use an existing widget. For a Swing app, something like QuickTable looks promising.  If you go the webapp/AJAX route, there are all sorts of databound grid widgets (e.g. Smart GWT, showcase)

  • By the way: Have you looked at integrating R with Jess?  R is a very powerful statistics package, and the JRI API let's you integrate it with Java.
Hope this helps!

Cheers,
Jason
------------------------------------------------------
Morris Technical Solutions LLC
[hidden email]
(517) 304-5883


On Fri, Mar 18, 2011 at 8:35 AM, Flogger <[hidden email]> wrote:
Hi Community,

not long ago I asked you how to store rules in an excel sheet. Me and my
tutor are totally ok with the apache api for accessing our rules.
I programmed a small GUI were all the input can be made.
My question right now is:
Is it possible to link my input fields to my seperated jess-file called
Bachelorarbeit.clp?
And my other question is:
How do I have to write the rules in Bachelorarbeit.clp so they can
handle input?
I tried working with the examples from "Jess in Action" but so far I was not successful.
At the moment my "program" looks like this:

(bind ?beta_sz 52.5)
(bind ?b_sz 2.5)
(bind ?l_sz 3)
(bind ?r_sz_2 0.6)
(bind ?r_sz_3 0.3)


(progn (bind ?TEPS_linear (+     (* ?b_sz -0.216)
                                (* ?l_sz 0.685)
                                (* ?r_sz_2 0.392)
                                 0.867 ))
    (printout t "TEPS_linear ist " ?TEPS_linear crlf))


(progn (bind ?TEPS_poly (+    (* +0.000 (** ?beta_sz 4))
                               (* +0.035 (** ?b_sz 1))
                            (* -0.103 (** ?l_sz 3))
                            (* -0.163 (** ?r_sz_2 5))
                            (* -0.002 (** ?r_sz_3 5))
                            -0.126)
        )
    (printout t "TEPS_polynomial ist " ?TEPS_poly crlf)
 )

I declared my variables to check if i can handle the formulas. What i
want to do now is to write a piece of code to catch the variables from
the GUI (?beta_sz to ?r_sz_3). When this is done I finally want to
outsource the rule part to excel and only have the GUI and the catcher
for my variables in the code.
Thank you in advance guys.
I am happy for every little piece of help.
Greetings from good old cloudy cold Germany
Florian




--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [hidden email]'
in the BODY of a message to [hidden email], NOT to the list
(use your own address!) List problems? Notify [hidden email].
--------------------------------------------------------------------





Reply | Threaded
Open this post in threaded view
|

Re: JESS: Combining JESS.clp and normal Java GUI

Jason Morris
In reply to this post by Flogger
Hi Florian,

Rules "handle" input by activating and firing in response to the assertion of facts that match their LHS patterns.  If you want a rule to "handle" some input data, simply write a rule that matches a fact containing that data.

Just have the event handler code for your "OK" button (or whatever GUI control starts your processing) assert all of your variables wrapped as Jess facts.  Then, when your rules "see" those facts containing your data, their RHS code can process it.

An example fact template would be:

  (deftemplate datum
  "A linear regression variable"
    (slot variable)
    (slot value) )


Using the Jess language, you can then assert facts like so...

    (assert (datum (variable beta_sz)(value 52.5)))

From Java proper, this would be something like:
 Rete engine = new Rete();
engine.eval("(deftemplate datum \"A linear regression variable\" (slot variable) (slot value))");

Fact datum = new Fact("datum", engine);
datum.setSlotValue("variable", new Value("beta_sz", RU.SYMBOL));
datum.setSlotValue("value", new Value(52.5, RU.FLOAT));
engine.assertFact(f);
...
  • If you are really ambitious, use a grid control on a form to act as the input/output control to a backend spreadsheet. For example, you could write an I/O widget that extends javax.swing.JTable and is databound to an Excel file via Apache Poi.  You will have to rig all the plumbing, but it can be done.  Better to use an existing widget. For a Swing app, something like QuickTable looks promising.  If you go the webapp/AJAX route, there are all sorts of databound grid widgets (e.g. Smart GWT, showcase)

  • By the way: Have you looked at integrating R with Jess?  R is a very powerful statistics package, and the JRI API let's you integrate it with Java.
Hope this helps!

Cheers,
Jason
------------------------------------------------------
Morris Technical Solutions LLC
[hidden email]
(517) 304-5883


On Fri, Mar 18, 2011 at 8:35 AM, Flogger <[hidden email]> wrote:
Hi Community,

not long ago I asked you how to store rules in an excel sheet. Me and my
tutor are totally ok with the apache api for accessing our rules.
I programmed a small GUI were all the input can be made.
My question right now is:
Is it possible to link my input fields to my seperated jess-file called
Bachelorarbeit.clp?
And my other question is:
How do I have to write the rules in Bachelorarbeit.clp so they can
handle input?
I tried working with the examples from "Jess in Action" but so far I was not successful.
At the moment my "program" looks like this:

(bind ?beta_sz 52.5)
(bind ?b_sz 2.5)
(bind ?l_sz 3)
(bind ?r_sz_2 0.6)
(bind ?r_sz_3 0.3)


(progn (bind ?TEPS_linear (+     (* ?b_sz -0.216)
                                (* ?l_sz 0.685)
                                (* ?r_sz_2 0.392)
                                 0.867 ))
    (printout t "TEPS_linear ist " ?TEPS_linear crlf))


(progn (bind ?TEPS_poly (+    (* +0.000 (** ?beta_sz 4))
                               (* +0.035 (** ?b_sz 1))
                            (* -0.103 (** ?l_sz 3))
                            (* -0.163 (** ?r_sz_2 5))
                            (* -0.002 (** ?r_sz_3 5))
                            -0.126)
        )
    (printout t "TEPS_polynomial ist " ?TEPS_poly crlf)
 )

I declared my variables to check if i can handle the formulas. What i
want to do now is to write a piece of code to catch the variables from
the GUI (?beta_sz to ?r_sz_3). When this is done I finally want to
outsource the rule part to excel and only have the GUI and the catcher
for my variables in the code.
Thank you in advance guys.
I am happy for every little piece of help.
Greetings from good old cloudy cold Germany
Florian




--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [hidden email]'
in the BODY of a message to [hidden email], NOT to the list
(use your own address!) List problems? Notify [hidden email].
--------------------------------------------------------------------





Reply | Threaded
Open this post in threaded view
|

Re: JESS: Combining JESS.clp and normal Java GUI

Flogger
In reply to this post by Jason Morris
Hello Jason,

Thanks for your quick response.
Maybe handle was the wrong word to use :-).
Your approach seems to be good, but my problem is: do i need a single deftemplate for every variable or is it one deftemplate for all variables ok? And in which way do I need to rephrase my formulas so I can access the facts I asserted in my deftemplate
In my last post I attached my gui. Maybe you can take a quick look.
What I want to do:
I want to write my variables in the different jtextfields catch their values and assert them as facts. Then I click on "Start" what will start my jess-code and in the PopUp I can see the different conclusions.
What do you think would it be easier: to connect my gui (newjframe.java) to jess (bachelorarbeit.clp),
                                                                   to rewrite the gui in jess ( I think it is a terrible work, because my gui has more then 800lines)
                                                                   or integrate my jess code in java.
Thanks again for your help. Maybe someone else has a good hint as well.
Greetings Florian

My Am 18.03.2011 17:44, schrieb Jason Morris:
Hi Florian,

Rules "handle" input by activating and firing in response to the assertion of facts that match their LHS patterns.  If you want a rule to "handle" some input data, simply write a rule that matches a fact containing that data.

Just have the event handler code for your "OK" button (or whatever GUI control starts your processing) assert all of your variables wrapped as Jess facts.  Then, when your rules "see" those facts containing your data, their RHS code can process it.

An example fact template would be:

  (deftemplate datum
  "A linear regression variable"
    (slot variable)
    (slot value) )


Using the Jess language, you can then assert facts like so...

    (assert (datum (variable beta_sz)(value 52.5)))

From Java proper, this would be something like:
 Rete engine = new Rete();


 engine.eval("(deftemplate datum \"A linear regression variable\" (slot variable) (slot value))");

 Fact datum = new Fact("datum", engine);


 datum.setSlotValue("variable", new Value("beta_sz", RU.SYMBOL));
 datum.setSlotValue("value", new Value(52.5, RU.FLOAT));
 engine.assertFact(f);


 ...
  • If you are really ambitious, use a grid control on a form to act as the input/output control to a backend spreadsheet. For example, you could write an I/O widget that extends javax.swing.JTable and is databound to an Excel file via Apache Poi.  You will have to rig all the plumbing, but it can be done.  Better to use an existing widget. For a Swing app, something like QuickTable looks promising.  If you go the webapp/AJAX route, there are all sorts of databound grid widgets (e.g. Smart GWT, showcase)

  • By the way: Have you looked at integrating R with Jess?  R is a very powerful statistics package, and the JRI API let's you integrate it with Java.
Hope this helps!

Cheers,
Jason
------------------------------------------------------
Morris Technical Solutions LLC
[hidden email]
(517) 304-5883


On Fri, Mar 18, 2011 at 8:35 AM, Flogger <[hidden email]> wrote:
Hi Community,

not long ago I asked you how to store rules in an excel sheet. Me and my
tutor are totally ok with the apache api for accessing our rules.
I programmed a small GUI were all the input can be made.
My question right now is:
Is it possible to link my input fields to my seperated jess-file called
Bachelorarbeit.clp?
And my other question is:
How do I have to write the rules in Bachelorarbeit.clp so they can
handle input?
I tried working with the examples from "Jess in Action" but so far I was not successful.
At the moment my "program" looks like this:

(bind ?beta_sz 52.5)
(bind ?b_sz 2.5)
(bind ?l_sz 3)
(bind ?r_sz_2 0.6)
(bind ?r_sz_3 0.3)


(progn (bind ?TEPS_linear (+     (* ?b_sz -0.216)
                                (* ?l_sz 0.685)
                                (* ?r_sz_2 0.392)
                                 0.867 ))
    (printout t "TEPS_linear ist " ?TEPS_linear crlf))


(progn (bind ?TEPS_poly (+    (* +0.000 (** ?beta_sz 4))
                               (* +0.035 (** ?b_sz 1))
                            (* -0.103 (** ?l_sz 3))
                            (* -0.163 (** ?r_sz_2 5))
                            (* -0.002 (** ?r_sz_3 5))
                            -0.126)
        )
    (printout t "TEPS_polynomial ist " ?TEPS_poly crlf)
 )

I declared my variables to check if i can handle the formulas. What i
want to do now is to write a piece of code to catch the variables from
the GUI (?beta_sz to ?r_sz_3). When this is done I finally want to
outsource the rule part to excel and only have the GUI and the catcher
for my variables in the code.
Thank you in advance guys.
I am happy for every little piece of help.
Greetings from good old cloudy cold Germany
Florian




--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [hidden email]'
in the BODY of a message to [hidden email], NOT to the list
(use your own address!) List problems? Notify [hidden email].
--------------------------------------------------------------------