Praecepta is a rules engine implemented in Java that uses a trie tree to efficiently search and match patterns in a large set of rules.
- Fast rule matching using a trie tree data structure
- Flexible rule definition syntax
- Support for rule prioritization and conflict resolution
- Asynchronous rule execution
To use Praecepta Engine in your project, you will need to:
- Add the Praecepta Engine library to your project's dependencies
- Define your rules using the provided syntax
- Create a
PraeceptaEngine
instance and add your rules to it - Use the
PraeceptaEngine
to evaluate rules and execute their associated actions
For example:
var input1 = new PraeceptaInput(Map.of("input", "input1"));
var output1 = new PraeceptaOutput(Map.of("output", "output1"));
var praeceptum1 = new Praeceptum(1, input1, output1);
var input2 = new PraeceptaInput(Map.of("input", "input2"));
var output2 = new PraeceptaOutput(Map.of("output", "output2"));
var praeceptum2 = new Praeceptum(2, input2, output2);
var engine = new PraeceptaEngine<>(HitPolicy.UNIQUE, input -> input, output -> output);
engine.register(List.of(praeceptum1, praeceptum2));
var inputToEvaluate = new PraeceptaInput(Map.of("input", "input2"));
var result = engine.evaluate(inputToEvaluate);
To use Praecepta Loader in your project, you will need to:
- Add the Praecepta Loader library to your project's dependencies
- Define your rules using the provided syntax
- Create a
ExcelLoader
instance and add your rules to it - Use the
ExcelLoader
to read the excel file and register the rules into the engine
For example:
var loader = new ExcelLoader("./yourmatrix.xlsx", Set.of("input"), Set.of("output"));
var engine = new PraeceptaEngine<>(HitPolicy.UNIQUE, input -> input, output -> output);
var praecepta = loader.getPraecepta();
engine.register(praecepta);
var inputToEvaluate = new PraeceptaInput(Map.of("input", "input2"));
var result = engine.evaluate(inputToEvaluate);
To build Praecepta, you will need Maven installed on your system. To build the project, run the following command from the root directory of the repository:
mvn clean install
To run the tests, use the following command:
mvn test
Praecepta Engine has the following dependencies:
- Java 17
Praecepta Loader has the following dependencies:
- Apache POI
We welcome contributions to Praecepta! If you would like to contribute, please follow these steps:
- Fork the repository
- Create a new branch for your changes
- Make your changes
- Run the tests to ensure they pass
- Submit a pull request
Praecepta is licensed under the MIT License. See LICENSE for more information.