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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

[jess] Why a language and not an API?

 
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
In another thread I read "Remember that besides being a rule engine, Jess is an entire programming language." This was also the impression I got from reading the jess documentation online.
Can anyone explain a little more about why this might be a good idea. My immediate reaction is that we have plenty of scripting languages already, as well as the Java language itself. If I just want to be able to set a few values and run an inference engine, why should I need a language interpreter cluttering up my VM?
I hope it doesn't sound as if I'm trolling here, as I'm genuinely interested in this.
 
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
Well, there are several reasons. First, the Jess language isn't really a made-up language: it's a variant of Lisp which has a long history in rule-based systems. CLIPS, OPS, and ART, systems which you could consider to be Jess's grandparents, used variants of this same language, so there were tools to support the language, books to teach the language, and people that knew the language, before Jess was first created (7 years ago, now.)
People have described the Jess language as a kind of "Javafied Lisp," which I think fit.
Now, why do you need a Javafied Lisp at all, rather than just having a Java API? If you think about a rule as an if-then kind of thing, the hard part to do with a Java API is the "if". This is a rule from the "Recommendations Agent" in part 6 of the book. The RecommendationsAgent looks at what a customer is buying and what they've bought in the past, and recommends that they buy more stuff. This is one rule that recommends DVDs or VCR tapes to people who have bought the appropriate player.

The first "pattern" in the "if" part of this rule is

This pattern matches a product which is either a dvd or a video tape, set a variable "?media" to the part number, "?c" to the product category, and sets a variable "?p1" to refer to this product object as a whole. OK, what would this look like in Java? A rough try at a Java API looks something like

That's just the first of seven patterns! So you see the Jess language has much more economy of expression in this domain.
P.S. Besides the Jess language, Jess has a rich Java API for embedding and manipulating the rule engine.
[ September 02, 2003: Message edited by: Ernest Friedman-Hill ]
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I may add my 2c, the fact is that rule based languages are declarative in nature, while Java is an imperative language. Declarative languages are concise and expressive when used to represent logical expressions. The semantics of a rule is implemented by a logic interpreter. Converting into an imperative form such as a Java API would require explicating the procedural semantics of the rule in terms of a set of base classes and expressions, plus somewhere in your system implementing a Java version of the interpreter to thread the rules into the desired set of behaviors, such as Ernest showed in his message.
Ernest, I am just beginning to learn about JESS. Can you do forward and backwards based reasoning with JESS rules?
 
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


Jorge Phillips writes:
[B]Ernest, I am just beginning to learn about JESS. Can you do forward and backwards based reasoning with JESS rules? {/B]


Jess is primarily a forward-chaining rule engine, but it supports a certain kind of backward-chaining, too. It's possible to set things up so that, say, if you have a rule like

but there are no persons in working memory, other rules you provide, called goal-seeking rules, are automatically triggered; these rules have a chance to provide persons that fit this profile from someplace (say, by querying a database). You can chain backwards through any number of levels this way. So it's definitely backward chaining, although it's not completely transparent.
 
Frank Carver
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
[I]A rough try at a Java API looks something like

That's just the first of seven patterns! So you see the Jess language has much more economy of expression in this domain.
[/I]
Well, yes, but that's not really what I was getting at, I suppose.
Looking at the structure of the Jess language examples I have seen, I guess it compiles into some sort of list/tree representation internally. At this point it has a lot in common with any of the other Java APIs that create and manipulate list/tree representations (the XML APIs, AWT/Swing. JNDI etc. etc.)
If that API were publicly available as you discribe it would be both simple and powerful to transform from one of these list/tree models to another without ever manually creating rules as you describe. Jess in XML? Jess in JNDI? Graphic builder tools?
P.S. Besides the Jess language, Jess has a rich Java API for embedding and manipulating the rule engine.
Hmm. but from the way you describe the above example as "A rough try at a Java API", I guess it doesn't extend to the level of programmatically creating/changing rules. Or have I missed something?
 
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


If that API were publicly available as you discribe it would be both simple and powerful to transform from one of these list/tree models to another without ever manually creating rules as you describe. Jess in XML? Jess in JNDI? Graphic builder tools?


