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

org.drools.verifier.subsumption.Possibilities.drl Maven / Gradle / Ivy

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

import org.drools.verifier.components.Restriction;
import org.drools.verifier.components.Pattern;
import org.drools.verifier.components.PatternPossibility;
import org.drools.verifier.components.RulePossibility;
import org.drools.verifier.report.components.Redundancy;
import org.drools.verifier.report.components.Subsumption;
import org.drools.verifier.report.components.CauseType;
import org.drools.verifier.report.components.RedundancyType;


#declare any global variables here

#
# Fires when two pattern possibilities are subsumptant.
# Creates a Subsumption object.
#
# Dependencies: Needs at least one rule.
#
#		package org.drools.verifier.redundancy.patterns
#			rule "Find redundant Patterns with restrictions"
#			rule "Find redundant Patterns without restrictions"
#
# Example 1: P( x == 10 ) and P( x == 10 && y == 20 )
#
rule "Find subsumptant pattern possibilities"
	when
		
		$redundancy :Redundancy(
			left.causeType == CauseType.PATTERN
		)

		# Find two PatternPossibilities.
		$pp1 :PatternPossibility(
			eval( patternId == $redundancy.getLeft().getId() )
		)
		$pp2 :PatternPossibility(
			eval( patternId == $redundancy.getRight().getId() )
		)		
		
		# For every restriction in $pp1 there is a redundancy to restriction in $pp2.
		forall(
			$r :Restriction(
				this memberOf $pp1.items
			)

			Subsumption(
				left == $r,
				right memberOf $pp2.items
			)
		)
		
		# There is no restriction on $pp2 that has no redundancy in $pp1 
		# and has a lower order number than an existing redundancy from $pp2 to $pp1.
		not(
				$r1 :Restriction(
					this memberOf $pp2.items
				)
			and
				$r2 :Restriction(
					this memberOf $pp2.items,
					orderNumber > $r1.orderNumber
				)
			and
				not Subsumption(
					left memberOf $pp1.items,
					right == $r1
				)
			and
				Subsumption(
					left memberOf $pp1.items,
					right == $r2
				)
		)

	then
		insert( new Subsumption( $pp1, $pp2 ) );
end

#
# Fires when two pattern possibilities are subsumptant.
# Creates a Subsumption object.
#
# Dependencies: Needs at least one rule from either one of the following packages.
#
#		package org.drools.verifier.subsumption.patterns
#			rule "Find subsumptant pattern possibilities"
#
#		package org.drools.verifier.redundancy.patterns
#			rule "Find redundant Patterns with restrictions"
#			rule "Find redundant Patterns without restrictions"
#
rule "Find subsumptant rule possibilities"
	when
		
		$redundancy :Redundancy(
			left.causeType == CauseType.RULE
		)

		# Find two RulePossibilities.
		$rp1 :RulePossibility(
			eval( ruleId == $redundancy.getLeft().getId() )
		)
		$rp2 :RulePossibility(
			eval( ruleId == $redundancy.getRight().getId() )
		)
		
		# For every PatternPossibility in $rp1 there is a redundancy to PatternPossibility in $rp2.
		forall(
			$pp :PatternPossibility(
				this memberOf $rp1.items
			)

			Subsumption(
				left == $pp,
				right memberOf $rp2.items
			)
		)
		
		# There is no PatternPossibility on $rp2 that has no redundancy in $rp1 
		# and has a lower order number than an existing PatternPossibility from $rp2 to $rp1.
		not(
				$pp1 :PatternPossibility(
					this memberOf $rp2.items
				)
			and
				$pp2 :PatternPossibility(
					this memberOf $rp2.items,
					orderNumber > $pp1.orderNumber
				)
			and
				not Subsumption(
					left memberOf $rp1.items,
					right == $pp1
				)
			and
				Subsumption(
					left memberOf $rp1.items,
					right == $pp2
				)
		)
	then
		insert( new Subsumption( $rp1, $rp2 ) );
end






© 2015 - 2025 Weber Informatics LLC | Privacy Policy