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

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

There is a newer version: 9.44.0.Final
Show newest version
#
# created on: 27.6.2008
#
# Rules in this package look for patterns and rules that are always satisfied.
#
#
package org.drools.verifier.alwaysTrue


import org.drools.verifier.components.Restriction;
import org.drools.verifier.components.Pattern;
import org.drools.verifier.components.PatternPossibility;
import org.drools.verifier.components.VerifierRule;

import org.drools.verifier.report.components.AlwaysTrue;
import org.drools.verifier.report.components.Opposites;
import org.drools.verifier.report.components.VerifierMessage;
import org.drools.verifier.report.components.Severity;
import org.drools.verifier.report.components.MessageType;

import org.drools.verifier.dao.VerifierResult;

global VerifierResult result;



rule "Pattern possibility that is always true"
	when
		a :Restriction()
		b :Restriction()
		$pp :PatternPossibility()
		
		Opposites(
			(
				left == a && right memberOf $pp.items
			) && (
				left == b && right memberOf $pp.items
			)
		)
	then 
		insert( new AlwaysTrue( $pp ));
end
/*
#
# Finds pattern possibilities that are always true.
#
# Dependencies: None
#
# Example:
#		Pattern( a > 10 && a <= 10 )
#
rule "Pattern possibility that is always true"
	when
		$p :Pattern()
		
		$pp :PatternPossibility(
			patternId == $p.id
		)

		# For each restriction in pattern possibility 
		# there needs to be an opposite.
		forall(
			$r :Restriction(
				this memberOf $pp.items
			)
			
			Opposites( 
				(
					left == $r
				&&
					right memberOf $pp.items
				) || (
					left memberOf $pp.items
				&&
					right == $r
				)
			)
		)
	then 
		insert( new AlwaysTrue( $pp ));
end
*/
#
# Finds patterns that are always true.
#
# Dependencies:
#	Needs at least one of the following packages or rules to fire:
# 		package org.drools.verifier.alwaysTrue;
#			rule "Pattern possibility that is always true"
#
# Example:
#		Pattern( a > 10 && a <= 10 )
#
rule "Pattern that is always true"
	when
		$p :Pattern()

		# Only report the ones that have restrictions.
		exists PatternPossibility( patternId == $p.id )
		
		# For each restriction in each pattern possibility for current pattern, 
		# there needs to be an opposite.
		forall(
			$pp :PatternPossibility(
				patternId == $p.id
			)
			
			AlwaysTrue(
				cause == $pp
			)
		)
		
		$r :VerifierRule( id == $p.ruleId )
	then 
		result.add( new VerifierMessage(
								Severity.NOTE,
								MessageType.ALWAYS_TRUE,
								$p,
								$p + " in rule " + $r + " is always satisfied." ) );
end




© 2015 - 2025 Weber Informatics LLC | Privacy Policy