Module (SVN) name: drools-verifier
Verifier rules itself (eat our own dog food) to statically analyse and produce a report that can be displayed to the user with info on the quality of a knowledge package
How it works
Verifier takes in the Drools resources. Internally it examines the Drools AST. It will break it apart into a flat structure and figures out component relations for the validation rules to reason over.
Items that the Verifier rules looks for
- Range validation (missing ranges, making sure they are all covered)
- Missing equality (when there are inequalities, but not equality being catered for)
- Redundancy (when 2 rules have the same LHS and RHS - but with different attributes and names possibly)
- Subsumption: when there multiple rules that have the same RHS, and the LHS has some overlapping conditions
- Rule equivalence (rule A is equivalent with rule B)
- Rule incoherence (nothing can meet rule A) - eg if there are some constraints that contradict themselves. (a == b && a != b etc
- Warn if excessive use of "eval": if all rules in a set consist entirely (mostly) of eval statements, that is problem
- If an eval is used, it should be after any fact patterns are declared.
- Check that rule has an action.
- Rule optimization
- Rules and Patterns that are always satisfied. Pattern( a > b || a <= b )
Items that the Verifier rules will look for
These are the items that are planned.
- Rule combination
- Rule deduction
- Rule "compression
- Warn for combination explosion: if a rule has multiple fact patterns of the same type with no constraints, then warn users (it may not be a problem).
- Loop warning: if a rule modifies a fact that is bound on the LHS, and has no constraints on the LHS, and there is no no-loop attribute, then warn about a infinite loop.
- Excessive use of salience
- Rule incompatibility (if x meets rule A then it cannot meet rule B)
- Dominance checking (rule A is dominated by ruleSet S if the addition of rule A does not alter the behaviour of the system, i.e. find redundant rules)
- Rule conflict (rule A and B are in conflict is they cannot be satisfied simultaneously in a certain circumstance)
- Coverage checking (check whether a rule is defined for a certain circumstance)
- Pattern that is not placed in to a variable and has no restrictions. Like TestPattern(), should probably have an exists or not
- Person( age == age ) or Person( age > age ) user is compares two values from two person facts and forgets to use $person1.age in the pattern. There should be a warning for this.
How the results will be presented
Verifier returns the VerifierReport object that contains the verifier messages that the verification rules produce.
Three Verification message types
Notes: needs attention, may be ignored
Warnings: possible problem, usually may be an alternative way
- Errors: needs correction, logical falacy etc.
How to use
Ant task
Guvnor
Using Java
// Create verifier builder [1]
VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
// Create verifier [2]
Verifier verifier = vBuilder.newVerifier();
// Add Resources you want to verify [3]
verifier.addResourcesToVerify( new ClassPathResource( "TestFile.drl",ThisClass.class ),ResourceType.DRL );
// Run the verification rules [4]
verifier.fireAnalysis();
// Get the result object [5]
VerifierReport result = verifier.getResult();
// Print the the errors [6]
for(VerifierMessageBase base: result.getBySeverity( Severity.ERROR ) ){
System.out.println( base );
}
- Creates the builder. You can pass VerifierBuilderConfiguration as a parameter if you want something else than the default set of verfication rules.
- Creates the Verifier
- Add the resources you want to verify. In this case we are just verifying one DRL file.
- Runs the verification rules
- Returns the verifier report object that contains information about all the issues in the TestFile.drl file.
- Prints all the errors. There are 3 levels of severity (ERROR, WARNING, NOTIFICATION).
Links
Some info: http://citeseer.ist.psu.edu/515931.html
Esteban's Blog - Guvnor's Field Constraints: http://ilesteban.wordpress.com/2010/04/05/guvnors-field-constraints/
Comments