Code Monkey home page Code Monkey logo

feel's Introduction

About

FEEL is an expression language based on DMN specification conformance level 3. Written using PEG.js - JavaScript Parser Generator. FEEL is a very powerful language built with the purpose of defining rules in Business Rule Engines. FEEL also offers an API to implement and execute Decision Table defined in excel (.xlsx)

Getting Started

FEEL is not available on npm yet and will be published soon.

FEEL is a completely flexible library which can be used with any project to add support for Decision Table. It also comes with a powerful expression language termed FEEL built-in to define a multitude of decision rules.

Installation

Development

# npm install
npm install git+https://github.com/EdgeVerve/feel.git

Contribution

# git clone 
git clone https://github.com/EdgeVerve/feel.git

# install dependencies
npm install

# run test cases
npm test

Usage

Decision tables are defined in excel (.xlsx). Please check Sample Rules. Each cell in the body of the decision table has to be a valid FEEL expression. The following make use of FEEL parser to parse and execute expressions and hence the decision logic.

Excel to Decision Table

const { decisionTable } = require('feel');

const csv = decisionTable.xls_to_csv('./test/StudentFinancialPackageEligibility.xlsx');
const decision_table = decisionTable.csv_to_decision_table(csv[0]);

Execute Decision Table

The Decision Table (decision_table) created in the previous step can be executed using; decisionTable.execute_decision_table

const payload = {"Student GPA" : 3.6,"Student Extra-Curricular Activities Count" : 4,"Student National Honor Society Membership" : "Yes"};
decisionTable.execute_decision_table("StudentFinancialPackageEligibility", decision_table,payload, (results)=> {
    console.log(results)
});

Using FEEL Standalone

const {feel} = require('feel');

const rule = 'a + b - c';
const context = {
    a: 10,
    b: 20,
    c: 5
};

const parsedGrammar = feel.parse(rule);
parsedGrammar.build(context).then(result => {
    console.log(result);
}).catch(err => console.error(err));

Sample FEEL Expressions

Some valid FEEL expressions (logically categorized):

Arithmetic

  • a + b - c
  • ((a + b)/c - (d + e*2))**f
  • 1-(1+rate/12)**-term
  • (a + b)**-c

Comparision

  • 5 in (<= 5)
  • 5 in ((5..10])
  • 5 in ([5..10])
  • 5 in (4,5,6)
  • 5 in (<5,>5)
  • (a + 5) >= (7 + g)
  • (a+b) between (c + d) and (e - f)

Conjunction

  • a or b
  • a and b
  • ((a or b) and (b or c)) or (a and d)
  • ((a > b) and (a > c)) and (b > c)
  • ((a + b) > (c - d)) and (a > b)
  • a or b or a > b
  • (x(i, j) = y) and (a > b)
  • (a + b) > (c - d) and (a > b)

For

  • for a in [1,2,3] return a * a
  • for age in [18..40], name in ["george", "mike", "bob"] return status

Function Definition

  • function(age) age < 21
  • function(rate, term, amount) (amount*rate/12)/(1-(1+rate/12)**-term)

If

  • if applicant.maritalStatus in ("M", "S") then "valid" else "not valid"
  • if Pre-Bureau Risk Category = "DECLINE" or Installment Affordable = false or Age < 18 or Monthly Income < 100 then "INELIGIBLE" else "ELIGIBLE"
  • if "Pre-Bureau Risk Category" = "DECLINE" or "Installment Affordable" = false or Age < 18 or "Monthly Income" < 100 then "INELIGIBLE" else "ELIGIBLE"

Quantified

  • some ch in credit history satisfies ch.event = "bankruptcy"

Please note: This is not a complete list of FEEL Expressions. Please refer DMN Specification Document for detailed documentation on FEEL grammar.

Sample Rules

Validation.xlsx

PostBureauRiskCategory.xlsx

ElectricityBill.xlsx

Reference

For comprehensive set of documentation on DMN, you can refer to :

DMN Specification Document

feel's People

Contributors

pragyandas avatar

Stargazers

Sachin Mane avatar

Watchers

Sachin Mane avatar

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.