Loads and evaluates the accounting knowledge program for a single event.
Given a normalized event, this module:
- generates runtime facts (
Logistiki.Knowledge.Facts) - builds a program from
Logistiki.Knowledge.Program(with static facts) - adds the runtime facts
- materializes the Datalog knowledge
- interprets the result into a
Logistiki.Knowledge.Result
Datalog decides facts and relationships; Elixir interprets them.
Summary
Functions
Lists all derived account roles for an event.
Lists all derived policy facts for an event (useful for tests).
Evaluates the knowledge layer for normalized_event and interprets the result.
Interprets materialized knowledge into a Logistiki.Knowledge.Result.
Materializes the knowledge program with the runtime facts for event.
Returns the raw ExDatalog.Knowledge for inspection/debugging.
Functions
@spec derived_account_roles(ExDatalog.Knowledge.t()) :: %{ required(atom()) => String.t() }
Lists all derived account roles for an event.
Arguments
knowledge—%ExDatalog.Knowledge{}.
Returns
%{atom() => String.t()}— role-to-code map.
Examples
iex> Logistiki.Knowledge.KnowledgeBase.derived_account_roles(knowledge)
%{cash_account: "ASSETS:CASH:USD:NOSTRO"}
@spec derived_policies(ExDatalog.Knowledge.t()) :: [atom()]
Lists all derived policy facts for an event (useful for tests).
Arguments
knowledge—%ExDatalog.Knowledge{}.
Returns
[atom()]— the derived policy atoms.
Examples
iex> Logistiki.Knowledge.KnowledgeBase.derived_policies(knowledge)
[:cash_deposit]
@spec evaluate( Logistiki.Event.Normalized.t(), keyword() ) :: {:ok, Logistiki.Knowledge.Result.t()} | {:error, term()}
Evaluates the knowledge layer for normalized_event and interprets the result.
Arguments
normalized_event—%Logistiki.Event.Normalized{}.opts—keyword()— passed toExDatalog.materialize/2.
Returns
{:ok, %Logistiki.Knowledge.Result{}}— the interpreted result withpolicy,template_postings,account_roles,blocked, etc.{:error, term()}— materialization failed.
Examples
iex> {:ok, result} = Logistiki.Knowledge.KnowledgeBase.evaluate(normalized_event)
iex> result.policy
:cash_deposit
@spec interpret(ExDatalog.Knowledge.t(), Logistiki.Event.Normalized.t()) :: Logistiki.Knowledge.Result.t()
Interprets materialized knowledge into a Logistiki.Knowledge.Result.
Extracts derived policies, account roles, template postings, and required
dimensions, selects the policy (unique, first-sorted on ambiguity, or nil),
and builds the Result.
Arguments
knowledge—%ExDatalog.Knowledge{}— materialized knowledge.normalized_event—%Logistiki.Event.Normalized{}— for the event id.
Returns
%Logistiki.Knowledge.Result{}— the interpreted result.
Examples
iex> {:ok, knowledge} = Logistiki.Knowledge.KnowledgeBase.materialize_for(normalized_event)
iex> result = Logistiki.Knowledge.KnowledgeBase.interpret(knowledge, normalized_event)
iex> result.policy
:cash_deposit
@spec materialize_for( Logistiki.Event.Normalized.t(), keyword() ) :: {:ok, ExDatalog.Knowledge.t()} | {:error, term()}
Materializes the knowledge program with the runtime facts for event.
Arguments
normalized_event—%Logistiki.Event.Normalized{}.opts—keyword()— passed toExDatalog.materialize/2.
Returns
{:ok, %ExDatalog.Knowledge{}}— materialized knowledge with all derived facts.{:error, term()}— materialization failed.
Examples
iex> {:ok, knowledge} = Logistiki.Knowledge.KnowledgeBase.materialize_for(normalized_event)
iex> ExDatalog.Knowledge.get(knowledge, "policy")
MapSet.new({:evt, :cash_deposit})
@spec raw_knowledge( Logistiki.Event.Normalized.t(), keyword() ) :: {:ok, ExDatalog.Knowledge.t()} | {:error, term()}
Returns the raw ExDatalog.Knowledge for inspection/debugging.
Arguments
normalized_event—%Logistiki.Event.Normalized{}.opts—keyword()— passed toExDatalog.materialize/2.
Returns
{:ok, %ExDatalog.Knowledge{}}|{:error, term()}
Examples
iex> {:ok, knowledge} = Logistiki.Knowledge.KnowledgeBase.raw_knowledge(normalized_event)