Help coderanch get a
new server
by contributing to the fundraiser
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

How to add rules to running engine?

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic