All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.drools.verifier.redundancy.Warnings.drl Maven / Gradle / Ivy

There is a newer version: 9.44.0.Final
Show newest version
#created on: 9.12.2007
package org.drools.verifier.redundancy

#list any import classes here.
global VerifierResult result;



#declare any global variables here
import java.util.Collection;
import java.util.ArrayList;

import org.drools.verifier.components.RulePossibility;
import org.drools.verifier.dao.VerifierResult;
import org.drools.verifier.report.components.Redundancy;
import org.drools.verifier.report.components.RedundancyType;
import org.drools.verifier.report.components.VerifierMessage;
import org.drools.verifier.report.components.Cause;
import org.drools.verifier.report.components.CauseType;
import org.drools.verifier.report.components.Severity;
import org.drools.verifier.report.components.MessageType;

#
# Dependencies:
#
#	Needs at least one rule from these packages:
#		package org.drools.verifier.equivalency.rules
#			rule "Find equivalent Rules"
#		package org.drools.verifier.redundancy.rules
#			rule "Find redundant Rules, strong redundancy"
#
#	And this rule:
#		package org.drools.verifier.redundancy.possibilities
#			rule "Find rule possibility redundancy"
#
rule "Find redundant rule possibilities from different rules"
	salience -100
	when
		$ruleRedundancy :Redundancy(
			left.causeType == CauseType.RULE
		)

		$rulePossibilityRedundancy :Redundancy(
			left.causeType == CauseType.RULE_POSSIBILITY
		)

		# Check that redundant possibilities are from redundant rules
		exists RulePossibility(
			this == $rulePossibilityRedundancy.left,
			eval( ruleId == $ruleRedundancy.getLeft().getId() )
		)

		exists RulePossibility(
			this == $rulePossibilityRedundancy.right,
			eval( ruleId == $ruleRedundancy.getRight().getId() )
		)

		# Check that the possibilties are redundant to each other.
		exists Redundancy(
			left.causeType == CauseType.RULE_POSSIBILITY,
			left == $rulePossibilityRedundancy.right,
			right == $rulePossibilityRedundancy.left
		)

	then
		Collection causes = new ArrayList();
		causes.add( $rulePossibilityRedundancy.getLeft() );
		causes.add( $rulePossibilityRedundancy.getRight() );

		String message;
		if( $ruleRedundancy.getType() == RedundancyType.WEAK ) {
			message = "Rules are equivalent.";
		} else {
			message = "Rules are redundant.";
		}

		result.add(new VerifierMessage(
						Severity.WARNING, MessageType.REDUNDANCY,
						$rulePossibilityRedundancy, message, causes ) );
end

#
# Dependencies:
#
#	Needs at least one rule from these packages:
#		package org.drools.verifier.equivalency.rules
#			rule "Find equivalent Rules"
#		package org.drools.verifier.redundancy.rules
#			rule "Find redundant Rules, strong redundancy"
#
#	And this rule:
#		package org.drools.verifier.redundancy.possibilities
#			rule "Find rule possibility redundancy"
#
rule "Find subsumptant rule possibilities from different rules"
	salience -100
	when
		$ruleRedundancy :Redundancy(
			left.causeType == CauseType.RULE
		)

		$rulePossibilityRedundancy :Redundancy(
			left.causeType == CauseType.RULE_POSSIBILITY
		)

		# Check that redundant possibilities are from redundant rules
		exists RulePossibility(
			this == $rulePossibilityRedundancy.left,
			eval( ruleId == $ruleRedundancy.getLeft().getId() )
		)

		exists RulePossibility(
			this == $rulePossibilityRedundancy.right,
			eval( ruleId == $ruleRedundancy.getRight().getId() )
		)

		# Check that the left side is redundant to right, but the right side is not redudant to left.
		not Redundancy(
			left.causeType == CauseType.RULE_POSSIBILITY,
			left == $rulePossibilityRedundancy.right,
			right == $rulePossibilityRedundancy.left
		)

	then
		Collection causes = new ArrayList();
		causes.add( $rulePossibilityRedundancy.getLeft() );
		causes.add( $rulePossibilityRedundancy.getRight() );

		result.add(new VerifierMessage(
						Severity.WARNING, MessageType.REDUNDANCY,
						$rulePossibilityRedundancy, "Rules are subsumptant.", causes ) );
end




© 2015 - 2025 Weber Informatics LLC | Privacy Policy