ExOKF.Graph (ex_okf v0.1.0)

Copy Markdown View Source

Graph indexing and traversal over OKF concept links.

Dispatches to an ExOKF.Graph.Backend implementation. The default is the native adjacency backend (ExOKF.Graph.Adjacency).

After indexing, bundle.graph is %{backend: module(), data: term()}.

Example

{:ok, bundle} = ExOKF.load("path/to/bundle")
bundle = ExOKF.Graph.index(bundle)
ExOKF.Graph.neighbors(bundle, "tables/orders")
#=> ["datasets/sales", "tables/customers"]

ExOKF.Graph.stats(bundle)
#=> %{nodes: 3, edges: 6, backend: ExOKF.Graph.Adjacency}

Summary

Types

A module implementing ExOKF.Graph.Backend.

Functions

Lists available graph backend modules.

Returns all directed edges {from, to}.

Indexes the bundle's internal links using the given backend.

Returns outbound neighbors of a concept.

Returns concept ids reachable from id.

Returns inbound neighbors (backlinks) of a concept.

Returns graph summary statistics.

Types

backend()

@type backend() :: module()

A module implementing ExOKF.Graph.Backend.

Examples

ExOKF.Graph.Adjacency
ExOKF.Graph.GraphBLAS

Functions

backends()

@spec backends() :: [module()]

Lists available graph backend modules.

Examples

iex> ExOKF.Graph.backends()
[ExOKF.Graph.Adjacency, ExOKF.Graph.GraphBLAS]

edges(bundle)

@spec edges(ExOKF.Bundle.t()) :: [{String.t(), String.t()}]

Returns all directed edges {from, to}.

Parameters

  • bundle (ExOKF.Bundle.t()) — loaded OKF bundle

Examples

iex> bundle = ExOKF.TestSupport.sample_bundle()
iex> {"tables/orders", "tables/customers"} in ExOKF.Graph.edges(bundle)
true

index(bundle, backend \\ Adjacency)

@spec index(ExOKF.Bundle.t(), backend()) :: ExOKF.Bundle.t()

Indexes the bundle's internal links using the given backend.

Parameters

Returns

The same bundle with graph set to %{backend: module(), data: term()}.

Examples

iex> bundle = ExOKF.TestSupport.sample_bundle()
iex> indexed = ExOKF.Graph.index(bundle, ExOKF.Graph.Adjacency)
iex> indexed.graph.backend
ExOKF.Graph.Adjacency

neighbors(bundle, id)

@spec neighbors(ExOKF.Bundle.t(), String.t()) :: [String.t()]

Returns outbound neighbors of a concept.

Lazily indexes the bundle with the default backend when graph is nil.

Parameters

  • bundle (ExOKF.Bundle.t()) — loaded OKF bundle
  • id (String.t()) — concept id

Examples

iex> bundle = ExOKF.TestSupport.sample_bundle()
iex> "tables/customers" in ExOKF.Graph.neighbors(bundle, "tables/orders")
true

reachable(bundle, id, opts \\ [])

@spec reachable(ExOKF.Bundle.t(), String.t(), keyword()) :: [String.t()]

Returns concept ids reachable from id.

Parameters

  • bundle (ExOKF.Bundle.t()) — loaded OKF bundle
  • id (String.t()) — start concept id
  • opts (keyword()) — passed to the backend:
    • :max_depth (pos_integer() \| :infinity) — hop limit (default :infinity)
    • :include_self (boolean()) — include id (default false)

Examples

iex> bundle = ExOKF.TestSupport.sample_bundle()
iex> ExOKF.Graph.reachable(bundle, "tables/orders", max_depth: 1) |> Enum.sort()
["datasets/sales", "tables/customers"]

reverse_neighbors(bundle, id)

@spec reverse_neighbors(ExOKF.Bundle.t(), String.t()) :: [String.t()]

Returns inbound neighbors (backlinks) of a concept.

Parameters

  • bundle (ExOKF.Bundle.t()) — loaded OKF bundle
  • id (String.t()) — concept id

Examples

iex> bundle = ExOKF.TestSupport.sample_bundle()
iex> "tables/orders" in ExOKF.Graph.reverse_neighbors(bundle, "tables/customers")
true

stats(bundle)

@spec stats(ExOKF.Bundle.t()) :: %{
  nodes: non_neg_integer(),
  edges: non_neg_integer(),
  backend: module()
}

Returns graph summary statistics.

Parameters

  • bundle (ExOKF.Bundle.t()) — loaded OKF bundle

Returns

%{nodes: non_neg_integer(), edges: non_neg_integer(), backend: module()}

Examples

iex> bundle = ExOKF.TestSupport.sample_bundle()
iex> stats = ExOKF.Graph.stats(bundle)
iex> {stats.nodes, stats.backend}
{3, ExOKF.Graph.Adjacency}