org.drools.verifier.incoherence.Patterns.drl Maven / Gradle / Ivy
/*
* Copyright 2010 Red Hat, Inc. and/or its affiliates.
*
* 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: 14.11.2007
package org.drools.verifier.incoherence
//list any import classes here.
import org.drools.verifier.components.VerifierRule;
import org.drools.verifier.components.LiteralRestriction;
import org.drools.verifier.components.NumberRestriction;
import org.drools.verifier.components.SubPattern;
import org.drools.verifier.components.SubRule;
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.data.VerifierReport;
import java.util.Collection;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import org.drools.core.base.evaluators.Operator;
//declare any global variables here
global VerifierReport result;
//
// If two Patterns are in conflict.
//
// Type: Warning
// Dependencies: None
// Example:
// IncorencePattern( a == 1 )
// not IncorencePattern( a == 1 )
//
rule "Incoherent Patterns in rule possibility"
when
$r1 :LiteralRestriction(
patternIsNot == true
)
$r2 :LiteralRestriction(
rulePath == $r1.rulePath,
patternIsNot == false,
restrictionType == $r1.restrictionType,
fieldPath == $r1.fieldPath,
valueType == $r1.valueType,
operator == $r1.operator,
valueAsString == $r1.valueAsString
)
$pp1 :SubPattern(
patternPath == $r1.patternPath
)
$pp2 :SubPattern(
patternPath == $r2.patternPath
)
// There is a problem if both of these are in the same SubRule.
$rp :SubRule(
items contains $pp1,
items contains $pp2
)
$p1 :Pattern(
path == $r1.patternPath
)
$p2 :Pattern(
path == $r2.patternPath
)
$r :VerifierRule(
path == $rp.rulePath
)
then
Map impactedRules = new HashMap();
impactedRules.put( $r.getPath(), $r.getName());
Collection list = new ArrayList();
list.add( $p1 );
list.add( $p2 );
result.add( new VerifierMessage(
impactedRules,
Severity.WARNING,
MessageType.INCOHERENCE,
$r,
"Pattern " + $p1 + " and " + $p2 +
" are in conflict. Because of this, it is possible that the rule that contains them can never be satisfied.",
list
) );
end
//
// If two Patterns are in conflict.
//
// Type: Warning
// Dependencies: None
// Example:
// $var :Object()
// IncorencePattern( a == $var )
// not IncorencePattern( a == $var )
//
rule "Incoherent Patterns in rule possibility, variables"
when
$r1 :VariableRestriction(
patternIsNot == true
)
$r2 :VariableRestriction(
rulePath == $r1.rulePath,
patternIsNot == false,
fieldPath == $r1.fieldPath,
variable.parentPath == $r1.variable.parentPath,
variable.parentType == $r1.variable.parentType,
operator == $r1.operator
)
$pp1 :SubPattern(
patternPath == $r1.patternPath
)
$pp2 :SubPattern(
patternPath == $r2.patternPath
)
// There is a problem if both of these are in the same SubRule.
$rp :SubRule(
items contains $pp1,
items contains $pp2
)
$p1 :Pattern(
path == $r1.patternPath
)
$p2 :Pattern(
path == $r2.patternPath
)
$r :VerifierRule(
path == $rp.rulePath
)
then
Map impactedRules = new HashMap();
impactedRules.put( $r.getPath(), $r.getName());
Collection list = new ArrayList();
list.add( $p1 );
list.add( $p2 );
result.add( new VerifierMessage(
impactedRules,
Severity.WARNING,
MessageType.INCOHERENCE,
$r,
"Pattern " + $p1 + " and " + $p2 +
" are in conflict. Because of this, it is possible that the rule that contains them can never be satisfied.",
list
) );
end
//
// If two Patterns are in conflict.
//
// Type: Warning
// Dependencies: None
// Example:
// IncorencePattern8( a > 11 )
// not IncorencePattern8( a > 1 )
//
rule "Incoherent Patterns in rule possibility, ranges when not conflicts with lesser value"
when
$r1 :NumberRestriction(
patternIsNot == true,
( operator == Operator.GREATER || == Operator.GREATER_OR_EQUAL )
)
$r2 :NumberRestriction(
rulePath == $r1.rulePath,
patternIsNot == false,
( operator == Operator.GREATER || == Operator.GREATER_OR_EQUAL || == Operator.EQUAL ),
fieldPath == $r1.fieldPath,
value > $r1.value
)
$pp1 :SubPattern(
patternPath == $r1.patternPath
)
$pp2 :SubPattern(
patternPath == $r2.patternPath
)
// There is a problem if both of these are in the same SubRule.
$rp :SubRule(
items contains $pp1,
items contains $pp2
)
$p1 :Pattern(
path == $r1.patternPath
)
$p2 :Pattern(
path == $r2.patternPath
)
$r :VerifierRule(
path == $rp.rulePath
)
then
Map impactedRules = new HashMap();
impactedRules.put( $r.getPath(), $r.getName());
Collection list = new ArrayList();
list.add( $p1 );
list.add( $p2 );
result.add( new VerifierMessage(
impactedRules,
Severity.WARNING,
MessageType.INCOHERENCE,
$r,
"Pattern " + $p1 + " and " + $p2 +
" are in conflict. Because of this, it is possible that the rule that contains them can never be satisfied.",
list
) );
end
//
// If two Patterns are in conflict.
//
// Type: Warning
// Dependencies: None
// Example:
// IncorencePattern( a < 1 )
// not IncorencePattern( a < 11 )
//
rule "Incoherent Patterns in rule possibility, ranges when not conflicts with greater value"
when
$r1 :NumberRestriction(
patternIsNot == true,
( operator == Operator.LESS || == Operator.LESS_OR_EQUAL )
)
$r2 :NumberRestriction(
rulePath == $r1.rulePath,
patternIsNot == false,
( operator == Operator.LESS || == Operator.LESS_OR_EQUAL || == Operator.EQUAL ),
fieldPath == $r1.fieldPath,
value < $r1.value
)
$pp1 :SubPattern(
patternPath == $r1.patternPath
)
$pp2 :SubPattern(
patternPath == $r2.patternPath
)
// There is a problem if both of these are in the same SubRule.
$rp :SubRule(
items contains $pp1,
items contains $pp2
)
$p1 :Pattern(
path == $r1.patternPath
)
$p2 :Pattern(
path == $r2.patternPath
)
$r :VerifierRule(
path == $rp.rulePath
)
then
Map impactedRules = new HashMap();
impactedRules.put( $r.getPath(), $r.getName());
Collection list = new ArrayList();
list.add( $p1 );
list.add( $p2 );
result.add( new VerifierMessage(
impactedRules,
Severity.WARNING,
MessageType.INCOHERENCE,
$r,
"Pattern " + $p1 + " and " + $p2 +
" are in conflict. Because of this, it is possible that the rule that contains them can never be satisfied.",
list
) );
end
//
// If two Patterns are in conflict.
//
// Type: Warning
// Dependencies: None
// Example:
// IncoherencePattern( a >= 1 )
// not IncoherencePattern( a != 1 )
//
rule "Incoherent Patterns in rule possibility, ranges when not conflicts with equal or unequal value"
when
$r1 :LiteralRestriction(
patternIsNot == true,
operator == Operator.NOT_EQUAL
)
$r2 :LiteralRestriction(
rulePath == $r1.rulePath,
patternIsNot == false,
// It is also a problem if the value is NOT_EQUAL, but there is already a rule for that.
( operator != Operator.EQUAL && != Operator.NOT_EQUAL ),
fieldPath == $r1.fieldPath,
valueAsString == $r1.valueAsString
)
$pp1 :SubPattern(
patternPath == $r1.patternPath
)
$pp2 :SubPattern(
patternPath == $r2.patternPath
)
// There is a problem if both of these are in the same SubRule.
$rp :SubRule(
items contains $pp1,
items contains $pp2
)
$p1 :Pattern(
path == $r1.patternPath
)
$p2 :Pattern(
path == $r2.patternPath
)
$r :VerifierRule(
path == $rp.rulePath
)
then
Map impactedRules = new HashMap();
impactedRules.put( $r.getPath(), $r.getName());
Collection list = new ArrayList();
list.add( $p1 );
list.add( $p2 );
result.add( new VerifierMessage(
impactedRules,
Severity.WARNING,
MessageType.INCOHERENCE,
$r,
"Pattern " + $p1 + " and " + $p2 +
" are in conflict. Because of this, it is possible that the rule that contains them can never be satisfied.",
list
) );
end
//
// If two Patterns are in conflict.
//
// Type: Warning
// Dependencies: None
// Example:
// IncoherencePattern15( a >= $var )
// not IncoherencePattern15( a != $var )
//
rule "Incoherent Patterns in rule possibility, ranges when not conflicts with equal or unequal variables"
when
$r1 :VariableRestriction(
patternIsNot == true,
operator == Operator.NOT_EQUAL
)
$r2 :VariableRestriction(
rulePath == $r1.rulePath,
patternIsNot == false,
fieldPath == $r1.fieldPath,
variable.parentPath == $r1.variable.parentPath,
variable.parentType == $r1.variable.parentType,
// It is also a problem if the value is NOT_EQUAL, but there is already a rule for that.
( operator != Operator.EQUAL && != Operator.NOT_EQUAL )
)
$pp1 :SubPattern(
patternPath == $r1.patternPath
)
$pp2 :SubPattern(
patternPath == $r2.patternPath
)
// There is a problem if both of these are in the same SubRule.
$rp :SubRule(
items contains $pp1,
items contains $pp2
)
$p1 :Pattern(
path == $r1.patternPath
)
$p2 :Pattern(
path == $r2.patternPath
)
$r :VerifierRule(
path == $rp.rulePath
)
then
Map impactedRules = new HashMap();
impactedRules.put( $r.getPath(), $r.getName());
Collection list = new ArrayList();
list.add( $p1 );
list.add( $p2 );
result.add( new VerifierMessage(
impactedRules,
Severity.WARNING,
MessageType.INCOHERENCE,
$r,
"Pattern " + $p1 + " and " + $p2 +
" are in conflict. Because of this, it is possible that the rule that contains them can never be satisfied.",
list
) );
end
//
// If two Patterns are in conflict.
//
// Type: Warning
// Dependencies: None
// Example:
// IncoherencePattern13( a == $var )
// not IncoherencePattern13( a >= $var )
//
rule "Incoherent Patterns in rule possibility, ranges when not conflicts with equal value"
when
$r1 :LiteralRestriction(
patternIsNot == true,
( operator == Operator.LESS_OR_EQUAL || == Operator.GREATER_OR_EQUAL )
)
$r2 :LiteralRestriction(
rulePath == $r1.rulePath,
patternIsNot == false,
operator == Operator.EQUAL,
fieldPath == $r1.fieldPath,
valueAsString == $r1.valueAsString
)
$pp1 :SubPattern(
patternPath == $r1.patternPath
)
$pp2 :SubPattern(
patternPath == $r2.patternPath
)
// There is a problem if both of these are in the same SubRule.
$rp :SubRule(
items contains $pp1,
items contains $pp2
)
$p1 :Pattern(
path == $r1.patternPath
)
$p2 :Pattern(
path == $r2.patternPath
)
$r :VerifierRule(
path == $rp.rulePath
)
then
Map impactedRules = new HashMap();
impactedRules.put( $r.getPath(), $r.getName());
Collection list = new ArrayList();
list.add( $p1 );
list.add( $p2 );
result.add( new VerifierMessage(
impactedRules,
Severity.WARNING,
MessageType.INCOHERENCE,
$r,
"Pattern " + $p1 + " and " + $p2 +
" are in conflict. Because of this, it is possible that the rule that contains them can never be satisfied.",
list
) );
end
//
// If two Patterns are in conflict.
//
// Type: Warning
// Dependencies: None
// Example:
// IncoherencePattern13( a == $var )
// not IncoherencePattern13( a >= $var )
//
rule "Incoherent Patterns in rule possibility, ranges when not conflicts with equal variable"
when
$r1 :VariableRestriction(
patternIsNot == true,
// Equal is also a problem, but there is already a rule for that.
( operator == Operator.LESS_OR_EQUAL || == Operator.GREATER_OR_EQUAL )
)
$r2 :VariableRestriction(
rulePath == $r1.rulePath,
patternIsNot == false,
fieldPath == $r1.fieldPath,
variable.parentPath == $r1.variable.parentPath,
variable.parentType == $r1.variable.parentType,
operator == Operator.EQUAL
)
$pp1 :SubPattern(
patternPath == $r1.patternPath
)
$pp2 :SubPattern(
patternPath == $r2.patternPath
)
// There is a problem if both of these are in the same SubRule.
$rp :SubRule(
items contains $pp1,
items contains $pp2
)
$p1 :Pattern(
path == $r1.patternPath
)
$p2 :Pattern(
path == $r2.patternPath
)
$r :VerifierRule(
path == $rp.rulePath
)
then
Map impactedRules = new HashMap();
impactedRules.put( $r.getPath(), $r.getName());
Collection list = new ArrayList();
list.add( $p1 );
list.add( $p2 );
result.add( new VerifierMessage(
impactedRules,
Severity.WARNING,
MessageType.INCOHERENCE,
$r,
"Pattern " + $p1 + " and " + $p2 +
" are in conflict. Because of this, it is possible that the rule that contains them can never be satisfied.",
list
) );
end
© 2015 - 2025 Weber Informatics LLC | Privacy Policy