Xpath expression/queries ideas for this rule engine using the db

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hazz

    #1

    Xpath expression/queries ideas for this rule engine using the db

    This is what Nick Malik suggested from the c# newsgroup. Now that the hectic
    workweek is over, I can begin to appreciate what he said and break it down
    into constituent elements to solve. If anyone has any implementation
    examples related to what Nick describes below, they would be
    ppreciated. -hazz

    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.


  • hazz

    #2
    Re: Xpath expression/queries ideas for this rule engine using the db

    Sample Rule components
    Table Column op value score
    Buy Budget > 500000 10
    Buy Budget < 500000 5
    Sell In6mths = Yes 10
    Sell In6mths = No 5

    Object to evaluate
    CustomerID 1
    Budget (Dollars) 10000
    Sell (TimeFrame) 7 months
    CustomerID 2
    Budget (Dollars) 500001
    Sell (TimeFrame) 3 months
    CustomerID 3
    Budget (Dollars) 600000
    Sell (TimeFrame) 12 months


    Evaluating objects against rules would yield scores for each object, eg.
    CustomerID - Score
    If Buy then
    1 5
    2 10
    3 19

    If Sell then
    1 5
    2 10
    3 5


    Comment

    Working...