Re: rules engine ideas? Trying to prevent tons of conditional branches in a logic filter.



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
>


.



Relevant Pages

  • Re: rules engine ideas? Trying to prevent tons of conditional branches in a logic filter.
    ... someplace that would help me frame the XPath query solution....ie. ... > One thing you could do is to place your rules in a database. ... > you compare against, and the score. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: XPath: Multiple conditions (contains, dates, node-set)
    ... if the first one returns a node-set and so on. ... I recommend using the XPath Visuaizer for learning XPath the fun way -- ... in case there is any doubt how an XPath expression will be evaluated, ... compare the parts of a date as integers. ...
    (microsoft.public.dotnet.xml)
  • Re: File Auditing - Fast DB import and data manipulation
    ... the files into the database is not the best way forward. ... on either system (you'll need to download gunzip from gnuwin32 ... The databases I've dealt with (Oracle, SQL Server, Access, Postgres) ... So, I need some way to compare todays file, to yesterdays and see ...
    (comp.lang.ruby)
  • Re: Divining the full pathname of a file, all logicals translated
    ... compare it to the "current" state when an audit report is run. ... drive name needs to be retained also, unmasked from any logicals. ... The auditors may never see the actual database. ...
    (comp.os.vms)
  • Re: Efficient Integer Comparison Algorithm
    ... The other database is external and I ... Do you think there is a way to link my Oracle DB and the file input ... Since you only want to compare according to equality of your two values a HashMap is more efficient. ... If the first ordered column in the local store data is less than in the DB data, increase it until they are same or greater. ...
    (comp.lang.java.programmer)

Loading