Re: Rules in a database

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



A bit of algebra first:

any expression formed of atomic expressions, AND, OR and parentheses can be
reduced to a "canonical" form, by using the De Morgan laws:
a AND ( b OR c ) is equiv. to a AND b OR a AND c

So a rule can eventually be reduced to "AND" groups, joined by "OR":
a(1) AND... AND a(n) OR ... OR z(1) AND ... AND z(p)
Each "AND" group contains 1 or more rules.

Therefore, to model "input" rules:
- store atomic rules in a table
- store "AND" rule groups in a table (1-n relation to the "atomic" table)
- store full rules in a table (1-n relation to the "AND" table)

Now you can model "output" rules likewise, and finally create a table of
associations between "input" and "output" rules

Problem is: once you've flattened your rules to the canonical form, they can
become illegible. So perhaps a hierarchical data model (XML) would be more
appropriate, for your rules would remain human-legible (and thererfore
human-maintainable)

HTH
Ignatius
_________________________
----- Original Message -----
From: "John" <ioannes@xxxxxxxxxxxxxx>
To: <php-db@xxxxxxxxxxxxx>
Sent: Friday, February 06, 2004 15:35
Subject:  Rules in a database


> I work in tax and thus have to read legislation - some complex - and I
> wanted to store some of the logic in a database so that if I know certain
> conditions were true I could look up what results this might have.
>
> Thus I am thinking of having two tables - one of phrases and the other of
> how these phrases are linked together as rules.  A rule structure could
be:
>
> IF A THEN B
> IF A OR A1 OR A2 THEN B
> IF A THEN B AND C
>
> I was wondering how to do this.  For instance, each rule could be one
record
> in the table.  The rules table has fields, IF and THEN. The ID field is
the
> rule ID.  Assume the phrases are numbered.  One IF record could say:
> +/12/41/31/+/90/ meaning if phrases 12, 41 or 31 are true and phrase 90 is
> true.  Then if I have a real situation where condition 12 is true, for
> instance, I can find it and access it using sub string functions. Does
this
> scheme seem OK?  Has anyone done anything like this before?
>
> Regards,
>
> John
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux