ExOKF.Graph.GraphBLAS (ex_okf v0.1.0)

Copy Markdown View Source

GraphBLAS-backed sparse graph (ExOKF extension).

Maps concept identifiers onto dense integer indices and will use ex_graphblas sparse relations for reachability, transitive closure, dependency analysis, and cycle detection.

Full acceleration lands in v0.2. In v0.1 this module implements the ExOKF.Graph.Backend behaviour by delegating to ExOKF.Graph.Adjacency so callers can select the backend without changing code paths.

Fields

FieldTypeDescription
adjacencyExOKF.Graph.Adjacency.t()Underlying adjacency graph used for v0.1 queries.
id_to_index%{optional(String.t()) => non_neg_integer()}Concept id → dense index.
index_to_id%{optional(non_neg_integer()) => String.t()}Dense index → concept id.

Example

%ExOKF.Graph.GraphBLAS{
  adjacency: %ExOKF.Graph.Adjacency{},
  id_to_index: %{"datasets/sales" => 0, "tables/customers" => 1, "tables/orders" => 2},
  index_to_id: %{0 => "datasets/sales", 1 => "tables/customers", 2 => "tables/orders"}
}

Summary

Types

t()

GraphBLAS-oriented graph handle (v0.1 delegates compute to adjacency).

Functions

Builds a GraphBLAS handle with dense id↔index maps.

Returns the number of directed edges (delegates to adjacency).

Returns all directed edges (delegates to adjacency).

Returns true when edge from → to exists (delegates to adjacency).

Returns the concept id for a dense integer index, or nil if unmapped.

Returns the dense integer index for a concept id, or nil if unmapped.

Returns sorted outbound neighbors of id (delegates to adjacency).

Returns the number of concept nodes (delegates to adjacency).

Returns concept ids reachable from id (delegates to adjacency).

Returns sorted inbound neighbors of id (delegates to adjacency).

Types

t()

@type t() :: %ExOKF.Graph.GraphBLAS{
  adjacency: ExOKF.Graph.Adjacency.t(),
  id_to_index: %{optional(String.t()) => non_neg_integer()},
  index_to_id: %{optional(non_neg_integer()) => String.t()}
}

GraphBLAS-oriented graph handle (v0.1 delegates compute to adjacency).

See the module documentation for field meanings.

Functions

build(bundle)

@spec build(ExOKF.Bundle.t()) :: t()

Builds a GraphBLAS handle with dense id↔index maps.

Parameters

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

Examples

iex> bundle = ExOKF.TestSupport.sample_bundle()
iex> g = ExOKF.Graph.GraphBLAS.build(bundle)
iex> is_integer(ExOKF.Graph.GraphBLAS.index_of(g, "tables/orders"))
true

edge_count(graph_blas)

@spec edge_count(t()) :: non_neg_integer()

Returns the number of directed edges (delegates to adjacency).

Parameters

  • graph (t/0) — GraphBLAS handle

edges(graph_blas)

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

Returns all directed edges (delegates to adjacency).

Parameters

  • graph (t/0) — GraphBLAS handle

has_edge?(graph_blas, from, to)

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

Returns true when edge from → to exists (delegates to adjacency).

Parameters

  • graph (t/0) — GraphBLAS handle
  • from (String.t()) — source concept id
  • to (String.t()) — target concept id

id_of(graph_blas, index)

@spec id_of(t(), non_neg_integer()) :: String.t() | nil

Returns the concept id for a dense integer index, or nil if unmapped.

Parameters

  • graph (t/0) — GraphBLAS handle
  • index (non_neg_integer()) — dense index

Examples

iex> g = ExOKF.Graph.GraphBLAS.build(ExOKF.TestSupport.sample_bundle())
iex> id = ExOKF.Graph.GraphBLAS.id_of(g, 0)
iex> is_binary(id)
true

index_of(graph_blas, id)

@spec index_of(t(), String.t()) :: non_neg_integer() | nil

Returns the dense integer index for a concept id, or nil if unmapped.

Parameters

  • graph (t/0) — GraphBLAS handle
  • id (String.t()) — concept id

Examples

iex> g = ExOKF.Graph.GraphBLAS.build(ExOKF.TestSupport.sample_bundle())
iex> ExOKF.Graph.GraphBLAS.index_of(g, "missing")
nil

neighbors(graph_blas, id)

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

Returns sorted outbound neighbors of id (delegates to adjacency).

Parameters

  • graph (t/0) — GraphBLAS handle
  • id (String.t()) — concept id

node_count(graph_blas)

@spec node_count(t()) :: non_neg_integer()

Returns the number of concept nodes (delegates to adjacency).

Parameters

  • graph (t/0) — GraphBLAS handle

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

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

Returns concept ids reachable from id (delegates to adjacency).

Parameters

reverse_neighbors(graph_blas, id)

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

Returns sorted inbound neighbors of id (delegates to adjacency).

Parameters

  • graph (t/0) — GraphBLAS handle
  • id (String.t()) — concept id