MCPcopy
hub / github.com/j-easy/easy-rules

github.com/j-easy/easy-rules @easy-rules-4.1.0 sqlite

repository ↗ · DeepWiki ↗ · release easy-rules-4.1.0 ↗
839 symbols 2,518 edges 136 files 139 documented · 17%
README

<b><em>Easy Rules</em></b>


The simple, stupid rules engine for Java&trade;

MIT license Build Status Maven Central Javadoc Gitter


Latest news

  • 17/05/2020: Version 4.0.0 is now released with a lot of new features and enhancements! Check out what's new here.
  • 08/12/2019: Version 3.4.0 is out with a few enhancements and bug fixes. Check out the release notes here.

What is Easy Rules?

Easy Rules is a Java rules engine inspired by an article called "Should I use a Rules Engine?" of Martin Fowler in which Martin says:

You can build a simple rules engine yourself. All you need is to create a bunch of objects with conditions and actions, store them in a collection, and run through them to evaluate the conditions and execute the actions.

This is exactly what Easy Rules does, it provides the Rule abstraction to create rules with conditions and actions, and the RulesEngine API that runs through a set of rules to evaluate conditions and execute actions.

Core features

  • Lightweight library and easy to learn API
  • POJO based development with an annotation programming model
  • Useful abstractions to define business rules and apply them easily with Java
  • The ability to create composite rules from primitive ones
  • The ability to define rules using an Expression Language (Like MVEL and SpEL)

Example

1. First, define your rule..

Either in a declarative way using annotations:

@Rule(name = "weather rule", description = "if it rains then take an umbrella")
public class WeatherRule {

    @Condition
    public boolean itRains(@Fact("rain") boolean rain) {
        return rain;
    }

    @Action
    public void takeAnUmbrella() {
        System.out.println("It rains, take an umbrella!");
    }
}

Or in a programmatic way with a fluent API:

Rule weatherRule = new RuleBuilder()
        .name("weather rule")
        .description("if it rains then take an umbrella")
        .when(facts -> facts.get("rain").equals(true))
        .then(facts -> System.out.println("It rains, take an umbrella!"))
        .build();

Or using an Expression Language:

Rule weatherRule = new MVELRule()
        .name("weather rule")
        .description("if it rains then take an umbrella")
        .when("rain == true")
        .then("System.out.println(\"It rains, take an umbrella!\");");

Or using a rule descriptor:

Like in the following weather-rule.yml example file:

name: "weather rule"
description: "if it rains then take an umbrella"
condition: "rain == true"
actions:
  - "System.out.println(\"It rains, take an umbrella!\");"
MVELRuleFactory ruleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader());
Rule weatherRule = ruleFactory.createRule(new FileReader("weather-rule.yml"));

2. Then, fire it!

public class Test {
    public static void main(String[] args) {
        // define facts
        Facts facts = new Facts();
        facts.put("rain", true);

        // define rules
        Rule weatherRule = ...
        Rules rules = new Rules();
        rules.register(weatherRule);

        // fire rules on known facts
        RulesEngine rulesEngine = new DefaultRulesEngine();
        rulesEngine.fire(rules, facts);
    }
}

This is the hello world of Easy Rules. You can find other examples like the Shop, Airco or WebApp tutorials in the wiki.

Contribution

You are welcome to contribute to the project with pull requests on GitHub.

If you find a bug or want to request a feature, please use the issue tracker.

For any question, you can use StackOverflow or Gitter.

Awesome contributors

Thank you all for your contributions!

Easy Rules in other languages

Who is using Easy Rules?

Credits

YourKit Java Profiler

Many thanks to YourKit, LLC for providing a free license of YourKit Java Profiler to support the development of Easy Rules.

License

Easy Rules is released under the terms of the MIT license:

The MIT License (MIT)

Copyright (c) 2020 Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Extension points exported contracts — how you extend this code

