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

org.drools.verifier.rangeChecks.Clean.drl Maven / Gradle / Ivy

There is a newer version: 9.44.0.Final
Show newest version
#created on: 24.9.2007
package org.drools.verifier.rangeChecks.cleanUp

import org.drools.base.evaluators.Operator;

import org.drools.verifier.components.*;  
import org.drools.verifier.report.components.Gap;  
import org.drools.verifier.report.components.MissingNumberPattern;

import org.drools.verifier.dao.VerifierResult;

#declare any global variables here
global VerifierResult result;

#
# Merges existing gaps from working memory. Cleans out the data for actual reporting.
#
# Type: None
# Dependencies: Needs at least one of the following packages or rules to fire.
#
# 		package org.drools.verifier.rangeChecks.patterns;
#			rule "Range check for number patterns"
#			rule "Range check for number patterns, !="
#		package org.drools.verifier.rangeChecks.integers
#			rule "Range check for integers, if smaller than or equal is missing"
#			rule "Range check for integers, if greater than or equal is missing"
#			rule "Range check for integers, equal and greater than"
#			rule "Range check for integers, equal and smaller than"
#		package org.drools.verifier.rangeChecks.doubles
#			rule "Range check for doubles, if smaller than or equal is missing"
#			rule "Range check for doubles, if greater than or equal is missing"
#			rule "Range check for doubles, equal and greater than"
#			rule "Range check for doubles, equal and smaller than"
#		package org.drools.verifier.rangeChecks.dates
#			rule "Range check for dates, if smaller than or equal is missing"
#			rule "Range check for dates, if greater than or equal is missing"
#			rule "Range check for dates, equal and greater than"
#			rule "Range check for dates, equal and smaller than"
#
# Example: missing ( x >= 10 ) and ( x <= 10 ). This is the same as ( x == 10 )
#
rule "Merge gaps"
	when
		$g1 :Gap(
			operator == Operator.GREATER_OR_EQUAL
		)
		$g2 :Gap( 
			id != $g1.id,
			field == $g1.field,
			operator == Operator.LESS_OR_EQUAL,
			valueAsString == $g1.valueAsString
		)		
	then	
		result.remove( $g1 );
		result.remove( $g2 );
		retract( $g1 );
		retract( $g2 );
		
		MissingNumberPattern mnp = new MissingNumberPattern( 
											$g1.getField(), 
											Operator.EQUAL, 
											$g1.getField().getFieldType(), 
											$g1.getValueAsString() );
		result.add( mnp );
		insert( mnp );
end

#
# Removes existing gaps from working memory. Cleans out the data for actual reporting.
#
# Type: None
# Dependencies: Needs at least one of the following packages or rules to fire.
#
#		package org.drools.verifier.rangeChecks.integers
#			rule "Range check for integers, if smaller than or equal is missing"
#			rule "Range check for integers, if greater than or equal is missing"
#			rule "Range check for integers, equal and greater than"
#			rule "Range check for integers, equal and smaller than"
#
# Example: covered ( x > 10 ), ( x > 70 ) ( x < 100 )and ( x == 50 )
# 			reports that ( x < 50 ), ( x > 50 ) and ( x <= 70 ) is missing.
#
rule "Remove useless integer gaps lesser or lesser and equal"
	when
		# Covered x > 10
		$lower :LiteralRestriction( 
			valueType == Field.FieldType.INT,
			( operator == Operator.GREATER || == Operator.GREATER_OR_EQUAL)
		)

		# Covered x < 100
		$higher :LiteralRestriction( 
			fieldId == $lower.fieldId,
			intValue > $lower.intValue,
			patternIsNot == $lower.patternIsNot,
			( operator == Operator.LESS || == Operator.LESS_OR_EQUAL)
		)
		
		# No "<" or "<=" restrictions between these two
		not LiteralRestriction( 
			( operator == Operator.LESS_OR_EQUAL || == Operator.LESS ),
			fieldId == $lower.fieldId,
			patternIsNot == $lower.patternIsNot, 
			intValue > $lower.intValue,
			intValue < $higher.intValue
		)

		# gap ( x < 50 ) or ( x > 50 ) or ( x <= 70 )
		$gap :Gap(
			restriction.fieldId == $lower.fieldId,
			restriction.patternIsNot == $lower.patternIsNot,
			restriction.intValue > $lower.intValue,
			restriction.intValue < $higher.intValue
		)
	then
		retract( $gap );
		result.remove( $gap );
end

