On Sun, 5 Sep 2004 19:43:09 -0700 (PDT), [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I think Don Schwarz wrote: > > Hello, > > > > While attempting to integrate Jess with some existing Java code, I > > have stumbled across what I think is a very useful design pattern. I > > want to share this pattern with you guys and get your feedback on it. > > This is very, very clever. I like it a lot. > Glad to hear it! :-)
> Note that instead of defining your own version of defclass, you could > use "defadvice" to add this behavior to the built-in defclass. > Yes. I had considered that, but it wasn't clear that you'd want to turn backwards-chaining on for any class that you weren't using in this manner. > Rather than using backward chaining, you could instrument definstance > to "push" all the objects it finds in the slots of definstanced > objects. This is more work upfront, but depending on usage pattern > could be less computation in the long run. > Yes. This is actually what I started out with. I was trying to integrate Jess with Spring in such a way that you could write rules to match on all objects specified in your beans.xml and all sub-objects that could be reached from these. My first attempt iterated over the Spring BeanFactory, recursed through all accessible objects, and definstance'd each object encountered. However, for all but the most trivial applications this turned out to be too inefficient. My next attempt was to assert a single fact for each top-level object in the BeanFactory: (bean (name "beanName") (object beanObject)). I then had a rule that matched all (bean) facts and called (definstance), and the use of backwards chaining as described in my previous email allowed you to match sub-objects. Finally, I made the lookup of the (bean) facts use backwards chaining as well, so that the entire process could occur lazily. (defrule lookup-bean (need-bean (name ?name) (object nil)) => (assert (bean (name ?name) (object (call ?beanFactory "getBean" ?name))))) > > Can anyone think of a clever way to extend this style of rule matching > > to support one-to-many associations (e.g., if a plane contained a list > > of engines) ? I haven't had much luck with this. > > In theory what I just proposed would work for this, too. > Yes, it did. This is the one piece of functionality that I lost in the conversion to backwards chaining, which is why I'm trying to find some way to do this. Thanks for the feedback, Don -------------------------------------------------------------------- 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] --------------------------------------------------------------------