Code Monkey home page Code Monkey logo

Comments (4)

CacheControl avatar CacheControl commented on May 14, 2024

@arsalans interesting concept. My understanding of decision trees is that for each permutation of the conditions, there is a defined set of actions. Although it would be easy for the engine to take in a list of conditions and compute a rule per permutation, I'm confused as to how the engine would know the appropriate event to fire in each circumstance. Maybe I just need you to expand on the use case you provided so I can understand the problem you're trying to solve.

from json-rules-engine.

arsalans avatar arsalans commented on May 14, 2024

@CacheControl So, how about if I write my rule like this, and again, I am trying to be as naive as possible:

var decisionTable = 
{
	{
		"color": "Blue",
		"price": 10
	},
	{
		"color": "Red",
		"price": 11
	},
	{
		"color": "Green",
		"price": 13
	},
	{
		"color": "Yellow",
		"price": 14
	}
};
var helper =
{
	"condition": "color",
	"event": "price"
};

new DecisionTable (decisionTable, helper);

So now, the DecisionTable object knows what are the conditions and what are the events to send.

from json-rules-engine.

CacheControl avatar CacheControl commented on May 14, 2024

@arsalans Ah ok, I think I get it now. In json-rules-engine vernacular it's essentially wanting to vary the event based on which condition succeeded.

To me, this almost feels like an accessory package that would act as a rule generator - it would take in the decision tree data structure you posted above, and use it to generate a rule per decisionTable row. json-rules-engine would be responsible for the lower-level execution of the generated rules.

Alternatively, you may want to look at the ruleResult feature just released in 2.0.0 - you can use the ruleResult argument provided in the success/failure events to determine which condition was successful, and use the condition's factResult("yellow", "red", etc) to lookup from a prices hash you maintain outside the engine.

It terms of whether or not this belongs in json-rules-engine itself, right now it feels like something I'd like to keep separate; I want to keep json-rules-engine as the low level executor of basic boolean logic + firing events, while more complex rule orchestrations such as decisionTables are probably better suited as plugins/extensions.

from json-rules-engine.

CacheControl avatar CacheControl commented on May 14, 2024

Here's the ruleResult docs I mentioned above.

from json-rules-engine.

Related Issues (20)

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.