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

org.drools.verifier.opposites.Patterns.drl Maven / Gradle / Ivy

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

//list any import classes here.
import org.drools.verifier.components.Restriction;
import org.drools.verifier.components.SubPattern;

import org.drools.verifier.report.components.Opposites;

import org.drools.verifier.data.VerifierReport;

//declare any global variables here
global VerifierReport result;


//
// Pattern possibilities are opposites if all of the restrictions are opposites.
//
// Dependencies:
//
//    Needs at least one of the following packages or rules to fire:
//         package org.drools.verifier.opposites;
//            rule "Opposite LiteralRestrictions"
//            rule "Opposite LiteralRestrictions with ranges, greater or equal - less"
//            rule "Opposite LiteralRestrictions with ranges, greater - less or equal"
//            rule "Opposite LiteralRestrictions with ranges, less - greater for ints and dates"
//            rule "Opposite LiteralRestrictions with ranges, less or equal - greater or equal for ints and dates"
//
// Example:
//            Pattern( a < b)
//            Pattern( a >= b )
//
rule "Opposite Patterns"
    when
        $opposites :Opposites()

        $pp1 :SubPattern(
            items contains $opposites.left
        )

        $pp2 :SubPattern(
            items contains $opposites.right
        )

        // Check that these facts do not already exist
        not Opposites( left == $pp1, right == $pp2 )
        not Opposites( left == $pp2, right == $pp1 )

        // Check if all the restrictions in $pp1 have an opposite in $pp2.
        forall (
            $r1 :Restriction(
                    this memberOf $pp1.items
            )

            Opposites(
                    left == $r1,
                    right memberOf $pp2.items
            )
        )

        // Check if all the restrictions in $pp2 have an opposite in $pp1.
        forall (
            $r1 :Restriction(
                    this memberOf $pp2.items
            )

            Opposites(
                    right == $r1,
                    left memberOf $pp1.items
            )
        )
    then
        // These two pattern possibilities are opposite.
        insert( new Opposites( $pp1, $pp2 ));
end




© 2015 - 2025 Weber Informatics LLC | Privacy Policy