I think Blaine Alex Bell wrote: [Charset iso-8859-1 unsupported, filtering to ASCII...] > I was baffled as well by this question, but I resolved it > by just using the function executeCommand(String cmd) for the rule. > It is odd that the Defrule API doesn't support the methods for building a > rule in this manner (could/would be faster and more precise than string > parsing).
Everyone seems to have this belief -- that about parsing a String into a rule is slow. But let's say you were going to try to build the OP's sample rule using a Java API: > > (defrule example-3 > > (not-b-and-c ?n1&~b ?n2&~c) > > (different ?d1 ?d2&~?d1) > > (same ?s ?s) > > (more-than-one-hundred ?m&:(> ?m 100)) > > (red-or-blue red|blue) > > => > > (printout t "Found what I wanted!" crlf)) There are five patterns, which includes about 15 tests, plus a function call on the RHS. So using such an API, you'd create a Defrule object, five "Pattern" objects, call an "addTest" method something like 15 times (either by creating Test objects, or letting Jess define them for you,) then create a Funcall, call arg() on it three times, and call "addFunctionCall" . Then you'd have a Defrule. Then you'd give it to Jess, which would analyze the rule and create the approximately 25 different Rete network notes that come from this rule. Do you really thiink that parsing a string adds that much overhead compared to the total amount of work that defining a rule represents? > However, not that big of a deal, because in order to create the > string you need to have your own representation of patterns, LHS, RHS, > etc.(that will get more complicated based on your program), so what you > are suggesting might not be that worthwhile to implement in JESS. > The reason Jess has never had a public API for creating Defrule objects is that the conceptual structure for Defules changes quite a bit between releases. Adding new concepts like nested CEs and (logical) requires some major restructuring. If I exposed a public API for rule creation, either 1) it would break with every release, or 2) it would have a thick firewall between it and Jess's actual internals. In the latter case, it would be -less- efficient than String parsing, because although you'd be making direct Java calls, they'd be filtered through an abstraction layer (and the most convenient abstraction would be the textual representation of a rule!) --------------------------------------------------------- Ernest Friedman-Hill Distributed Systems Research Phone: (925) 294-2154 Sandia National Labs FAX: (925) 294-2234 Org. 8920, MS 9012 [EMAIL PROTECTED] PO Box 969 http://herzberg.ca.sandia.gov Livermore, CA 94550 -------------------------------------------------------------------- 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] --------------------------------------------------------------------
