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

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

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

#list any import classes here.
import org.drools.verifier.components.Restriction;
import org.drools.verifier.components.PatternPossibility;

import org.drools.verifier.report.components.Opposites;

import org.drools.verifier.dao.VerifierResult;

#declare any global variables here
global VerifierResult result;


#
# Pattern possibilities are opposites if all of the restrictions are opposites.
#
# Dependencies:
#
#	Needs at least one of the following packages or rules to fire:
# 		package org.drools.verifier.opposites;
#			rule "Opposite LiteralRestrictions"
#			rule "Opposite LiteralRestrictions with ranges, greater or equal - less"
#			rule "Opposite LiteralRestrictions with ranges, greater - less or equal"
#			rule "Opposite LiteralRestrictions with ranges, less - greater for ints and dates"
#			rule "Opposite LiteralRestrictions with ranges, less or equal - greater or equal for ints and dates"
#
# Example: 
#			Pattern( a < b) 
#			Pattern( a >= b )
#
rule "Opposite Patterns"
	when
		$opposites :Opposites()
		
		$pp1 :PatternPossibility(
			items contains $opposites.left
		)
		
		$pp2 :PatternPossibility(
			items contains $opposites.right
		)
		
		# Check that these facts do not already exist
		not Opposites( left == $pp1, right == $pp2 )
		not Opposites( left == $pp2, right == $pp1 )
		
		# Check if all the restrictions in $pp1 have an opposite in $pp2.
		forall (
			$r1 :Restriction(
					this memberOf $pp1.items
			)
			
			Opposites( 
					left == $r1,
					right memberOf $pp2.items
			)
		)

		# Check if all the restrictions in $pp2 have an opposite in $pp1.
		forall (
			$r1 :Restriction(
					this memberOf $pp2.items
			)
			
			Opposites( 
					right == $r1,
					left memberOf $pp1.items
			)
		)
	then 
		# These two pattern possibilities are opposite.
		insert( new Opposites( $pp1, $pp2 ));
end




© 2015 - 2025 Weber Informatics LLC | Privacy Policy