Action (Interface)
This interface represents a rule's action. @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com) [19 implementers]
easy-rules-core/src/main/java/org/jeasy/rules/api/Action.java
RuleDefinitionReader (Interface)
Strategy interface for RuleDefinition readers. @see JsonRuleDefinitionReader @see YamlRuleDefinitionReader @au [2 implementers]
easy-rules-support/src/main/java/org/jeasy/rules/support/reader/RuleDefinitionReader.java
Condition (Interface)
This interface represents a rule's condition. @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com) [22 implementers]
easy-rules-core/src/main/java/org/jeasy/rules/api/Condition.java
Rule (Interface)
Abstraction for a rule that can be fired by a rules engine. Rules are registered in a namespace of rule of type {@link [2 …
easy-rules-core/src/main/java/org/jeasy/rules/api/Rule.java
RulesEngineListener (Interface)
A listener for rules engine execution events. @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com) [2 implementers]
easy-rules-core/src/main/java/org/jeasy/rules/api/RulesEngineListener.java
RulesEngine (Interface)
Rules engine interface. @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com) [1 implementers]
easy-rules-core/src/main/java/org/jeasy/rules/api/RulesEngine.java

Core symbols most depended-on inside this repo

getName
called by 68
easy-rules-core/src/main/java/org/jeasy/rules/api/Rule.java
evaluate
called by 51
easy-rules-core/src/main/java/org/jeasy/rules/api/Rule.java
put
called by 47
easy-rules-core/src/main/java/org/jeasy/rules/api/Facts.java
execute
called by 47
easy-rules-core/src/main/java/org/jeasy/rules/api/Rule.java
getPriority
called by 40
easy-rules-core/src/main/java/org/jeasy/rules/api/Rule.java
fire
called by 38
easy-rules-core/src/main/java/org/jeasy/rules/api/RulesEngine.java
add
called by 37
easy-rules-core/src/main/java/org/jeasy/rules/api/Facts.java
get
called by 35
easy-rules-core/src/main/java/org/jeasy/rules/api/Facts.java

Shape

Method 680
Class 152
Interface 7

Languages

Java100%

Modules by API surface

easy-rules-support/src/test/java/org/jeasy/rules/support/composite/ConditionalRuleGroupTest.java38 symbols
easy-rules-core/src/test/java/org/jeasy/rules/core/RuleProxyTest.java31 symbols
easy-rules-core/src/test/java/org/jeasy/rules/core/DefaultRulesEngineTest.java30 symbols
easy-rules-core/src/main/java/org/jeasy/rules/core/RuleProxy.java25 symbols
easy-rules-core/src/test/java/org/jeasy/rules/core/FactInjectionTest.java24 symbols
easy-rules-core/src/test/java/org/jeasy/rules/core/InferenceRulesEngineTest.java21 symbols
easy-rules-support/src/test/java/org/jeasy/rules/support/composite/ActivationRuleGroupTest.java20 symbols
easy-rules-core/src/test/java/org/jeasy/rules/core/RuleDefinitionValidatorTest.java20 symbols
easy-rules-core/src/test/java/org/jeasy/rules/api/RulesTest.java17 symbols
easy-rules-core/src/main/java/org/jeasy/rules/core/DefaultRulesEngine.java17 symbols
easy-rules-support/src/test/java/org/jeasy/rules/support/composite/UnitRuleGroupTest.java16 symbols
easy-rules-support/src/main/java/org/jeasy/rules/support/RuleDefinition.java16 symbols

Dependencies from manifests, versioned

com.fasterxml.jackson.dataformat:jackson-dataformat-yaml
com.github.stefanbirkner:system-lambda
javax.servlet:javax.servlet-api
junit:junit
org.apache.commons:commons-jexl3
org.assertj:assertj-core
org.jeasy:easy-rules-core4.1.0 · 1×
org.jeasy:easy-rules-mvel
org.jeasy:easy-rules-support
org.mockito:mockito-core
org.mvel:mvel2

For agents

$ claude mcp add easy-rules \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact