Slashdot Mirror


Building Intelligent, Rule-Based Applications?

Donald Hughes asks: "What are good approaches for building intelligent, rule-based applications? In particular, I typically build ASP.Net applications. I came across P#, which translates Prolog into C#. I also came across NxBRE, which touts itself as the first open-source rules engine for the .Net platform. Currently, the intelligence in my applications consist of data stored in the database, which is either processed in T-SQL or in a C# class using linear conditional logic. This approach works fine to a point, after which the complexity of the if/then statements becomes extremely difficult to manage. This is especially problematic when returning to a project after several months of not looking at it, or when someone needs to be introduced to it for the first time. Does anyone have some helpful advice?"

1 of 57 comments (clear)

  1. just start refactoring by Anonymous Coward · · Score: 5, Interesting

    I'm not sure I understand the question but you definitely don't want if/then statements in rule-based programming. You basically want to create a separate function for each "if" and each "then", and then declare the relationship between them.

    For example (I'm just making this up off the top of my head, and using Ruby syntax), you might want to call "customer.save" to send a customer object to the database. You can't call this function until the customer object has had certain things happen to it, for instance "not customer.empty?" must return true. "customer.agreed_to_terms?" must return true. Each of these tests might itself depend on other tests, and so forth. And some tests might need input from the user, or the result of a complex calculation, or whatever.

    Just write a function for each and then write some generic code that doesn't call a function until all the dependencies return true. This is like, 5 lines of code.

    You can configure the relationships with a simple text file. This is a very powerful system. An analogous system for shell scripts would be Makefiles.

    This is super-easy in Lisp, Ruby, etc., not sure about .NET languages, but I'm sure it can be done with a little reflection (pun intended).

    This is a really easy and powerful concept once you figure it out. Basically your code will "discover" the proper order to do things in based on the dependencies.

    A further step is to encode the state of your app in a tuple (an array), and use tuple spaces to distribute work among many machines. It's quite magical when you've got it all working right.

    Study the prolog examples as well, Prolog basically generalizes this procedure even more.