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

Jess and databases

 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From other threads I notice mention of using Jess with data stored in a (potentially large) database, and yet I can't seem to find anything in the Jess on-line manual about it.
Whenever I've experimented with forward-chaining rules algorithms in the past, I've never been able to sensibly use bulk data sources such as a database (or CSV file, or whatever) without effectively resetting and triggering all the rules as if all the data is newly asserted.
I've read that this is one of the major reasons that caused the Mandarax programmers to go for a backward-chaining approach, whch is indeed much more amenable to just fetching data items which are actually referenced by triggered rules. Backward-chaining has other issues, of course.
Can anyone shed any light on how/if Jess gets round this problem?
 
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
The fundamental problem is, of course, that if there's data in a database, somehow, the rule engine has to know about it. There are a couple of ways that people have tackled this.
First, Jess has PropertyChangeEvent support built-in. If the database is the persistence layer for EJBs, say, and the rule engine is reasoning about the EJBs, then if you make the EJBs send PropertyChangeEvents, everything is kept in sync automatically. Even without the events, you can manually tell Jess to update a single object.
Now, of course, this doesn't deal with the question of how the objects get into the rule engine in the first place. Jess is primarily a forward-chaining engine, but it's got some backward chaining machinery in it which can be used to good effect. One of the "User Contributions" on the Jess web site is the "Fact Storage Provider Framework (FSPF), " which can be used as is, or used as an example. The basic idea here is that you write forward-chaining rules about arbitrary data, and Jess's backward-chaining machinery is told to try to find the data these rules want to match. The FSPF is triggered by this and makes JDBC calls to fetch the objects you need to reason about. These objects can be flushed when you're done with them, or the change-event mechanism could be used to keep them up to date. So this is basically the Mandarax approach you described, except in a forward-chaining engine.
A third, more radical alternative is to do away with the RDBMS altogether, and use a OODBMS or something like Prevayler to store the objects, which then basically live in Jess's working memory. This is more practical than you'd imagine, especially on architectures where the Java heap can be a full 4GB.
There's no magic bullet; none of this stuff is completely transparent. But people have done a good job of successfully addressing the problem in many different ways using Jess. The Jess user community is a smart bunch of people.
 
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If the database is the persistence layer for EJBs, say, and the rule engine is reasoning about the EJBs, then if you make the EJBs send PropertyChangeEvents, everything is kept in sync automatically. Even without the events, you can manually tell Jess to update a single object


That sounds so simple. I've had this discussion a long while ago about managing events this way (as you'd do with ordinary JavaBeans) but never managed to get very far (they weren't sure about EJBs in the first place). Nice to see this is possible.
regards
 
reply
    Bookmark Topic Watch Topic
  • New Topic