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

org.drools.verifier.optimisation.PatternOrder.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: 27.10.2007
package org.drools.verifier.optimisation

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

import org.drools.verifier.components.Pattern;
import org.drools.verifier.components.VerifierRule;
import org.drools.verifier.components.PatternOperatorDescr;
import org.drools.verifier.components.Eval;
import org.drools.verifier.components.SubRule;
import org.drools.verifier.components.SubPattern;
import org.drools.verifier.components.RuleComponent;
import org.drools.verifier.data.VerifierComponent;
import org.drools.verifier.components.VerifierComponentType;
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.Map;
import java.util.HashMap;

//declare any global variables here
global VerifierReport result;




// Informs that rule would be more effective if eval
// was after fact patterns.
//
// Type: Note
// Dependencies: None
// Example:
//        eval(function( $something ))
//        Pattern()
//
rule "Optimise evals inside pattern"
    when
        $subRule : SubRule()

        $eval :Eval(
            this memberOf $subRule.items
        )

        $subPattern : SubPattern(
            this memberOf $subRule.items,
            patternPath == $subPattern.patternPath,
            pattern.orderNumber > $eval.orderNumber,
            $pattern : pattern
        )
    then
        Map impactedRules = new HashMap();
        impactedRules.put(  $subRule.getRule().getPath(),
                            $subRule.getRule().getName());

        Collection list = new ArrayList();
        list.add( $eval );
        list.add( $pattern );
        result.add( new VerifierMessage(
                                impactedRules,
                                Severity.NOTE,
                                MessageType.OPTIMISATION,
                                $subRule.getRule(),
                                "Rule \"" + $subRule.getRuleName() +
                                "\" would be more effective if the less expensive component, (" +
                                $pattern +
                                "), could be before (" +
                                $eval + ").",
                                list ) );
end




© 2015 - 2025 Weber Informatics LLC | Privacy Policy