Re: rules engine ideas? Trying to prevent tons of conditional branches in a logic filter.
- From: "Nick Malik [Microsoft]" <nickmalik@xxxxxxxxxxxxxxxxxx>
- Date: Thu, 30 Jun 2005 00:36:41 -0700
One thing you could do is to place your rules in a database. Each rule
consists of an XPath expression for the operand, and operator, the value you
compare against, and the score. Bring your data into your system and
serialize it into an XML document. Then, apply each of the Xpath queries to
the object, one at a time. If the query produces a result, you have a value
you can compare against. Apply the comparison and, if true, add the score
to your accumulated score.
This will work regardless of the data coming in, and your storage mechanism
can work for anything. Xpath queries are very powerful and you can
differentiate easily depending on the structure of the inbound document, so
that a query may match a value only if it is at a particular place in the
document, or anywhere in the document... up to you.
Total lines of code < 200. Highly flexible since you can add and delete
rules in the db at any time.
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik
Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"hazz" <greghazzard@xxxxxxxxxxxxxxxxx> wrote in message
news:eAEI0bQfFHA.3616@xxxxxxxxxxxxxxxxxxxxxxx
> before I start filling up the first page of perhaps many pages of code
> with if/then or switch:case buckets, I wanted to step back and see if
> there is a better way...
> I will have a table with up to 300 rules in it. Maybe more... In each
> Score table there is a column which will refer to a domain specific table
> and another table column that contains the property of that domain
> specific object. IceCream is a domain and scoops is a property I want to
> compare against. There are two other columns which have an operator
> (=,>,<) and a value to compare against. And a score assigned to that rule.
> If object.value > 100,000 scoops of ice cream, assign a score of 100.
> Basically a rule will compare a value for an object which has already been
> hydrated from the database and goes through the rule filter, which I have
> yet to build. If object.value > target.value then assign score. Keep a
> cumulative score as this object, with its various properties and property
> values, as it drops through the logic filter.
>
> I am trying to prevent an unwieldy control flow maze. Does anyone have
> ideas? I have heard about control structures like the HybridDictionary but
> I am having a difficult time imagineering that. I know what to do with an
> ice cream cone, especially chocolate chip, but I don't know what to do
> with a HybridDictionary object.
>
> Maintanability of this engine would be important as well as the possibilty
> of caching all the rules so that no database calls are required after the
> service or executable is running. Thank you. -hazz
>
.
- Follow-Ups:
- References:
- Prev by Date: Re: ThreadPool wait for threads to finish
- Next by Date: Re: How to read a file from a different drive on the same machine C# windows based application
- Previous by thread: Re: rules engine ideas? Trying to prevent tons of conditional branches in a logic filter.
- Next by thread: Re: rules engine ideas? Trying to prevent tons of conditional branches in a logic filter.
- Index(es):
Relevant Pages
|
Loading