ExOKF.Bundle (ex_okf v0.1.0)

Copy Markdown View Source

An in-memory OKF knowledge bundle — the unit of distribution (OKF §3).

Holds concepts, reserved index/log documents, parse diagnostics, and an optional graph index built from internal links.

Fields

FieldTypeDescription
rootString.t()Absolute filesystem path to the bundle directory.
okf_versionString.t() | nilDeclared version from root index.md frontmatter, e.g. "0.1".
concepts%{optional(String.t()) => ExOKF.Concept.t()}Map of concept id → concept.
indexes%{optional(String.t()) => ExOKF.Index.t()}Map of relative path → index doc.
logs%{optional(String.t()) => ExOKF.Log.t()}Map of relative path → log doc.
diagnosticsExOKF.Diagnostics.t()Parse/load diagnostics accumulated while reading.
graphmap() | nilOpaque graph handle %{backend: module(), data: term()} after indexing.

Example

%ExOKF.Bundle{
  root: "/data/acme-knowledge",
  okf_version: "0.1",
  concepts: %{"tables/orders" => %ExOKF.Concept{id: "tables/orders", path: "tables/orders.md", type: "BigQuery Table"}},
  indexes: %{"index.md" => %ExOKF.Index{path: "index.md", directory: ""}},
  logs: %{"log.md" => %ExOKF.Log{path: "log.md", directory: ""}},
  diagnostics: %ExOKF.Diagnostics{entries: []},
  graph: %{backend: ExOKF.Graph.Adjacency, data: %ExOKF.Graph.Adjacency{}}
}

Summary

Types

t()

An loaded OKF bundle.

Functions

Returns all concept ids present in the bundle, sorted.

Lists all concepts sorted by id.

Returns the concept with the given id, or nil if absent.

Returns true when the concept id exists in the bundle.

Merges additional diagnostics into the bundle.

Attaches or replaces the graph index on the bundle.

Returns the number of concepts in the bundle.

Types

t()

@type t() :: %ExOKF.Bundle{
  concepts: %{optional(String.t()) => ExOKF.Concept.t()},
  diagnostics: ExOKF.Diagnostics.t(),
  graph: map() | nil,
  indexes: %{optional(String.t()) => ExOKF.Index.t()},
  logs: %{optional(String.t()) => ExOKF.Log.t()},
  okf_version: String.t() | nil,
  root: String.t()
}

An loaded OKF bundle.

See the module documentation for field meanings and a structural example.

Functions

concept_ids(bundle)

@spec concept_ids(t()) :: [String.t()]

Returns all concept ids present in the bundle, sorted.

Parameters

  • bundle (t/0) — loaded bundle

Examples

iex> bundle = ExOKF.TestSupport.minimal_bundle()
iex> ExOKF.Bundle.concept_ids(bundle)
["hello"]

concepts(bundle)

@spec concepts(t()) :: [ExOKF.Concept.t()]

Lists all concepts sorted by id.

Parameters

  • bundle (t/0) — loaded bundle

Examples

iex> bundle = ExOKF.TestSupport.sample_bundle()
iex> ExOKF.Bundle.concepts(bundle) |> Enum.map(& &1.id)
["datasets/sales", "tables/customers", "tables/orders"]

get_concept(bundle, id)

@spec get_concept(t(), String.t()) :: ExOKF.Concept.t() | nil

Returns the concept with the given id, or nil if absent.

Parameters

  • bundle (t/0) — loaded bundle
  • id (String.t()) — concept id, e.g. "tables/orders"

Examples

iex> bundle = ExOKF.TestSupport.minimal_bundle()
iex> ExOKF.Bundle.get_concept(bundle, "hello").type
"Reference"

iex> bundle = ExOKF.TestSupport.minimal_bundle()
iex> ExOKF.Bundle.get_concept(bundle, "missing")
nil

has_concept?(bundle, id)

@spec has_concept?(t(), String.t()) :: boolean()

Returns true when the concept id exists in the bundle.

Parameters

  • bundle (t/0) — loaded bundle
  • id (String.t()) — concept id

Examples

iex> bundle = ExOKF.TestSupport.minimal_bundle()
iex> ExOKF.Bundle.has_concept?(bundle, "hello")
true

put_diagnostics(bundle, diags)

@spec put_diagnostics(t(), ExOKF.Diagnostics.t()) :: t()

Merges additional diagnostics into the bundle.

Parameters

  • bundle (t/0) — loaded bundle
  • diags (ExOKF.Diagnostics.t()) — diagnostics to append

Examples

iex> bundle = ExOKF.TestSupport.minimal_bundle()
iex> extra = ExOKF.Diagnostics.new([
...>   %ExOKF.Diagnostic{severity: :info, code: :note, message: "hello"}
...> ])
iex> updated = ExOKF.Bundle.put_diagnostics(bundle, extra)
iex> Enum.any?(updated.diagnostics.entries, &(&1.code == :note))
true

put_graph(bundle, graph)

@spec put_graph(t(), term()) :: t()

Attaches or replaces the graph index on the bundle.

Prefer ExOKF.Graph.index/2, which builds the graph and calls this.

Parameters

  • bundle (t/0) — loaded bundle
  • graph (term()) — opaque graph handle, typically %{backend: module(), data: term()}

Examples

iex> bundle = ExOKF.TestSupport.minimal_bundle()
iex> indexed = ExOKF.Bundle.put_graph(bundle, %{backend: ExOKF.Graph.Adjacency, data: %{}})
iex> match?(%{backend: _, data: _}, indexed.graph)
true

size(bundle)

@spec size(t()) :: non_neg_integer()

Returns the number of concepts in the bundle.

Parameters

  • bundle (t/0) — loaded bundle

Examples

iex> bundle = ExOKF.TestSupport.sample_bundle()
iex> ExOKF.Bundle.size(bundle)
3