Logistiki.Knowledge.Facts (logistiki v0.1.0)

Copy Markdown View Source

Generates runtime Datalog facts from a normalized business event.

The event is represented in the Datalog program by the fixed atom :evt. Generated facts are added to the program before materialization.

Generated relations

RelationArityExample
event_type2{:evt, :deposit_received}
event_currency2{:evt, "USD"}
event_amount_cents2{:evt, 100000}
event_fee_type2{:evt, :wire_fee}
event_entity_type2{:evt, :corporate}
event_product2{:evt, :retail_deposit}
event_account2{:evt, "LIABILITIES:CLIENT_DEPOSITS:USD:ACME:OPERATING"}
event_cash_account2{:evt, "ASSETS:CASH:USD:NOSTRO"}
event_fee_income_account2{:evt, "INCOME:FEES:WIRE"}
event_interest_expense_account2{:evt, "EXPENSES:INTEREST"}
event_destination_account2{:evt, "LIABILITIES:CLIENT_DEPOSITS:USD:ACME:PAYROLL"}

Only fields with non-nil values generate facts.

Summary

Functions

Returns the fixed event identifier used inside the Datalog program.

Generates a list of {relation, values} facts for normalized.

Functions

event_id()

(since 0.1.0)
@spec event_id() :: :evt

Returns the fixed event identifier used inside the Datalog program.

Returns

  • :evt — the atom representing the current event in all Datalog rules.

Examples

iex> Logistiki.Knowledge.Facts.event_id()
:evt

generate(event)

(since 0.1.0)
@spec generate(Logistiki.Event.Normalized.t()) :: [{atom(), [term()]}]

Generates a list of {relation, values} facts for normalized.

Arguments

  • normalized%Logistiki.Event.Normalized{} — the flattened event.

Returns

  • [{atom(), [term()]}] — a list of {relation_name, argument_list} tuples ready to be added to the Datalog program.

Examples

iex> facts = Logistiki.Knowledge.Facts.generate(%Logistiki.Event.Normalized{
...>   type: "deposit_received", amount: Decimal.new("1000.00"), currency: "USD",
...>   account_code: "LIAB:ACME", cash_account_code: "ASSETS:CASH"
...> })
iex> {:event_type, [:evt, :deposit_received]} in facts
true
iex> {:event_currency, [:evt, "USD"]} in facts
true
iex> {:event_amount_cents, [:evt, 100000]} in facts
true