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

org.drools.verifier.subsumption.SubPatterns.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: 8.1.2008
package org.drools.verifier.subsumption.patterns

import org.drools.verifier.components.Restriction;
import org.drools.verifier.components.Pattern;
import org.drools.verifier.components.PatternComponent;
import org.drools.verifier.components.SubPattern;
import org.drools.verifier.components.SubRule;
import org.drools.verifier.components.Source;
import org.drools.verifier.report.components.Redundancy;
import org.drools.verifier.report.components.Subsumption;

import org.drools.verifier.data.VerifierReport;

import java.util.ArrayList;

#declare any global variables here
global VerifierReport result

#
# Fires when two pattern possibilities are subsumptant.
# Creates a Subsumption object.
#
# Dependencies: Needs at least one rule.
#
#        package org.drools.verifier.redundancy.patterns
#            rule "Find redundant Patterns with restrictions"
#            rule "Find redundant Patterns without restrictions"
#
# Example 1: P( x == 10 ) and P( x == 10 && y == 20 )
#
rule "Find subsumptant sub patterns, subsumptant source"
    when

        $subPattern1 :SubPattern()
        $subPattern2 :SubPattern(
            path != $subPattern1.path,
            objectTypePath == $subPattern1.objectTypePath,
            # TODO: Check these. Should work with the idea of subsumption.
            patternNot == $subPattern1.patternNot,
            patternExists == $subPattern1.patternExists,
            patternForall == $subPattern1.patternForall
        )
        # Check if sources are equal or subsumptant
        $sourceSubsumption :Subsumption()
        Source(
            path == $subPattern1.sourcePath,
            verifierComponentType == $subPattern1.sourceType,
            this == $sourceSubsumption.left
        )
        Source(
            path == $subPattern2.sourcePath,
            verifierComponentType == $subPattern2.sourceType,
            this == $sourceSubsumption.right
        )

        # For every restriction in $subPattern1 there is a subsumption to a restriction in $subPattern2.
        forall (
            $leftPatternComponent :PatternComponent(
            ) from $subPattern1.items

            Subsumption(
                left == $leftPatternComponent,
                right memberOf $subPattern2.items
            )
        )

        $causes : ArrayList()
            from collect(
                  Subsumption(
                      left memberOf $subPattern1.items,
                      right memberOf $subPattern2.items
                  )
            )
    then
        insert(
            new Subsumption(
                $subPattern1,
                $subPattern2,
                $causes
            )
        );
end

#
# Fires when two pattern possibilities are subsumptant.
# Creates a Subsumption object.
#
# Dependencies: Needs at least one rule.
#
#        package org.drools.verifier.redundancy.patterns
#            rule "Find redundant Patterns with restrictions"
#            rule "Find redundant Patterns without restrictions"
#
# Example 1: P( x == 10 ) and P( x == 10 && y == 20 )
#
rule "Find subsumptant sub patterns, same source"
    when

        $subPattern1 :SubPattern()
        $subPattern2 :SubPattern(
            path != $subPattern1.path,
            objectTypePath == $subPattern1.objectTypePath,
            # TODO: Check these. Should work with the idea of subsumption.
            patternNot == $subPattern1.patternNot,
            patternExists == $subPattern1.patternExists,
            patternForall == $subPattern1.patternForall
        )
        # Check if sources are equal or subsumptant #
        Source(
                path == $subPattern1.sourcePath && == $subPattern2.sourcePath,
                verifierComponentType == $subPattern1.sourceType && == $subPattern2.sourceType
        )

        # For every restriction in $subPattern1 there is a subsumption to a restriction in $subPattern2.
        forall (
            $leftPatternComponent :PatternComponent(
            ) from $subPattern1.items

            Subsumption(
                left == $leftPatternComponent,
                right memberOf $subPattern2.items
            )
        )

        $causes : ArrayList()
            from collect(
                  Subsumption(
                      left memberOf $subPattern1.items,
                      right memberOf $subPattern2.items
                  )
            )
    then
        insert(
            new Subsumption(
                $subPattern1,
                $subPattern2,
                $causes
            )
        );
end





© 2015 - 2025 Weber Informatics LLC | Privacy Policy