#
# Removes existing gaps from working memory. Cleans out the data for actual reporting.
#
# Type: None
# Dependencies: Needs at least one of the following packages or rules to fire.
#
#		package org.drools.verifier.rangeChecks.integers
#			rule "Range check for integers, if smaller than or equal is missing"
#			rule "Range check for integers, if greater than or equal is missing"
#			rule "Range check for integers, equal and greater than"
#			rule "Range check for integers, equal and smaller than"
#
# Example: covered ( x > 10 ), ( x < 70 ) ( x < 100 )and ( x == 50 )
#			reports that ( x < 50 ), ( x > 50 ) and ( x >= 70 ) is missing.
#
rule "Remove useless integer gaps greater or greater and equal"
	when
		# Covered x > 10
		$lower :LiteralRestriction( 
			valueType == Field.FieldType.INT,
			( operator == Operator.GREATER || == Operator.GREATER_OR_EQUAL)
		)

		# Covered x < 100
		$higher :LiteralRestriction( 
			fieldId == $lower.fieldId,
			intValue > $lower.intValue,
			patternIsNot == $lower.patternIsNot,
			( operator == Operator.LESS || == Operator.LESS_OR_EQUAL)
		)
		
		# No "<" or "<=" restrictions between these two
		not LiteralRestriction( 
			( operator == Operator.GREATER_OR_EQUAL || == Operator.GREATER ),
			fieldId == $lower.fieldId,
			patternIsNot == $lower.patternIsNot, 
			intValue > $lower.intValue,
			intValue < $higher.intValue
		)

		# gap ( x < 50 ) or ( x > 50 ) or ( x >= 70 )
		$gap :Gap(
			restriction.fieldId == $lower.fieldId,
			restriction.patternIsNot == $lower.patternIsNot,
			restriction.intValue > $lower.intValue,
			restriction.intValue < $higher.intValue
		)
	then
		retract( $gap );
		result.remove( $gap );
end

#
# Removes existing gaps from working memory. Cleans out the data for actual reporting.
#
# Type: None
# Dependencies: Needs at least one of the following packages or rules to fire.
#
#		package org.drools.verifier.rangeChecks.doubles
#			rule "Range check for doubles, if smaller than or equal is missing"
#			rule "Range check for doubles, if greater than or equal is missing"
#			rule "Range check for doubles, equal and greater than"
#			rule "Range check for doubles, equal and smaller than"
#
# Example: covered ( x > 10.0 ), ( x > 70.0 ) ( x < 100.0 )and ( x == 50.0 )
# 			reports that ( x < 50.0 ), ( x > 50.0 ) and ( x <= 70.0 ) is missing.
#
rule "Remove useless double gaps lesser or lesser and equal"
	when
		# Covered x > 10.0
		$lower :LiteralRestriction( 
			valueType == Field.FieldType.DOUBLE,
			( operator == Operator.GREATER || == Operator.GREATER_OR_EQUAL)
		)

		# Covered x < 100.0
		$higher :LiteralRestriction( 
			fieldId == $lower.fieldId,
			doubleValue > $lower.doubleValue,
			patternIsNot == $lower.patternIsNot,
			( operator == Operator.LESS || == Operator.LESS_OR_EQUAL)
		)
		
		# No "<" or "<=" restrictions between these two
		not LiteralRestriction( 
			( operator == Operator.LESS_OR_EQUAL || == Operator.LESS ),
			fieldId == $lower.fieldId,
			patternIsNot == $lower.patternIsNot, 
			doubleValue > $lower.doubleValue,
			doubleValue < $higher.doubleValue
		)

		# gap ( x < 50.0 ) or ( x > 50.0 ) or ( x <= 70.0 )
		$gap :Gap(
			restriction.fieldId == $lower.fieldId,
			restriction.patternIsNot == $lower.patternIsNot,
			restriction.doubleValue > $lower.doubleValue,
			restriction.doubleValue < $higher.doubleValue
		)
	then
		retract( $gap );
		result.remove( $gap );
end

#
# Removes existing gaps from working memory. Cleans out the data for actual reporting.
#
# Type: None
# Dependencies: Needs at least one of the following packages or rules to fire.
#
#		package org.drools.verifier.rangeChecks.doubles
#			rule "Range check for doubles, if smaller than or equal is missing"
#			rule "Range check for doubles, if greater than or equal is missing"
#			rule "Range check for doubles, equal and greater than"
#			rule "Range check for doubles, equal and smaller than"
#
# Example: covered ( x > 10.0 ), ( x < 70.0 ) ( x < 100.0 )and ( x == 50.0 )
# reports that ( x < 50.0 ), ( x > 50.0 ) and ( x >= 70.0 ) is missing.
#
rule "Remove useless double gaps greater or greater and equal"
	when
		# Covered x > 10.0
		$lower :LiteralRestriction( 
			valueType == Field.FieldType.DOUBLE,
			( operator == Operator.GREATER || == Operator.GREATER_OR_EQUAL)
		)

		# Covered x < 100.0
		$higher :LiteralRestriction( 
			fieldId == $lower.fieldId,
			doubleValue > $lower.doubleValue,
			patternIsNot == $lower.patternIsNot,
			( operator == Operator.LESS || == Operator.LESS_OR_EQUAL)
		)
		
		# No "<" or "<=" restrictions between these two
		not LiteralRestriction( 
			( operator == Operator.GREATER_OR_EQUAL || == Operator.GREATER ),
			fieldId == $lower.fieldId,
			patternIsNot == $lower.patternIsNot, 
			doubleValue > $lower.doubleValue,
			doubleValue < $higher.doubleValue
		)

		# gap ( x < 50.0 ) or ( x > 50.0 ) or ( x >= 70.0 )
		$gap :Gap(
			restriction.fieldId == $lower.fieldId,
			restriction.patternIsNot == $lower.patternIsNot,
			restriction.doubleValue > $lower.doubleValue,
			restriction.doubleValue < $higher.doubleValue
		)
	then
		retract( $gap );
		result.remove( $gap );
