Search in sources :

Example 11 with RulesEngine

use of org.jeasy.rules.api.RulesEngine in project easy-rules by j-easy.

the class Launcher method main.

public static void main(String[] args) {
    // define facts
    Facts facts = new Facts();
    facts.put("temperature", 30);
    // define rules
    Rule airConditioningRule = new RuleBuilder().name("air conditioning rule").when(itIsHot()).then(decreaseTemperature()).build();
    Rules rules = new Rules();
    rules.register(airConditioningRule);
    // fire rules on known facts
    RulesEngine rulesEngine = new InferenceRulesEngine();
    rulesEngine.fire(rules, facts);
}
Also used : InferenceRulesEngine(org.jeasy.rules.core.InferenceRulesEngine) InferenceRulesEngine(org.jeasy.rules.core.InferenceRulesEngine) RulesEngine(org.jeasy.rules.api.RulesEngine) Rule(org.jeasy.rules.api.Rule) RuleBuilder(org.jeasy.rules.core.RuleBuilder) Rules(org.jeasy.rules.api.Rules) Facts(org.jeasy.rules.api.Facts)

Example 12 with RulesEngine

use of org.jeasy.rules.api.RulesEngine in project easy-rules by j-easy.

the class FizzBuzzWithEasyRules method main.

public static void main(String[] args) {
    // create rules engine
    RulesEngineParameters parameters = new RulesEngineParameters().skipOnFirstAppliedRule(true);
    RulesEngine fizzBuzzEngine = new DefaultRulesEngine(parameters);
    // create rules
    Rules rules = new Rules();
    rules.register(new FizzRule());
    rules.register(new BuzzRule());
    rules.register(new FizzBuzzRule(new FizzRule(), new BuzzRule()));
    rules.register(new NonFizzBuzzRule());
    // fire rules
    Facts facts = new Facts();
    for (int i = 1; i <= 100; i++) {
        facts.put("number", i);
        fizzBuzzEngine.fire(rules, facts);
        System.out.println();
    }
}
Also used : DefaultRulesEngine(org.jeasy.rules.core.DefaultRulesEngine) DefaultRulesEngine(org.jeasy.rules.core.DefaultRulesEngine) RulesEngine(org.jeasy.rules.api.RulesEngine) RulesEngineParameters(org.jeasy.rules.core.RulesEngineParameters) Rules(org.jeasy.rules.api.Rules) Facts(org.jeasy.rules.api.Facts)

Example 13 with RulesEngine

use of org.jeasy.rules.api.RulesEngine in project easy-rules by j-easy.

the class Launcher method main.

public static void main(String[] args) {
    // create facts
    Facts facts = new Facts();
    // create rules
    Rules rules = new Rules();
    rules.register(new HelloWorldRule());
    // create a rules engine and fire rules on known facts
    RulesEngine rulesEngine = new DefaultRulesEngine();
    rulesEngine.fire(rules, facts);
}
Also used : DefaultRulesEngine(org.jeasy.rules.core.DefaultRulesEngine) DefaultRulesEngine(org.jeasy.rules.core.DefaultRulesEngine) RulesEngine(org.jeasy.rules.api.RulesEngine) Rules(org.jeasy.rules.api.Rules) Facts(org.jeasy.rules.api.Facts)

Example 14 with RulesEngine

use of org.jeasy.rules.api.RulesEngine in project tutorials by eugenp.

the class Launcher method main.

public static void main(String... args) {
    // create facts
    Facts facts = new Facts();
    // create rules
    Rules rules = new Rules();
    rules.register(new HelloWorldRule());
    // create a rules engine and fire rules on known facts
    RulesEngine rulesEngine = new DefaultRulesEngine();
    rulesEngine.fire(rules, facts);
}
Also used : DefaultRulesEngine(org.jeasy.rules.core.DefaultRulesEngine) DefaultRulesEngine(org.jeasy.rules.core.DefaultRulesEngine) RulesEngine(org.jeasy.rules.api.RulesEngine) Rules(org.jeasy.rules.api.Rules) Facts(org.jeasy.rules.api.Facts)

Aggregations

RulesEngine (org.jeasy.rules.api.RulesEngine)14 Facts (org.jeasy.rules.api.Facts)13 Rules (org.jeasy.rules.api.Rules)13 Test (org.junit.Test)8 DefaultRulesEngine (org.jeasy.rules.core.DefaultRulesEngine)5 File (java.io.File)1 Rule (org.jeasy.rules.api.Rule)1 InferenceRulesEngine (org.jeasy.rules.core.InferenceRulesEngine)1 RuleBuilder (org.jeasy.rules.core.RuleBuilder)1 RulesEngineParameters (org.jeasy.rules.core.RulesEngineParameters)1 MVELRule (org.jeasy.rules.mvel.MVELRule)1