• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Embedding Jess into Java

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,
I was wondering if anyone knew how to embedd Jess Code into a
Java Application? I have tried to figure out with the pumps example but have been mostly unsuccessful.
Many Thanks,
Sarah.
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sarah,
Well, if anybody knows, it's going to be me!
Jess is very flexible, so you can embed it in a Java program at a number of different levels. The very easiest way looks like this:

There you go. Now, anytime you want to execute Jess code (say "(assert (foo))", for example) you just say

You can execute functions and get their return values back using the Value class. For example, this prints "4":

If you want to exchange Java objects between Jess and Java code, one easy is to use the "fetch and store" method. This prints "xxxyyy":

This, on the other hand, prints "yyyxxx":

All of this (and more) is in chapter 4 of the manual. There's even more information, with many more full-size examples, in my book (see the link in my signature.)
More Jess questions welcome here anytime.
 
Sarah Ingram
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so very much for your reply!
Its helped me a great deal!
 
Sarah Ingram
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Mr Ernest Friedman-Hill or anyone else who can help!!
Hi, I am still experiencing some problems while trying to embed Jess into Java...and was wondering if you could please please help me!
I am creating a system that will diagnose Tuberculosis and am using backwards chaining. I have created a Java Swing GUI page and have (after looking at many examples and books) tried to embed my Jess code...however it is not working! I have only started using Jess about 2-3 weeks ago and so am very inexperienced with it...any advice or help will be greatly appreciated!
I have attached my Java Class below and my Jess rules beneath that...
Thanks in advance!

Jess rules:-
 
Sarah Ingram
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so sorry...i forgot to mention the nature of my problem
when i compile everything is ok, but when i run it nothing happens at all. I think either I am on totally the wrong track in terms of embedding the jess code, or I have missed something very important out...
any help will be welcome!
thanks...sarah
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if Jess's "batch" command encounters an error in the .clp file, it will report the problem using a JessException. You're catching JessException and calling "getMessage()", which returns a useful description of the problem -- but then you're neglecting to do anything with the String (like, for instance, printing it someplace where the user could see it!) Try replacing your "getMessage" calls with something like
rete.getOutputRouter("t").println(je.getMessage());
and your exceptions would go to the TextArea where they can help you diagnose your problems.
[ April 17, 2004: Message edited by: Ernest Friedman-Hill ]
 
Sarah Ingram
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Mr. Ernest Friedman-Hill,
Firstly many thanks for your reply..I can now see that it is vital that I add something that would display the results/questions in the TextArea.
I tried replacing my getMessage calls but it keeps saying that it cannot resolve the symbol...
cannot resolve symbol
symbol : method println (java.lang.String)
location: class java.io.Writer
rete.getOutputRouter("t").println(je.getMessage());
^
Am Sorry to hassle you once again.
Sarah.
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, I'm sorry. The general getOutputRouter() routine returns Writer, not PrintWriter, so println() is not available; my mistake. Well, you could just use write(String), which the Writer class does have.
 
Sarah Ingram
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for your reply and help - It is much appreciated.
However I have now given up on trying to embed this TB solution in Java code - as I still cant get it to work!!
I think I will just go for a GUI written in Jess.
Thanks once again!
Sarah
 
Did you ever grow anything in the garden of your mind? - Fred Rogers. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic