Reputation: 1
I'm working on a Python rule engine that evaluates a set of rules against a given data set. The engine works fine when all the rule conditions are true, but I need to know when a rule condition is false and what data is causing it to be false. (Like which condition or rule is causing it)
Is there a way to modify the engine to identify false rule conditions and provide more detailed feedback on what data is causing the problem from UI if possible?
import rule_engine
# Create a rule to match a literal first name length and apply a regex for the condition on age.
rule = rule_engine.Rule(
'first_name.length > 5 and age > 16'
)
# Check if the rule matches the JSON data
data1 = {
'first_name': 'Luke Walker',
'last_name': 'Skywalker',
'email': '[email protected]',
'age': 25
}
data2 = {
'first_name': 'Luke',
'last_name': 'Vader',
'email': '[email protected]',
'age': 100
}
match1 = rule.matches(data1)
match2 = rule.matches(data2)
print(match1) # True
print(match2) # False here out of 2 conditions first one will fail so it shows
Can I now know where exactly it's breaking here because of the length of the first name is less than 5 the condition was evaluated as false. Here this is very minimal but when we have many rules and complex data can we identify that because of certain rule it's false if so can we find it and show it in UI? Here is the library used rule-engine
Upvotes: 0
Views: 166