Giter VIP home page Giter VIP logo

Evrete

GitHub repo size GitHub stars

Important!

Starting with version 3.2.00, the default build (release) version targets Java 11. Java 8 artifacts are now published with the '-8' suffix.

Evrete is a forward-chaining Java rule engine that implements the RETE algorithm and is fully compliant with the Java Rule Engine specification (JSR 94).

Historically designed as a fast and lightweight alternative to full-scale rule management systems, the engine also brings its own mix of features:

Rule authoring

  • Rules can be authored both externally and inline as a plain Java 8 code.
  • The engine allows rules to be authored as annotated Java sources, classes, or archives.
  • The library itself is a flexible tool for creating custom domain-specific rule languages (DSL).

Intuitive and developer-friendly

  • Library's type system allows it to seamlessly process any kinds of objects, including JSON and XML.
  • Fluent builders, Java functional interfaces, and other best practices keep developers' code concise and clear.
  • Key components are exposed as Service Provider Interfaces and can be customized.

Performance and security

  • The engine's algorithm and memory are optimized for large-scale and labeled data.
  • Built-in support of Java Security Manager protects against unwanted or potentially malicious code in the rules.

Project home

The official project description, documentation, and usage examples can be found at https://www.evrete.org

Prerequisites

Evrete is Java 8+ compatible and ships with zero dependencies.

Installation

Maven:

<dependency>
    <groupId>org.evrete</groupId>
    <artifactId>evrete-core</artifactId>
    <version>3.2.02</version>
</dependency>

Gradle:

implementation 'org.evrete:evrete-core:3.2.02'

Support for annotated rules (optional)

Maven:

<dependency>
    <groupId>org.evrete</groupId>
    <artifactId>evrete-dsl-java</artifactId>
    <version>3.2.02</version>
</dependency>

Gradle:

implementation 'org.evrete:evrete-dsl-java:3.2.02'

Quick start

Below is a simple example of rule that removes from session memory every integer except prime numbers.

As inline Java code:

public class PrimeNumbersInline {
    public static void main(String[] args) {
        KnowledgeService service = new KnowledgeService();
        Knowledge knowledge = service
                .newKnowledge()
                .builder()
                .newRule("prime numbers")
                .forEach(
                        "$i1", Integer.class,
                        "$i2", Integer.class,
                        "$i3", Integer.class
                )
                .where("$i1 * $i2 == $i3")
                .execute(ctx -> ctx.deleteFact("$i3"))
                .build();

        try (StatefulSession session = knowledge.newStatefulSession()) {
            // Inject candidates
            for (int i = 2; i <= 100; i++) {
                session.insert(i);
            }

            // Execute rules
            session.fire();

            // Print current memory state
            session.forEachFact((handle, o) -> System.out.println(o));
        }
        service.shutdown();
    }
}

As annotated Java source file:

public class PrimeNumbersDSLUrl {
    public static void main(String[] args) {
        KnowledgeService service = new KnowledgeService();
        Knowledge knowledge = service
                .newKnowledge(
                        "JAVA-SOURCE",
                        new URL("https://www.evrete.org/examples/PrimeNumbersSource.java")
                );

        try (StatefulSession session = knowledge.newStatefulSession()) {
            // Inject candidates
            for (int i = 2; i <= 100; i++) {
                session.insert(i);
            }
            // Execute rules
            session.fire();
            // Printout current memory state
            session.forEachFact((handle, o) -> System.out.println(o));
        }
    }
}

where the rule itself is stored externally as PrimeNumbersSource.java

For further details see the official documentation

License

This project uses the following license: MIT

Java Rule Engine's Projects

evrete icon evrete

Evrete is a lightweight and intuitive Java rule engine.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.