org.drools.verifier.incoherence.Restrictions.drl Maven / Gradle / Ivy
#created on: 13.11.2007
package org.drools.verifier.incoherence
#list any import classes here.
import org.drools.verifier.components.LiteralRestriction;
import org.drools.verifier.components.PatternPossibility;
import org.drools.verifier.components.Pattern;
import org.drools.verifier.components.VariableRestriction;
import org.drools.verifier.report.components.Cause;
import org.drools.verifier.report.components.MissingRange;
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;
import java.util.Collection;
import java.util.ArrayList;
import org.drools.base.evaluators.Operator;
#declare any global variables here
global VerifierResult result;
#
# If two LiteralRestrictions are in conflict.
#
# Type: Error
# Dependencies: None
# Example: IncorencePattern1( a == "b", a != "b" )
#
rule "Incoherent LiteralRestrictions in pattern possibility"
when
$r1 :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 )
)
$r2 :LiteralRestriction(
patternId == $r1.patternId,
restrictionType == $r1.restrictionType,
fieldId == $r1.fieldId,
valueType == $r1.valueType,
id != $r1.id,
# Operator needs to be reversed to what the other one has.
eval( operator == MissingRange.getReversedOperator( $r1.getOperator() ))
)
eval( $r1.compareValues( $r2 ) == 0 )
# There is a problem if both of these are in the same PatternPossibility.
$pp :PatternPossibility(
items contains $r1,
items contains $r2
)
$p :Pattern( id == $pp.patternId )
then
Collection list = new ArrayList();
list.add( $r1 );
list.add( $r2 );
result.add( new VerifierMessage(
Severity.ERROR,
MessageType.INCOHERENCE,
$p,
"Restriction " + $r1 + " and " + $r2 +
"are in conflict. Because of this, pattern that contains them can never be satisfied.",
list
) );
end
#
# If two LiteralRestrictions are in conflict.
#
# Type: Error
# Dependencies: None
# Example: IncorencePattern( a > 10 && a < -10 )
#
rule "Incoherent LiteralRestrictions with ranges in pattern possibility, impossible ranges"
when
$r1 :LiteralRestriction(
( operator == Operator.GREATER_OR_EQUAL || == Operator.GREATER )
)
$r2 :LiteralRestriction(
patternId == $r1.patternId,
restrictionType == $r1.restrictionType,
fieldId == $r1.fieldId,
valueType == $r1.valueType,
( operator == Operator.LESS_OR_EQUAL || == Operator.LESS),
id != $r1.id
)
eval( $r1.compareValues( $r2 ) == 1 )
# There is a problem if both of these are in the same PatternPossibility.
$pp :PatternPossibility(
items contains $r1,
items contains $r2
)
$p :Pattern( id == $pp.patternId )
then
Collection list = new ArrayList();
list.add( $r1 );
list.add( $r2 );
result.add( new VerifierMessage(
Severity.ERROR,
MessageType.INCOHERENCE,
$p,
"Restriction " + $r1 + " and " + $r2 +
"are in conflict. Because of this, pattern that contains them can never be satisfied.",
list
) );
end
#
# If two LiteralRestrictions are in conflict.
#
# Type: Error
# Dependencies: None
# Example: IncorencePattern( a < 1 && a == 10 )
#
rule "Incoherent LiteralRestrictions with ranges in pattern possibility, impossible equality less or equal"
when
$r1 :LiteralRestriction(
operator == Operator.EQUAL
)
$r2 :LiteralRestriction(
patternId == $r1.patternId,
restrictionType == $r1.restrictionType,
fieldId == $r1.fieldId,
valueType == $r1.valueType,
( operator == Operator.LESS_OR_EQUAL || == Operator.LESS || == Operator.EQUAL ),
id != $r1.id
)
eval( $r1.compareValues( $r2 ) == 1 )
# There is a problem if both of these are in the same PatternPossibility.
$pp :PatternPossibility(
items contains $r1,
items contains $r2
)
$p :Pattern( id == $pp.patternId )
then
Collection list = new ArrayList();
list.add( $r1 );
list.add( $r2 );
result.add( new VerifierMessage(
Severity.ERROR,
MessageType.INCOHERENCE,
$p,
"Restriction " + $r1 + " and " + $r2 +
"are in conflict. Because of this, pattern that contains them can never be satisfied.",
list
) );
end
#
# If two LiteralRestrictions are in conflict.
#
# Type: Error
# Dependencies: None
# Example: IncorencePattern( a > 10 && a == 1 )
#
rule "Incoherent LiteralRestrictions with ranges in pattern possibility, impossible equality greater"
when
$r1 :LiteralRestriction(
( operator == Operator.GREATER || == Operator.GREATER_OR_EQUAL )
)
$r2 :LiteralRestriction(
patternId == $r1.patternId,
restrictionType == $r1.restrictionType,
fieldId == $r1.fieldId,
valueType == $r1.valueType,
operator == Operator.EQUAL,
id != $r1.id
)
eval( $r1.compareValues( $r2 ) == 1 )
# There is a problem if both of these are in the same PatternPossibility.
$pp :PatternPossibility(
items contains $r1,
items contains $r2
)
$p :Pattern( id == $pp.patternId )
then
Collection list = new ArrayList();
list.add( $r1 );
list.add( $r2 );
result.add( new VerifierMessage(
Severity.ERROR,
MessageType.INCOHERENCE,
$p,
"Restriction " + $r1 + " and " + $r2 +
"are in conflict. Because of this, pattern that contains them can never be satisfied.",
list
) );
end
#
# If two LiteralRestrictions are in conflict.
#
# Type: Error
# Dependencies: None
# Example: IncorencePattern( a < "12-Dec-2007", a > "12-Dec-2007" )
#
rule "Incoherent LiteralRestrictions with ranges in pattern possibility, impossible range"
when
$r1 :LiteralRestriction(
operator == Operator.LESS
)
$r2 :LiteralRestriction(
patternId == $r1.patternId,
restrictionType == $r1.restrictionType,
fieldId == $r1.fieldId,
valueType == $r1.valueType,
operator == Operator.GREATER,
id != $r1.id
)
eval( $r1.compareValues( $r2 ) == 0 )
# There is a problem if both of these are in the same PatternPossibility.
$pp :PatternPossibility(
items contains $r1,
items contains $r2
)
$p :Pattern( id == $pp.patternId )
then
Collection list = new ArrayList();
list.add( $r1 );
list.add( $r2 );
result.add( new VerifierMessage(
Severity.ERROR,
MessageType.INCOHERENCE,
$p,
"Restriction " + $r1 + " and " + $r2 +
"are in conflict. Because of this, pattern that contains them can never be satisfied.",
list
) );
end
#
# If two VariableRestrictions are in conflict.
#
# Type: Error
# Dependencies: None
# Example: IncorencePattern( a contains $o, a not contains $o )
#
rule "Incoherent VariableRestrictions in pattern possibility"
when
$r1 :VariableRestriction(
# Not >= and <=, because ( a <=, a >= ) works.
# And not < or > because they are handled in a separete rule.
( operator != Operator.GREATER_OR_EQUAL || != Operator.LESS_OR_EQUAL || != Operator.LESS || != Operator.GREATER )
)
$r2 :VariableRestriction(
patternId == $r1.patternId,
fieldId == $r1.fieldId,
id != $r1.id,
variable.objectId == $r1.variable.objectId,
variable.objectType == $r1.variable.objectType,
# Operator needs to be reversed to what the other one has.
eval( operator == MissingRange.getReversedOperator( $r1.getOperator() ))
)
# There is a problem if both of these are in the same PatternPossibility.
$pp :PatternPossibility(
items contains $r1,
items contains $r2
)
$p :Pattern( id == $pp.patternId )
then
Collection list = new ArrayList();
list.add( $r1 );
list.add( $r2 );
result.add( new VerifierMessage(
Severity.ERROR,
MessageType.INCOHERENCE,
$p,
"Restriction " + $r1 + " and " + $r2 +
"are in conflict. Because of this, pattern that contains them can never be satisfied.",
list
) );
end
#
# If two VariableRestrictions are in conflict.
#
# Type: Error
# Dependencies: None
# Example: IncorencePattern( a > $var, a < $var )
#
rule "Incoherent VariableRestrictions in pattern possibility, impossible range"
when
$r1 :VariableRestriction(
operator == Operator.LESS
)
$r2 :VariableRestriction(
patternId == $r1.patternId,
fieldId == $r1.fieldId,
operator == Operator.GREATER,
variable.objectId == $r1.variable.objectId,
variable.objectType == $r1.variable.objectType,
id != $r1.id
)
# There is a problem if both of these are in the same PatternPossibility.
$pp :PatternPossibility(
items contains $r1,
items contains $r2
)
$p :Pattern( id == $pp.patternId )
then
Collection list = new ArrayList();
list.add( $r1 );
list.add( $r2 );
result.add( new VerifierMessage(
Severity.ERROR,
MessageType.INCOHERENCE,
$p,
"Restriction " + $r1 + " and " + $r2 +
"are in conflict. Because of this, pattern that contains them can never be satisfied.",
list
) );
end
© 2015 - 2025 Weber Informatics LLC | Privacy Policy