I think Payam Fard wrote: > Hi all, > > I have a Java program that is using Jess for > reasoning. My program has some rules defined which > gets loaded into Jess upon start up of the system. > There are some more complicated rules involoving > lists. I am more comfortable writing these rules in > Java and invoke them from my program for inclusion > into Jess rule set. Here are my questions: > > 1) If I write each of these rules as a Java method, > how I can call them so that they can be treated as a > defrule command in Jess for inclusion into Jess rule > set?
This isn't an option -- Java methods can't be rules. But you can very easily write Userfunctions in Java; a Userfunction is an extension to the Jess language. This way, you can write the procedural parts of your program in Java, and the rule parts in Jess. > > 2) Assuming one of these rules is a list membership. > Given a list and an item, checking to see if that item > is a member of the list. How would this rule get > invoked by Jess given a Jess triple such as: > (membership ?item ?list)? It depends what you mean here. This could be a fact, in which case there's nothing to invoke. Facts just sit there and wait to be operated on. On the other hand, it could be a function call to a function you've defined either in Jess or in Java. > I do not see the overall picture yet. If my Java function is taking > a Collection and say an Object to check whether this Object is a > member of that Collection, how do Jess variable get mapped to a > Collection or an Object? Jess variables can be assigned either by pattern-matching, or by the "bind" function. (bind ?obj (new Object)) (bind ?collection (new java.util.ArrayList)) (?collection add ?obj) (call MyJavaClass myStaticJavaFunction ?obj ?collection) You might want to check out the new book "Jess in Action" at Amazon: http://www.amazon.com/exec/obidos/tg/detail/-/1930110898 . It's chock-full of detailed examples and scenarios, including several fully-worked large examples of Jess/Java integration. --------------------------------------------------------- Ernest Friedman-Hill Distributed Systems Research Phone: (925) 294-2154 Sandia National Labs FAX: (925) 294-2234 PO Box 969, MS 9012 [EMAIL PROTECTED] Livermore, CA 94550 http://herzberg.ca.sandia.gov -------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED] --------------------------------------------------------------------
