All Projects → CacheControl → Json Rules Engine

CacheControl / Json Rules Engine

Licence: isc
A rules engine expressed in JSON

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Json Rules Engine

Node Rules
Node-rules is a light weight forward chaining rule engine written in JavaScript.
Stars: ✭ 481 (-58.5%)
Mutual labels:  rules, rule-engine, rules-engine, engine
rools
A small rule engine for Node.
Stars: ✭ 118 (-89.82%)
Mutual labels:  rules, rule-engine, rules-engine
powerflows-dmn
Power Flows DMN - Powerful decisions and rules engine
Stars: ✭ 46 (-96.03%)
Mutual labels:  rules, rule-engine, rules-engine
Rulette
A pragmatic business rule management system
Stars: ✭ 91 (-92.15%)
Mutual labels:  rules, rule-engine, rules-engine
Nrules
Rules engine for .NET, based on the Rete matching algorithm, with internal DSL in C#.
Stars: ✭ 1,003 (-13.46%)
Mutual labels:  rules, rule-engine, rules-engine
evrete
Evrete is a lightweight and intuitive Java rule engine.
Stars: ✭ 37 (-96.81%)
Mutual labels:  rule-engine, rules-engine
ruledesigner
Rule Designer is the Eclipse-based development environment for ODM developers.
Stars: ✭ 14 (-98.79%)
Mutual labels:  rules, rule-engine
Drools
rules engine
Stars: ✭ 266 (-77.05%)
Mutual labels:  rules, engine
Gamification Engine
gamification-engine (gengine) is a framework for developing gamification features for your application
Stars: ✭ 286 (-75.32%)
Mutual labels:  rules-engine, engine
Easy Rules
The simple, stupid rules engine for Java
Stars: ✭ 3,522 (+203.88%)
Mutual labels:  rule-engine, rules-engine
Rulebook
100% Java, Lambda Enabled, Lightweight Rules Engine with a Simple and Intuitive DSL
Stars: ✭ 562 (-51.51%)
Mutual labels:  rules, rules-engine
EngineX
Engine X - 实时AI智能决策引擎、规则引擎、风控引擎、数据流引擎。 通过可视化界面进行规则配置,无需繁琐开发,节约人力,提升效率,实时监控,减少错误率,随时调整; 支持规则集、评分卡、决策树,名单库管理、机器学习模型、三方数据接入、定制化开发等;
Stars: ✭ 369 (-68.16%)
Mutual labels:  rules, rule-engine
Spimedb
EXPLORE & EDIT REALITY
Stars: ✭ 14 (-98.79%)
Mutual labels:  json, engine
NiFi-Rule-engine-processor
Drools processor for Apache NiFi
Stars: ✭ 34 (-97.07%)
Mutual labels:  rule-engine, rules-engine
RulerZBundle
Symfony Bundle for RulerZ
Stars: ✭ 38 (-96.72%)
Mutual labels:  rules, rule-engine
Rulerz
Powerful implementation of the Specification pattern in PHP
Stars: ✭ 827 (-28.65%)
Mutual labels:  rules, rules-engine
Roulette
A text/template based rules engine
Stars: ✭ 32 (-97.24%)
Mutual labels:  rules, rules-engine
cs-expert-system-shell
C# implementation of an expert system shell
Stars: ✭ 34 (-97.07%)
Mutual labels:  rules, rule-engine
liteflow
Small but powerful rules engine,轻量强大优雅的规则引擎
Stars: ✭ 1,119 (-3.45%)
Mutual labels:  rule-engine, rules-engine
Bludit
Simple, Fast, Secure, Flat-File CMS
Stars: ✭ 824 (-28.9%)
Mutual labels:  json, engine

json-rules-engine js-standard-style Build Status

npm version install size npm downloads

A rules engine expressed in JSON

Synopsis

json-rules-engine is a powerful, lightweight rules engine. Rules are composed of simple json structures, making them human readable and easy to persist.

Features

  • Rules expressed in simple, easy to read JSON
  • Full support for ALL and ANY boolean operators, including recursive nesting
  • Fast by default, faster with configuration; priority levels and cache settings for fine tuning performance
  • Secure; no use of eval()
  • Isomorphic; runs in node and browser
  • Lightweight & extendable; 17kb gzipped w/few dependencies

Installation

$ npm install json-rules-engine

Docs

Examples

See the Examples, which demonstrate the major features and capabilities.

Basic Example

