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

org.drools.verifier.overlaps.Restrictions.drl Maven / Gradle / Ivy

There is a newer version: 9.44.0.Final
Show newest version
/*
 * 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: 2.2.2008
package org.drools.verifier.overlaps

#list any import classes here.
import java.util.Collection;
import java.util.ArrayList;

import org.drools.verifier.data.VerifierReport;

import org.drools.verifier.components.LiteralRestriction;
import org.drools.verifier.components.NumberRestriction;

import org.drools.verifier.report.components.Subsumption;
import org.drools.verifier.report.components.Severity;
import org.drools.verifier.report.components.MessageType;
import org.drools.verifier.report.components.Overlap;

#declare any global variables here
global VerifierReport result;

#
# Fires when two restrictions are overlapping.
# Reports these restrictions as overlapping.
#
# Dependencies: Needs at least one rule.
#
#        package org.drools.verifier.subsumption.patterns
#            rule "Find subsumptant restrictions, greater than"
#            rule "Find subsumptant restrictions, less than"
#
# Example 1: Pattern1( a > 10 ) and Pattern1( a > 100 )
#
rule "Find overlapping number restrictions"
    when
        # There is subsumption between two restrictions

        $left :NumberRestriction()
        $right :NumberRestriction(
            path != $left.path
        )

        $subsumption :Subsumption(
            left.path == $left.path,
            left.verifierComponentType == $left.verifierComponentType,
            right.path == $right.path,
            right.verifierComponentType == $right.verifierComponentType
        )

        # There is no restriction between these two restrictions.
        not $center :NumberRestriction(
                fieldPath == $left.fieldPath,
                value == $left.value,
                value > $right.value
        )
    then
        insert( new Overlap( $left, $right ) );
end

rule "Find overlapping literal restrictions"
    when
        # There is subsumption between two restrictions

        $left :LiteralRestriction()
        $right :LiteralRestriction(
            path != $left.path
        )

        $subsumption :Subsumption(
            left.path == $left.path,
            left.verifierComponentType == $left.verifierComponentType,
            right.path == $right.path,
            right.verifierComponentType == $right.verifierComponentType
        )

        # There is no restriction between these two restrictions.
        not $center :LiteralRestriction(
                fieldPath == $left.fieldPath,
                valueAsString == $left.valueAsString,
                valueAsString == $right.valueAsString
        )
    then
        insert( new Overlap( $left, $right ) );
end

rule "Finddsds overlapping literal restrictions"
    when
        # There is subsumption between two restrictions

        $left :LiteralRestriction()
        $right :LiteralRestriction(
            path != $left.path
        )
    then
        System.out.println( "-----" + $left +" "+ $right);
end






© 2015 - 2025 Weber Informatics LLC | Privacy Policy