org.drools.verifier.opposites.Restrictions.drl Maven / Gradle / Ivy
/*
* Copyright 2010 JBoss Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//created on: 23.02.2008
package org.drools.verifier.opposites
//list any import classes here.
import org.drools.verifier.components.LiteralRestriction;
import org.drools.verifier.components.NumberRestriction;
import org.drools.verifier.components.VariableRestriction;
import org.drools.verifier.components.Field;
import org.drools.verifier.report.components.Cause;
import org.drools.verifier.report.components.MissingRange;
import org.drools.verifier.report.components.Severity;
import org.drools.verifier.report.components.MessageType;
import org.drools.verifier.report.components.Opposites;
import org.drools.verifier.report.components.MissingRange;
import org.drools.verifier.data.VerifierReport;
import org.drools.base.evaluators.Operator;
//declare any global variables here
global VerifierReport result;
//
// If two LiteralRestrictions are in conflict.
//
// Dependencies: None
// Example: Pattern( a == "b", a != "b" )
//
rule "Opposite LiteralRestrictions"
when
$left :LiteralRestriction(
# Not >= and <=, because ( a <=, a >= ) works.
# And not < or > because they are handled in a separate rule.
( operator != Operator.GREATER_OR_EQUAL || != Operator.LESS_OR_EQUAL || != Operator.LESS || != Operator.GREATER )
)
$right :LiteralRestriction(
fieldPath == $left.fieldPath,
valueType == $left.valueType,
path != $left.path,
# Operator needs to be reversed to what the other one has.
eval( operator == MissingRange.getReversedOperator( $left.getOperator() )),
valueAsString == $left.valueAsString
)
# Check that there is not already a pair with these values.
not Opposites(
left == $left,
right == $right
)
not Opposites(
right == $left,
left == $right
)
then
System.out.println( $left + " " + $right );
insert( new Opposites( $left, $right ));
end
//
// If two LiteralRestrictions are in conflict.
//
// Dependencies: None
// Example: Pattern( a >= 10 && a < 10 )
//
rule "Opposite LiteralRestrictions with ranges, greater or equal - less"
when
$left :LiteralRestriction(
operator == Operator.GREATER_OR_EQUAL
)
$right :LiteralRestriction(
restrictionType == $left.restrictionType,
fieldPath == $left.fieldPath,
valueType == $left.valueType,
operator == Operator.LESS,
path != $left.path,
valueAsString == $left.valueAsString
)
# Check that there is not already a pair with these values.
not Opposites(
left == $left,
right == $right
)
not Opposites(
right == $left,
left == $right
)
then
insert( new Opposites( $left, $right ));
end
//
// If two LiteralRestrictions are in conflict.
//
// Dependencies: None
// Example: Pattern( a > 10 && a <= 10 )
//
rule "Opposite LiteralRestrictions with ranges, greater - less or equal"
when
$left :LiteralRestriction(
operator == Operator.GREATER
)
$right :LiteralRestriction(
restrictionType == $left.restrictionType,
fieldPath == $left.fieldPath,
valueType == $left.valueType,
operator == Operator.LESS_OR_EQUAL,
path != $left.path,
valueAsString == $left.valueAsString
)
# Check that there is not already a pair with these values.
not Opposites(
left == $left,
right == $right
)
not Opposites(
right == $left,
left == $right
)
then
insert( new Opposites( $left, $right ));
end
//
// If two LiteralRestrictions are in conflict.
//
// Dependencies: None
// Example: Pattern( a < 10 && a > 9 )
//
rule "Opposite LiteralRestrictions with ranges, less - greater for numbers"
when
$left :NumberRestriction(
operator == Operator.LESS,
( valueType == Field.INT || == Field.DATE )
)
$right :NumberRestriction(
restrictionType == $left.restrictionType,
fieldPath == $left.fieldPath,
valueType == $left.valueType,
operator == Operator.GREATER,
path != $left.path,
value > $left.value
)
# Check that there is not already a pair with these values.
not Opposites(
left == $left,
right == $right
)
not Opposites(
right == $left,
left == $right
)
then
insert( new Opposites( $left, $right ));
end
//
// If two LiteralRestrictions are in conflict.
//
// Dependencies: None
// Example: Pattern( a >= 10 && a <= 9 )
//
rule "Opposite LiteralRestrictions with ranges, less or equal - greater or equal for ints and dates"
when
$left :NumberRestriction(
operator == Operator.GREATER_OR_EQUAL,
( valueType == Field.INT || == Field.DATE )
)
$right :NumberRestriction(
restrictionType == $left.restrictionType,
fieldPath == $left.fieldPath,
valueType == $left.valueType,
operator == Operator.LESS_OR_EQUAL,
path != $left.path,
value < $left.value
)
# Check that there is not already a pair with these values.
not Opposites(
left == $left,
right == $right
)
not Opposites(
right == $left,
left == $right
)
then
insert( new Opposites( $left, $right ));
end
//
// If two VariableRestrictions are in conflict.
//
// Dependencies: None
// Example: Pattern( a contains $o, a not contains $o )
//
rule "Opposite VariableRestrictions"
when
$r1 :VariableRestriction()
$r2 :VariableRestriction(
fieldPath == $r1.fieldPath,
path != $r1.path,
variable.parentPath == $r1.variable.parentPath,
variable.parentType == $r1.variable.parentType,
# Operator needs to be reverse to what the other one has.
eval( operator == MissingRange.getReversedOperator( $r1.getOperator() ))
)
# Check that there is not already a pair with these values.
not Opposites(
left == $r1,
right == $r2
)
not Opposites(
right == $r1,
left == $r2
)
then
insert( new Opposites( $r1, $r2 ) );
end
© 2015 - 2025 Weber Informatics LLC | Privacy Policy