Skip to content

Converting a decision table to a ruleset #401

@Dvzkabou

Description

@Dvzkabou

We are really enjoying the library as team functioning in credit and fraud decisioning areas.

Our clients are used to decision tables as found in Drools and Fico Blaze Advisor and we are trying the provide an equivalent.

we are using the json structures for definitions.

As the ruleset should return the first match, we are using the any operator - here is an example ruleset:

{'LoanApproval': {'any': {'r_0': {'run': <function RulesFactory.get_callback..callback at 0x000001C7172AD300>, 'all': [{'m': {'$eq': {'strategy': 'CHP'}}}, {'m': {'$gte': {'decile': 0}}}, {'m': {'$lte': {'decile': 39}}}]}, 'r_1': {'run': <function RulesFactory.get_callback..callback at 0x000001C7172AD1C0>, 'all': [{'m': {'$eq': {'strategy': 'CHP'}}}, {'m': {'$gte': {'decile': 40}}}, {'m': {'$lte': {'decile': 49}}}]}, 'r_2': {'run': <function RulesFactory.get_callback..callback at 0x000001C7172AD3A0>, 'all': [{'m': {'$eq': {'strategy': 'CHP'}}}, {'m': {'$gte': {'decile': 50}}}, {'m': {'$lte': {'decile': 49}}}]}, 'r_3': {'run': <function RulesFactory.get_callback..callback at 0x000001C7172AD620>, 'all': [{'m': {'$eq': {'strategy': 'CHP'}}}, {'m': {'$gte': {'decile': 60}}}, {'m': {'$lte': {'decile': 69}}}]}, 'r_4': {'run': <function RulesFactory.get_callback..callback at 0x000001C7172AD6C0>, 'all': [{'m': {'$eq': {'strategy': 'CHP'}}}, {'m': {'$gte': {'decile': 70}}}, {'m': {'$lte': {'decile': 99}}}]}, 'r_5': {'run': <function RulesFactory.get_callback..callback at 0x000001C7172AD760>, 'all': [{'m': {'$eq': {'strategy': 'CH1'}}}, {'m': {'$gte': {'decile': 0}}}, {'m': {'$lte': {'decile': 49}}}]}, 'r_6': {'run': <function RulesFactory.get_callback..callback at 0x000001C7172AD580>, 'all': [{'m': {'$eq': {'strategy': 'CH1'}}}, {'m': {'$gte': {'decile': 50}}}, {'m': {'$lte': {'decile': 49}}}]}, 'r_7': {'run': <function RulesFactory.get_callback..callback at 0x000001C7172AD800>, 'all': [{'m': {'$eq': {'strategy': 'CH1'}}}, {'m': {'$gte': {'decile': 60}}}, {'m': {'$lte': {'decile': 69}}}]}, 'r_8': {'run': <function RulesFactory.get_callback..callback at 0x000001C7172ACD60>, 'all': [{'m': {'$eq': {'strategy': 'CH1'}}}, {'m': {'$gte': {'decile': 70}}}, {'m': {'$lte': {'decile': 99}}}]}}}}

this is giving us error:
Error : 'run' when registering the ruleset

if we remove the any:
{'LoanApproval': {'r_0': {'run': <function RulesFactory.get_callback..callback at 0x000001F060ECCFE0>, 'all': [{'m': {'$eq': {'strategy': 'CHP'}}}, {'m': {'$gte': {'decile': 0}}}, {'m': {'$lte': {'decile': 39}}}]}, 'r_1': {'run': <function RulesFactory.get_callback..callback at 0x000001F060ECD080>, 'all': [{'m': {'$eq': {'strategy': 'CHP'}}}, {'m': {'$gte': {'decile': 40}}}, {'m': {'$lte': {'decile': 49}}}]}, 'r_2': {'run': <function RulesFactory.get_callback..callback at 0x000001F060ECD120>, 'all': [{'m': {'$eq': {'strategy': 'CHP'}}}, {'m': {'$gte': {'decile': 50}}}, {'m': {'$lte': {'decile': 59}}}]}, 'r_3': {'run': <function RulesFactory.get_callback..callback at 0x000001F060ECD1C0>, 'all': [{'m': {'$eq': {'strategy': 'CHP'}}}, {'m': {'$gte': {'decile': 60}}}, {'m': {'$lte': {'decile': 69}}}]}, 'r_4': {'run': <function RulesFactory.get_callback..callback at 0x000001F060ECD260>, 'all': [{'m': {'$eq': {'strategy': 'CHP'}}}, {'m': {'$gte': {'decile': 70}}}, {'m': {'$lte': {'decile': 99}}}]}, 'r_5': {'run': <function RulesFactory.get_callback..callback at 0x000001F060ECD300>, 'all': [{'m': {'$eq': {'strategy': 'CH1'}}}, {'m': {'$gte': {'decile': 0}}}, {'m': {'$lte': {'decile': 49}}}]}, 'r_6': {'run': <function RulesFactory.get_callback..callback at 0x000001F060ECD3A0>, 'all': [{'m': {'$eq': {'strategy': 'CH1'}}}, {'m': {'$gte': {'decile': 50}}}, {'m': {'$lte': {'decile': 59}}}]}, 'r_7': {'run': <function RulesFactory.get_callback..callback at 0x000001F060ECD440>, 'all': [{'m': {'$eq': {'strategy': 'CH1'}}}, {'m': {'$gte': {'decile': 60}}}, {'m': {'$lte': {'decile': 69}}}]}, 'r_8': {'run': <function RulesFactory.get_callback..callback at 0x000001F060ECD4E0>, 'all': [{'m': {'$eq': {'strategy': 'CH1'}}}, {'m': {'$gte': {'decile': 70}}}, {'m': {'$lte': {'decile': 99}}}]}}}

we get no rule matching as we suspect all rules need to be triggered

Can you advise?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions