python-rule-engine
python-rule-engine copied to clipboard
Model list of dictionaries
How can I use list of dictionaries?
obj = {
"id": "123",
"sp1": {
"k1": 1.0,
"t1": [
{
"tc": "intro",
"t": "ty",
"s": "p"
},
{
"tc": "ola",
"t": "pls",
"s": "n"
}
]
},
"sp2": {
"k1": 1.9,
"t1": [
{
"tc": "contact",
"t": "get in touch with",
"s": "p"
},
{
"tc": "contact",
"t": "transfer the line",
"s": "p"
}
]
}
}
rule = {
"name": "basic_rule",
"conditions": {
"all": [
{
"path": "$.id",
"operator": "equal",
"value": "123"
},
{
"all": [
{
"path": "$.sp1[*].t1[*].tc",
"operator": "equal",
"value": "intro"
},
{
"path": "$.sp2[*].t1[*].tc",
"operator": "equal",
"value": "contact"
}
]
}
]
}
}
engine = RuleEngine([rule])
results = engine.evaluate(obj)
print("Scenario 5 : Multiple level 0 facts")
print("Scenario 5 results :" + str(results))