The business of defining rules in XML is tricky, but there are emerging standards (RuleML, DAML, BRML). None of them are quite powerful enough yet to express everything that Jess's rule language can express. But the next release of Jess (codename Charlemagne) will have XML support, and then these kinds of transformations will indeed be possible.


Hmm. but from the way you describe the above example as "A rough try at a Java API", I guess it doesn't extend to the level of programmatically creating/changing rules. Or have I missed something?


No, you're right, you can't create rules from Java without using snippets of Jess code. You can create many other Jess-language objects this way, though.
 
Frank Carver
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
the next release of Jess (codename Charlemagne) will have XML support,
Interesting. Will this be in addition to the existing definition language, or an alternative? Will the next release of the Jess "component" need to include the code for both?
As you may be able to guess by now, my ideal rule-engine would be one where everything is configurable/executable using a public API with one or more languages as layers built on top of the API. That way the rule-execution component is as light and flexible as possible and users/developers are free to store rule and data "source" in any language, in any format, in any location.
Which leads to another question. Is a configured ruleset serializable? Could I somehow "snapshot" a Jess system built using your current specification language, then load and execute it in a Jess-like-component without the language interpreter?
 
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


Interesting. Will this be in addition to the existing definition language, or an alternative? Will the next release of the Jess "component" need to include the code for both?


Implementation-wise, I'm not yet sure. The user experience will be that you can use one or the other language.


As you may be able to guess by now, my ideal rule-engine would be one where everything is configurable/executable using a public API with one or more languages as layers built on top of the API. That way the rule-execution component is as light and flexible as possible and users/developers are free to store rule and data "source" in any language, in any format, in any location.


The reason that Jess has never had a public Java API for building rules is that the internal data structures have changed a lot over the years, as I knew they would, and we don't like to expose any APIs that we can't support over time. Customers always want both compatibility and improvements, and it's hard to do both! The solution has been to restrict access to things we knew would change as the engine evolved.
An alternative solution would have been to provide a Java "buffer" layer, that exported an unchanging API and "translated" to the changing internals; but this would actually mean both added complexity, and a less efficient parser. Since your goal here is lightness, doing things this way would have been worse, really.


Which leads to another question. Is a configured ruleset serializable? Could I somehow "snapshot" a Jess system built using your current specification language, then load and execute it in a Jess-like-component without the language interpreter?


A configured ruleset is indeed serializable. You can snapshot the whole engine at any time, including the working memory and the agenda if those are populated. You can do this in Java, the normal way, or you can do it from the Jess language itself using the "bsave" and "bload" commands.
Currently, though, Jess doesn't support the idea of loading that snapshot into an environment without any language interpreter. The interpreter isn't used to execute the compiled ruleset, but Jess is very dynamic -- you can add, change, or delete rules, functions, queries, etc, at any time -- and so the engine uses its own internal copy of the interpreter to execute Jess code on the fly. It would be possible to modify Jess to lazy-load this interpreter object, though, so that it wasn't loaded if it weren't used.
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does any one use the langauge LISP. I had studied in my college but never used it.
 
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
Short answer: yes.
Longer answer: yes, especially various dialects like Scheme. Lisp has a reputation for being very old fashioned; it is one of the oldest high-level languages, after all. But actually, the various Lisps are very expressive and powerful in ways that many other languages (Java *cough*) are not; these other languages are still playing catch-up.
 
Frank Carver
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
A configured ruleset is indeed serializable. You can snapshot the whole engine at any time, including the working memory and the agenda if those are populated. You can do this in Java, the normal way, or you can do it from the Jess language itself using the "bsave" and "bload" commands.
Excellent. I will definately have to get hold of one of the source licences through some route or other and have a play with this.
More questions, though. Does the Jess development process/team have a policy about accepting code suggestions from users, or would any such changes constitute a project "fork"?
 
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


More questions, though. Does the Jess development process/team have a policy about accepting code suggestions from users, or would any such changes constitute a project "fork"?


We're very picky about code quality, so we don't often accept large amounts of code wholesale; we do accept ideas pretty regularly, though, and small patches. Have a look at the jess-users mailing list archive to get an idea of the level of involvement users can have in influencing Jess's direction (and that's only the public discussions!)
 
Frank Carver
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
Have a look at the jess-users mailing list archive.
Ah. Good resource. I can't help finding the threads here a bit easier to read, though
 
No holds barred. And no bars holed. Except this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic