decisionengine.framework.logicengine package

Subpackages

Submodules

decisionengine.framework.logicengine.BooleanExpression module

class decisionengine.framework.logicengine.BooleanExpression.BooleanExpression(expr)[source]

Bases: object

evaluate(d)[source]

Return the evaluated Boolean value of this expression in the context of the given data ‘d’.

exception decisionengine.framework.logicengine.BooleanExpression.LogicError[source]

Bases: TypeError

decisionengine.framework.logicengine.BooleanExpression.function_name_from_call(callnode)[source]
decisionengine.framework.logicengine.BooleanExpression.maybe_fail_on_error(expr)[source]

decisionengine.framework.logicengine.FactLookup module

class decisionengine.framework.logicengine.FactLookup.FactLookup(fact_names, rules_cfg)[source]

Bases: object

Establishes a policy for looking up a fact based on the given name.

To with, the first fact with a given name is the one that is used in the evaluation of all subsequent facts.

As an example, consider the following configuration:

{
    "facts": {
        "should_publish": "(True)"
    },
    "rules": {
        "publish_1": {
            "expression": "should_publish",
            "facts": ["should_publish"]
        },
        "publish_2": {
            "expression": "should_publish",
            "actions": ["go_to_press"],
            "facts": ["should_publish"]
        },
        "retract": {
            "expression": "not should_publish",
            "facts": ["should_retract"]
        }
    }
}

In the above, the first fact to be evaluated will always be the top-level facts (i.e. those not encapsulated by the ‘rules’ table). The rules labeled ‘publish_1’ and ‘publish_2’ both rely on the ‘should_publish’ fact in their expressions, and they in turn create their own facts with the same name. FactLookup ensures that ‘publish_1’ and ‘publish_2’ will both use the evaluated fact from the top-level ‘facts’ table.

rule_for(fact_name)[source]

Selects rule required to evaluate fact with the supplied name.

Parameters:

fact_name (str) – Name of fact for which rule will be selected.

Return type:

str

Returns:

Rule name

sorted_rules(rules_cfg)[source]

Rules sorted according to rule dependencies.

Parameters:

rules_cfg (dict) – rules as specified in logic-engine configuration

Return type:

list

Returns:

Rules to be evaluated by the rule engine.

decisionengine.framework.logicengine.LogicEngine module

class decisionengine.framework.logicengine.LogicEngine.LogicEngine(cfg)[source]

Bases: Module

_create_facts_dataframe(newfacts)[source]

Convert newfacts dict in format below to dataframe with columns [‘rule_name’, ‘fact_name’, fact_value’]

facts dict format:

{
    "newfacts": {
        "publish_glidein_requests": {
            "allow_hpc_new": true,
            "allow_foo": true
        },
        "dummy_rule": {
            "dummy_new_fact": true
        }
    }
}
consumes()[source]

Return the names of all the items that must be in the DataBlock for the rules to be evaluated.

evaluate(db)[source]

Evaluate our facts and rules, in the context of the given data. db can be any mappable, in particular a DataBlock or dictionary.

Parameters:

db (DataBlock) – Products used to evaluate facts.

evaluate_facts(db)[source]
Parameters:

db (DataBlock) – Products used to evaluate facts.

Return type:

dict

Returns:

Evaluated fact values (e.g. True or False) for each fact name.

produces()[source]
decisionengine.framework.logicengine.LogicEngine.passthrough_configuration(publisher_names)[source]

Assembles logic-engine configuration to unconditionally execute all publishers.

decisionengine.framework.logicengine.Rule module

class decisionengine.framework.logicengine.Rule.Rule(rule_name, rule_cfg)[source]

Bases: object

In-memory representation of logic-engine rule, relying on parsing utilities in BooleanExpression.

evaluate(evaluated_facts)[source]

Evaluates a compiled expression given the supplied facts.

Parameters:

evaluated_facts (dict) – Initial fact values (e.g. True or False) for each fact name.

Return type:

bool

decisionengine.framework.logicengine.RuleEngine module

class decisionengine.framework.logicengine.RuleEngine.RuleEngine(fact_names, rules_cfg)[source]

Bases: object

Engine responsible for evaluating logic-engine rules.

This class is responsible for (a) forming a sorted set of rules that supports dependencies between them, and (b) evaluating the rules according to a specified fact-lookup policy.

execute(evaluated_facts)[source]

Evaluates all rules given the supplied facts.

Parameters:

evaluated_facts (dict) – Initial fact values (e.g. True or False) for each fact name.

Return type:

tuple

Returns:

Actions to be taken based on rule evaluation; new facts produced during that evaluation.

Module contents