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

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

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

import org.drools.verifier.components.*;
import org.drools.verifier.report.components.Redundancy;
import org.drools.verifier.report.components.RedundancyType;

#
# Only checks for redundant pattern specifications,
# does not include actual restriction checks.
#
# Dependencies: None
#
rule "Find redundant Patterns with restrictions"
	when
		# Check that Patterns $left and $right have redundant fields.
		$left :Pattern()
		$right :Pattern(
			id != $left.id,
	  		objectTypeId == $left.objectTypeId,
	  		# TODO: In some cases the source might be redundant with different sources.
	 		sourceType == $left.sourceType,
	  		sourceId == $left.sourceId,
	  		patternNot == $left.patternNot,
	  		patternExists == $left.patternExists,
	  		patternForall == $left.patternForall
		)

		# Has possibilities, if the there is no possibilities,
		# then the Redundancy type is STRONG.
		# Because these patterns have no restrictions.
		exists PatternPossibility( patternId == $left.id )
		exists PatternPossibility( patternId == $right.id )

		# Check that there is not already a pair with these values.
		not Redundancy(
			left == $left,
			right == $right
		)
		not Redundancy(
			left == $right,
			right == $left
		)
	then
		insert( new Redundancy( RedundancyType.WEAK, $left, $right ) );
end

#
# Checks for redundant pattern specifications when the patterns have no possibilities.
#
# Dependencies: None
#
rule "Find redundant Patterns without restrictions"
	when
		# Check that Patterns $left and $right have redundant fields.
		$left :Pattern()
		$right :Pattern(
			id != $left.id,
	  		objectTypeId == $left.objectTypeId,
	  		# TODO: In some cases the source might be redundant with different sources.
	 		sourceType == $left.sourceType,
	  		sourceId == $left.sourceId,
	  		patternNot == $left.patternNot,
	  		patternExists == $left.patternExists,
	  		patternForall == $left.patternForall
		)

		# Not possibilities
		not PatternPossibility( patternId == $left.id )
		not PatternPossibility( patternId == $right.id )

		# Check that there is not already a pair with these values.
		not Redundancy(
			left == $left,
			right == $right
		)
		not Redundancy(
			left == $right,
			right == $left
		)
	then
		insert( new Redundancy( RedundancyType.STRONG, $left, $right ) );
end




© 2015 - 2025 Weber Informatics LLC | Privacy Policy