Liking cljdoc? Tell your friends :D

Introduction to cloj-rules-engine

cloj-rules-engine is a very simple rules engine written in Clojure and designed to work with Java.

Rules Engine

Features:

  • Each rule has a condition (composed of conditional expressions -written in Clojure- that refer to facts), and a set of actions that are activated if the condition is satisfied. Facts are the data upon which rules operate. The fired actions are a represented as a set of identifiers (strings).

  • Rules are expressed in a simple and easy to read Clojure format (clojure maps)

{
  :RULE_1 {:cond "(and (< #A 10) (> #B 50))"
           :actions ["action-1"]}
  ...
}
  • Facts can be expressed via clojure maps (Clojure) or via PersistentArrayMap objects (Java):
(update-map-facts {"#A" "14"})
PersistentArrayMap facts_map = new PersistentArrayMap(new Object[] {
		"#A", "14"
	});
clrules.updateMapFacts(facts_map);
  • This library can be used from Java or Clojure code

  • Third party libraries used in this project:

LibsVersionLicense
clojure1.8.0License
tools.logging0.3.1License
log4j1.2.17License
data.json0.2.6License
proto-repl0.3.1License: MIT
math.numeric-tower0.0.4License
  • Main methods:

    • initialize loads rules map from absolute or relative path. Returns true if everything is okay.
    (initialize "rules.clj")
    
    clrules.initialize("rules.clj");
    
    • update-map-facts update / initialize facts
    (update-map-facts {"#A" "14"})
    
    clrules.updateMapFacts(facts_map);
    
    • get-rules-actions evaluates rules based on current facts, and return a list (String) of 'fired' actions
    (get-rules-actions)
    
    clrules.getRulesActions();
    
    • get-fired-rules

    • initialize-from-json

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close