end

#
# Removes existing gaps from working memory. Cleans out the data for actual reporting.
#
# Type: None
# Dependencies: Needs at least one of the following packages or rules to fire.
#
#		package org.drools.verifier.rangeChecks.dates
#			rule "Range check for dates, if smaller than or equal is missing"
#			rule "Range check for dates, if greater than or equal is missing"
#			rule "Range check for dates, equal and greater than"
#			rule "Range check for dates, equal and smaller than"
#
# Example: covered ( x > "01-Oct-2007" ), ( x > "15-Oct-2007" ) ( x < "20-Oct-2007" )and ( x == "10-Oct-2007" )
# reports that ( x < "10-Oct-2007" ), ( x > "10-Oct-2007" ) and ( x <= "15-Oct-2007" ) is missing.
#
rule "Remove useless date gaps lesser or lesser and equal"
	when
		# Covered x > "01-Oct-2007"
		$lower :LiteralRestriction( 
			valueType == Field.FieldType.DATE,
			( operator == Operator.GREATER || == Operator.GREATER_OR_EQUAL)
		)

		# Covered x < "20-Oct-2007"
		$higher :LiteralRestriction( 
			fieldId == $lower.fieldId,
			patternIsNot == $lower.patternIsNot,
			( operator == Operator.LESS || == Operator.LESS_OR_EQUAL),
			eval( dateValue.after( $lower.getDateValue() ) )
		)
		
		# No "<" or "<=" restrictions between these two
		not LiteralRestriction( 
			( operator == Operator.LESS_OR_EQUAL || == Operator.LESS ),
			fieldId == $lower.fieldId,
			patternIsNot == $lower.patternIsNot, 
			eval( dateValue.after( $lower.getDateValue() ) ),
			eval( dateValue.before( $higher.getDateValue() ) )
		)

		# gap ( x < "10-Oct-2007" ) or ( x > "10-Oct-2007" ) or ( x <= "15-Oct-2007" )
		$gap :Gap(
			restriction.fieldId == $lower.fieldId,
			restriction.patternIsNot == $lower.patternIsNot,
			eval( restriction.getDateValue().after( $lower.getDateValue() ) ),
			eval( restriction.getDateValue().before( $higher.getDateValue() ) )
		)
	then
		retract( $gap );
		result.remove( $gap );
end

#
# Removes existing gaps from working memory. Cleans out the data for actual reporting.
#
# Type: None
# Dependencies: Needs at least one of the following packages or rules to fire.
#
#		package org.drools.verifier.rangeChecks.dates
#			rule "Range check for dates, if smaller than or equal is missing"
#			rule "Range check for dates, if greater than or equal is missing"
#			rule "Range check for dates, equal and greater than"
#			rule "Range check for dates, equal and smaller than"
#
# Example: covered ( x > "01-Oct-2007" ), ( x < "15-Oct-2007" ) ( x < "20-Oct-2007" )and ( x == "10-Oct-2007" )
# reports that ( x < "10-Oct-2007" ), ( x > "10-Oct-2007" ) and ( x >= "15-Oct-2007" ) is missing.
#
rule "Remove useless date gaps greater or greater and equal"
	when
		# Covered x > "01-Oct-2007"
		$lower :LiteralRestriction( 
			valueType == Field.FieldType.DATE,
			( operator == Operator.GREATER || == Operator.GREATER_OR_EQUAL)
		)

		# Covered x < "20-Oct-2007"
		$higher :LiteralRestriction( 
			fieldId == $lower.fieldId,
			patternIsNot == $lower.patternIsNot,
			( operator == Operator.LESS || == Operator.LESS_OR_EQUAL),
			eval( dateValue.after( $lower.getDateValue() ) )
		)
		
		# No ">" or ">=" restrictions between these two
		not LiteralRestriction( 
			( operator == Operator.GREATER_OR_EQUAL || == Operator.GREATER ),
			fieldId == $lower.fieldId,
			patternIsNot == $lower.patternIsNot,
			eval( dateValue.after( $lower.getDateValue() ) ),
			eval( dateValue.before( $higher.getDateValue() ) )
		)

		# gap ( x < "10-Oct-2007" ) or ( x > "10-Oct-2007" ) or ( x >= "15-Oct-2007" )
		$gap :Gap(
			restriction.fieldId == $lower.fieldId,
			restriction.patternIsNot == $lower.patternIsNot,
			eval( restriction.getDateValue().after( $lower.getDateValue() ) ),
			eval( restriction.getDateValue().before( $higher.getDateValue() ) )
		)
	then
		retract( $gap );
		result.remove( $gap );
end




© 2015 - 2025 Weber Informatics LLC | Privacy Policy