

Building Intelligent, Rule-Based Applications? 57
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?"
Generator? (Score:3, Interesting)
Of course I tend to be slightly biased towards generators as they save me days of coding and testing in my current job.
You Mean Translator? (Score:2)
P# / LISP (Score:3, Interesting)
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
just start refactoring (Score:5, Interesting)
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.
Re:just start refactoring (Score:3, Insightful)
Re:just start refactoring (Score:3, Insightful)
You're exactly right: Most languages have very weak support for that kind of dynamic, introspective, functional programming. It would be ugly in C, for example, and impossible in Fortran. (In theory, everything is possible in every Turing-equivalent language. But eventually you blow out all your tendons and have to be put in a madhouse.) You s
Off topic, of course... (Score:3, Funny)
Actually - this is possible - it is called (IIRC) "forge welding" - basically, you get both of your pieces of steel super red hot, place them one on top of the other on an anvil, and pound them as hard as you can with your blacksmith's hammer. This may require more than one person to accomplish, and you need some good strength, because you have to pound that shit HARD. Plus, you need to keep it red hot as you work it. In the end, though, with a
The mods are IDIOTS!!!!! (Score:2)
Need proof that this is a real form of welding? HERE IS YOUR PROOF [dfoggknives.com]
A couple of excerpts from the site:
Forge welding is the core technique involved in creating Damascus steels. It is a solid-phase bondi
Ruby Cowboys (Score:2)
This could be a mature application with business analysts and real money on the line, he doesn't care about
Re:Ruby Cowboys (Score:1)
Re:Ruby Cowboys (Score:2)
Book (Score:3, Informative)
Newbie C++ Programmer Question From The Fat Guy... (Score:2)
Re:Newbie C++ Programmer Question From The Fat Guy (Score:1)
The application will load and interpret the rules in order to perform processing functions; and the rules can be modified at runtime, typically by expert users or adminsitrators.
Finite State Machine (Score:4, Informative)
Depending on what you are doing a finite state machine could be a good answer. Take a look at the state machine compiler (SMC) on sourceforge.
Re:Finite State Machine (Score:1)
http://www.pragmaticprogrammer.com/articles/nov_0
Re:Finite State Machine (Score:2)
T & R = T
Mercury .NET (Score:2)
basic question (Score:3, Interesting)
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.
Re:basic question (Score:3, Informative)
The advantage in these sorts of uses is that you can reason about the declarative program much easier than you can about the set of steps that you would write down in a procedural language.
SQL is a kind of declarative language that you might be familiar with. Although it is much less powerful than say prolog, its advantage
Re:basic question (Score:2)
Re:basic question (Score:5, Informative)
You need a set of rules about when traders can go ahead and execute a particular trade. For example, if the bank already has a huge stash of Japanese yen, they might not want to buy any more (regardless of the price); they'll have a particular risk profile that each trade must fall into.
Now, the people who write the code to check how much the bank holds in Japanese yen at a particular point in time, will almost certainly NOT be the people who create and maintain the risk profiles that the bank needs to trade under when it buys or sells yen. The first set of guys will probably be full-time "normal" programmers who reference stuff out of one or more databases; the second set of guys will be trading management type people. While there's obviously a level of synergy required between the two, they're unlikely to (want to) sit and work together on a regular basis.
So far, it's not that unusual a problem.
Where it gets interesting is that both areas tend to be very dynamic: the definition of a good risk profile tends to vary over time, and the way of calculating current positions in Japanese yen may also change over time (as the bank starts/stops trading in different exchanges, as the bank opens/closes trading rooms in different parts of the world and different timezones, and so on).
Where rule-based apps shine in this scenario is that the two requirements can (and should) be largely separated. Provided the data coming from the data guys can be kept valid (which can be a huge challenge in itself), there's no reason for the risk management guys to be aware of where that data comes from or to question its integrity; they should be adjusting risk profiles via a rules-based mechanism rather than a programming mechanism that requires them to understand anything more than the actual values of the data.
Their rules may include things like "if we're going to buy more yen, we have to sell Brazilian real because we believe there's a relation between the two"; sure, you could employ a regular OO-type coder to do this stuff, but it's much quicker/safer for the guys making such rules to implement them in a rules engine. In this scenario, when a trader puts in a request to buy more yen, it will have to be matched with the amount of Brazilian real that has been sold to see if the appropriate ratios exist to allow the yen trade to go through.
Frequently, things get much more complicated than that, and maybe you'll have to deal with half a dozen other factors as well; this is a simplistic example that could probably be done with a few Excel macros and stored procs, but hopefully you can see how the complexity could scale to the point that a rules-based approach becomes significantly better than "traditional" alternatives as the problem becomes less and less trivial.
Re:basic question (Score:2)
Thanks very much for taking the trouble.
Re:basic question (Score:2)
Is the sky falling?
Table Oriented Programming (Score:3, Interesting)
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-
Re:Table Oriented Programming (Score:1)
Hence you'd probably want to write it in lisp so you can do away with that whole useless data vs. code dichotemy
You can probably find some decent rule-system implementations floating near academia if you dig.
Re:Table Oriented Programming (Score:1)
Hmmm. What about TCL?
Die, Anti-Lisp Bigot! (Score:2)
High-end programmers should have no problem switching between prefix and infix: it's only cog-like code monkeys who insist that the most popular languages have C-like syntax. Experts will continue to implement obscure applications in obs
Re:Table Oriented Programming (Score:2, Interesting)
The rete algorithm appears to relate to creating a tree structure where each node is a rule and each leaf is a function. So, as the process goes from node to node, and the process evaluates rule after rule, the process comes to the final leaf and calls the desired function.
Celko's books deal with the implementation of trees in databas
Re:Table Oriented Programming (Score:1)
Ilog (Score:2)
Re:Ilog (Score:2)
Re:Ilog (Score:2)
Regression testing (Score:2, Interesting)
Java Rules Engines (Score:4, Informative)
SQL Server 2005 Recursive Queries (Score:1)
Recursive queries in SQL Server 2005 [sqlservercentral.com]
Take a look at CLIPS (Score:1)
Seconded (Score:2)
A friend of mine used CLIPS in a system for a drug store chain, which provided suggestions to customers depending on what they purchased.
intelligent approach? depends on the given problem (Score:2, Interesting)
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 man
A few practical questions... (Score:2)
If it is just for you it really does not matter.
If it a company you work for you may want to check. I had a guy working for me that wanted to write everything in FoxPro because that is what he knew. I told him no but he wrote some little utilities for a different department. He left and no one knows how modify his code. That goodness they were trivial.
If it is a company you are starting. W
Rules Engine... (Score:2, Informative)
Domain-Specific Language (Score:2)
CLIPS (Score:1)
http://www.ghg.net/clips/CLIPS.html [ghg.net]
Usually you don't need it (Score:2)
For the rest of cases, building your own rule processing engine that serves a particular purpose and interacts with the rest of the system, is such an easy task, it is not worth generalizing.
For $deity sake, netfilter has some (simple) rule-based processing, and it's merely a small piece of code inside the Linux kernel.