Choreo.Lab.DSL.DecisionTree (Choreo v0.12.0)

Copy Markdown View Source

Experimental Livebook-friendly DSL for sketching decision trees.

This Lab DSL compiles to the stable, pipe-first Choreo.DecisionTree builders and returns an ordinary %Choreo.DecisionTree{}. It is useful for interview decision policies, routing rules, fallback strategies, and tradeoff walkthroughs.

Examples

iex> import Choreo.Lab.DSL.DecisionTree
...> tree = decision_tree do
...>   traffic = root("Traffic Source", feature: "source")
...>   authenticated = decision("Authenticated?", feature: "auth")
...>   reject = outcome("Reject", class: "403")
...>   route = outcome("Route Request", class: "route")
...>
...>   traffic ~> authenticated |> when_("api")
...>   edge authenticated ~> reject, "no"
...>   branch authenticated ~> route, "yes"
...> end
iex> Choreo.DecisionTree.root(tree)
:traffic
iex> Choreo.DecisionTree.condition(tree, :authenticated, :route)
"yes"

Branch conditions can use pipe modifiers or explicit branch forms:

root ~> decision |> when_("api")
decision ~> outcome |> condition("yes")
edge decision ~> outcome, "yes"
branch decision ~> outcome, "yes"

Summary

Types

branch_decl()

@type branch_decl() :: %{
  from: Yog.node_id(),
  to: Yog.node_id(),
  condition: String.t()
}

node_decl()

@type node_decl() :: %{id: Yog.node_id(), builder: atom(), opts: keyword()}

Functions

branch(arg1 \\ nil, arg2 \\ nil, opts \\ [])

decision(arg1 \\ nil, arg2 \\ nil, opts \\ [])

decision_tree(list)

(macro)

Builds a %Choreo.DecisionTree{} from a compact Lab DSL block.

decision_tree(opts, list)

(macro)

leaf(arg1 \\ nil, arg2 \\ nil, opts \\ [])

outcome(arg1 \\ nil, arg2 \\ nil, opts \\ [])

question(arg1 \\ nil, arg2 \\ nil, opts \\ [])

result(arg1 \\ nil, arg2 \\ nil, opts \\ [])

root(arg1 \\ nil, arg2 \\ nil, opts \\ [])

taxonomy()

@spec taxonomy() :: %{
  nodes: [atom()],
  edges: [atom()],
  modifiers: [atom()],
  options: [atom()]
}

Returns the vocabulary supported by the decision-tree DSL.

iex> taxonomy = Choreo.Lab.DSL.DecisionTree.taxonomy()
iex> :root in taxonomy.nodes
true
iex> :branch in taxonomy.edges
true
iex> :when_ in taxonomy.modifiers
true

verbs()

@spec verbs() :: map()

Compatibility alias for taxonomy/0.