RulezenexEngine (rulezenex v0.1.1)

Copy Markdown View Source

GoRules ZEN evaluating JSON Decision Model (JDM) graphs in-process.

A graph is the map the JDM Editor produces; a context is any map.

iex> RulezenexEngine.evaluate(graph, %{"amount" => 120})
{:ok, %{"tier" => "high"}}

Set RULEZENEX_NIF_PREBUILT=1 at compile time to load a library built elsewhere (priv/native/librulezenex.so of this application) instead of compiling the crate.

Summary

Functions

Evaluates graph with context. Returns {:ok, result} with the output node's value, or {:error, reason}. With trace: true the result also holds the evaluation trace under "trace".

A traced evaluation. Returns {:ok, %{"result" => _, "trace" => _, "performance" => _}} or {:error, reason}.

Checks that graph is a well-formed decision graph.

Functions

evaluate(graph, context, opts \\ [])

@spec evaluate(map(), map(), keyword()) :: {:ok, map()} | {:error, term()}

Evaluates graph with context. Returns {:ok, result} with the output node's value, or {:error, reason}. With trace: true the result also holds the evaluation trace under "trace".

simulate(graph, context)

@spec simulate(map(), map()) :: {:ok, map()} | {:error, term()}

A traced evaluation. Returns {:ok, %{"result" => _, "trace" => _, "performance" => _}} or {:error, reason}.

validate(graph)

@spec validate(map()) :: :ok | {:error, String.t()}

Checks that graph is a well-formed decision graph.