https://github.com/rpdevjesco/decisionrules
DecisionRules is a lightweight framework for defining and evaluating decision trees and rule sets.
https://github.com/rpdevjesco/decisionrules
Last synced: over 1 year ago
JSON representation
DecisionRules is a lightweight framework for defining and evaluating decision trees and rule sets.
- Host: GitHub
- URL: https://github.com/rpdevjesco/decisionrules
- Owner: RPDevJesco
- Created: 2024-04-03T03:18:18.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-03T05:02:30.000Z (over 2 years ago)
- Last Synced: 2025-04-13T03:18:18.074Z (over 1 year ago)
- Language: C#
- Size: 21.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# DecisionRules
# Overview
DecisionRules is a lightweight framework for defining and evaluating decision trees and rule sets. It provides a simple yet powerful way to encapsulate business logic and decision-making processes in a structured and maintainable manner. This framework can be used in various applications, including business process automation, data validation, and dynamic content generation.
# Features
Rule Engine: Allows defining and evaluating rules based on context data. Each rule consists of a condition and an action, where the action is executed if the condition evaluates to true.
Decision Tree: Supports creating and traversing decision trees, where each node represents a decision or action based on the evaluation of a condition.
Context Management: Provides a mechanism to store and manage context data, which is used for evaluating rules and decision trees.
# Use Cases
Business Process Automation: Automate decision-making in business workflows, such as approval processes, pricing strategies, and eligibility checks.
Data Validation: Define rules for validating input data in forms, APIs, or data processing pipelines.
Dynamic Content Generation: Use decision trees to dynamically generate content or recommendations based on user input or behavior.
# Getting Started
To get started with DecisionRules, you can create a new instance of the RuleSet and Tree classes and define your rules and decision nodes. Then, create a Context object to hold your data and evaluate your rules and decision trees against this context.
```cs
var ruleSet = new RuleSet();
ruleSet.AddRule(new Rule(
ctx => ctx.GetData("Age") >= 18,
ctx => Console.WriteLine("User is an adult.")));
var context = new Context();
context.SetData("Age", 25);
var ruleEvaluator = new RuleEvaluator(ruleSet);
ruleEvaluator.Evaluate(context);
```
# Complex Conditons & Rule Priority
```cs
// Example of combining conditions
Func conditionA = ctx => ctx.SomeValue > 10;
Func conditionB = ctx => ctx.AnotherValue == "Yes";
Func complexCondition = ctx => conditionA(ctx) && conditionB(ctx);
// Creating a rule with a complex condition
var complexRule = new Rule(complexCondition, someAction, priority: 1);
```
# Missing Features
Rule Persistence: Currently, there is no built-in mechanism to persist rules to a database or file system.
# Contributing
Contributions to the DecisionRules project are welcome. If you have ideas for new features or improvements, feel free to open an issue or submit a pull request.