This example demonstrates an engine for detecting whether a basketball player has fouled out (a player who commits five personal fouls over the course of a 40-minute game, or six in a 48-minute game, fouls out).

const { Engine } = require('json-rules-engine')


/**
 * Setup a new engine
 */
let engine = new Engine()

// define a rule for detecting the player has exceeded foul limits.  Foul out any player who:
// (has committed 5 fouls AND game is 40 minutes) OR (has committed 6 fouls AND game is 48 minutes)
engine.addRule({
  conditions: {
    any: [{
      all: [{
        fact: 'gameDuration',
        operator: 'equal',
        value: 40
      }, {
        fact: 'personalFoulCount',
        operator: 'greaterThanInclusive',
        value: 5
      }]
    }, {
      all: [{
        fact: 'gameDuration',
        operator: 'equal',
        value: 48
      }, {
        fact: 'personalFoulCount',
        operator: 'greaterThanInclusive',
        value: 6
      }]
    }]
  },
  event: {  // define the event to fire when the conditions evaluate truthy
    type: 'fouledOut',
    params: {
      message: 'Player has fouled out!'
    }
  }
})

/**
 * Define facts the engine will use to evaluate the conditions above.
 * Facts may also be loaded asynchronously at runtime; see the advanced example below
 */
let facts = {
  personalFoulCount: 6,
  gameDuration: 40
}

// Run the engine to evaluate
engine
  .run(facts)
  .then(({ events }) => {
    events.map(event => console.log(event.params.message))
  })

/*
 * Output:
 *
 * Player has fouled out!
 */

This is available in the examples

Advanced Example

This example demonstates an engine for identifying employees who work for Microsoft and are taking Christmas day off.

This demonstrates an engine which uses asynchronous fact data. Fact information is loaded via API call during runtime, and the results are cached and recycled for all 3 conditions. It also demonstates use of the condition path feature to reference properties of objects returned by facts.

const { Engine } = require('json-rules-engine')

// example client for making asynchronous requests to an api, database, etc
import apiClient from './account-api-client'

/**
 * Setup a new engine
 */
let engine = new Engine()

/**
 * Rule for identifying microsoft employees taking pto on christmas
 *
 * the account-information fact returns:
 *  { company: 'XYZ', status: 'ABC', ptoDaysTaken: ['YYYY-MM-DD', 'YYYY-MM-DD'] }
 */
let microsoftRule = {
  conditions: {
    all: [{
      fact: 'account-information',
      operator: 'equal',
      value: 'microsoft',
      path: '$.company' // access the 'company' property of "account-information"
    }, {
      fact: 'account-information',
      operator: 'in',
      value: ['active', 'paid-leave'], // 'status' can be active or paid-leave
      path: '$.status' // access the 'status' property of "account-information"
    }, {
      fact: 'account-information',
      operator: 'contains', // the 'ptoDaysTaken' property (an array) must contain '2016-12-25'
      value: '2016-12-25',
      path: '$.ptoDaysTaken' // access the 'ptoDaysTaken' property of "account-information"
    }]
  },
  event: {
    type: 'microsoft-christmas-pto',
    params: {
      message: 'current microsoft employee taking christmas day off'
    }
  }
}
engine.addRule(microsoftRule)

/**
 * 'account-information' fact executes an api call and retrieves account data, feeding the results
 * into the engine.  The major advantage of this technique is that although there are THREE conditions
 * requiring this data, only ONE api call is made.  This results in much more efficient runtime performance
 * and fewer network requests.
 */
engine.addFact('account-information', function (params, almanac) {
  console.log('loading account information...')
  return almanac.factValue('accountId')
    .then((accountId) => {
      return apiClient.getAccountInformation(accountId)
    })
})

// define fact(s) known at runtime
let facts = { accountId: 'lincoln' }
engine
  .run(facts)
  .then(({ events }) => {
    console.log(facts.accountId + ' is a ' + events.map(event => event.params.message))
  })

/*
 * OUTPUT:
 *
 * loading account information... // <-- API call is made ONCE and results recycled for all 3 conditions
 * lincoln is a current microsoft employee taking christmas day off
 */

This is available in the examples

Debugging

To see what the engine is doing under the hood, debug output can be turned on via:

Node

DEBUG=json-rules-engine

Browser

// set debug flag in local storage & refresh page to see console output
localStorage.debug = 'json-rules-engine'

Related Projects

https://github.com/vinzdeveloper/json-rule-editor - configuration ui for json-rules-engine:

rule editor 2

License

ISC

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].