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?"
I'm not an AI or Prolog type person. But if there are a lot of conditional statements that are based upon some know steps then generating them might be an idea.
Of course I tend to be slightly biased towards generators as they save me days of coding and testing in my current job.
there is a prolog compiler for .net around:1 .3/dlpsharp.html
;)
http://www.dcs.ed.ac.uk/home/jjc/psharp/psharp-1.
as you can implement a prolog interpreter in 30 lines of lisp, you might also want to check lisp.net compilers
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.
.NET languages, but I'm sure it can be done with a little reflection (pun intended).
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
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.
What kinds of problems would you solve with a prolog type system?
I've read about prolog, going back for years (it was a scare, a long time ago, in the '80's, I think -- the japanese were spending government money on prolog type logic systems, and they were going to bury us), but I've never really understood how it plugs into the real world.
I mean, if you're doing something practical, what does it do for you?
Even this question is pretty vague... I don't have any idea of what the poster wants the thing to do.
One approach is to have a database table with the rules in them. Example schema:
// example: "x > 3 and y == 7" // what to execute if true // order of execution
table: rules
----------------
ruleID
ruleDescript
expression
ifTrueSnippet
priority
This allows one to easily create a log of the of the rules and their result. Note that it takes a fairly dynamic language to impliment this so that it can execute code snippets from a database. You probably would want to go with something like Python or PHP instead of C++.
However, I am skeptical any such tool can be as flexible as just plain IF statements in code. But it may be useful for non-programmers, yet power-users to manage the rules themselves. The "ifTrueSnippet" may instead be predefined operation names rather than code in that case. And, maybe a parameter column or two may be in order, depending on the domain.
-T-
Table-ized A.I.
As other people have suggested, one path is to invest in an expert system. You haven't mentioned how many rules your expert system consists of, and you may switch to some other expert system to find that it hasn't improved your capability to manage your rules. Regardless of whether you switch or not, I cannot overemphasize the importance of having a good suite of regression tests for your rules.
I'll keep it short.
:-) searches... all the rules based systems have this issue, again the answer will be depending on the problem.
1. there is no way to completely get rid of if/then statements. they'll be somewhere. What's good with CLIPS or so is that there is not much else than the if/thens of the rules, so you don't get lost in memory allocation and the rest of the bull. On the other hand, the rules (and facts) tend to be localized in the same file, you don't have to read 200 classes of assembler (:-)) files to find all of them
2. depending on the nature of dynamics of your rules , if you don't have that many rules (20-30???) you can use simple (or complicated) if-then statements as long as you DOCUMENT THEM WELL!!! so the next john (or yourself) can pick up the work from there. hmm, this kind'a makes me think
3. if the rules are VERY dynamic (or just too many of them), a more general approach will be needed. Welcome CLIPS or other rule-based expert system. I heard fairy-tales with systems with tens of thousands of rules, so probably it works.
4. How you store the rules, is completely your business, I don't see any problem storing them in a database, file or on a rice, written by a very old and pacient chinese.
5. from the practical standpoint, the problem with the rules is a very general one. how do you connect a lot of facts with a lot of rules? answer? algorithms - check RETE, check hashes, I'll stop here gasping for air short of ideas.
6. how do you apply the rules, in which order? this is another issue, related to the given problem. see the depth, width or jumpy
7. another issue, thread safety, parallelism. how do you synchronize all of these?
and I think I forget something... hmmm... did I turn off the stove...?
I had another sig before, but this one is better