File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Java Products and Servers and the fly likes How to add rules to running engine? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Java Products and Servers
Bookmark "How to add rules to running engine?" Watch "How to add rules to running engine?" New topic
Author

How to add rules to running engine?

Hope Zhu
Ranch Hand

Joined: May 11, 2004
Posts: 32
Hi,

I am new to Jess, just could not figure out if there is a way to add rules to a running jess engine. I am calling jess command from a java application. All my rules are in a clp file, I use Rete.executeCommand("(batch *.clp)") to get all rules, then in a while loop I add some facts, call reset and run. It works fine if there is no need to change the rules in the clp file. I know I can move Rete.executeCommand("(batch *.clp)") into the while loop, but not sure if it's the right way to go since the rule file should not be changed very often. Please help!

Thanks in advance.
[ September 10, 2004: Message edited by: Hope Zhu ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

You can define new rules at any time, and you can also remove old rules using "undefrule".

I can't explain precisely what you ought to do, because I'm not sure I understand your setup. It sounds like you want this program to run continuously, and if the rule file changes, you'd like to reload it? Is that right?

In your Java while loop, you could just use File.getLastModified() to check the modification date of the file, and if it changes, then you could just reload the file. You probably want to call Rete.clear() before reloading the file, though, as some changes (for example, adding or removing slots from a template) can't be done on a live engine.

Does this make sense? Am I missing anything?


[Jess in Action][AskingGoodQuestions]
Hope Zhu
Ranch Hand

Joined: May 11, 2004
Posts: 32
Thanks Ernest, it is what I want. But this is how to achieve my goal in java, I was wondering if I can do it in Jess. Like jess setup or command?

Thanks again.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

No, Jess doesn't have any built-in way to automatically reload a batch file whenever it changes. But anything you can write in Java, you could also write directly in Jess, right? So just write the same while loop, but write it in Jess.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to add rules to running engine?
 
Similar Threads
jess!
How to assert a fact from java into a specifical jess module.
jess
questions about JESS,
this is my problem with the jess command!