File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to add rules to running engine?

 
Hope Zhu
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Hope Zhu
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic