ExOKF.Query (ex_okf v0.1.0)

Copy Markdown View Source

High-level query helpers over an OKF bundle.

Filters are ANDed together. Unknown filter keys are ignored (match fails).

Summary

Types

A single query filter.

Functions

Returns concepts that link to concept_id (backlinks).

Finds a concept by id.

Queries concepts matching all given filters.

Returns all distinct tags in the bundle, sorted.

Returns all distinct concept types in the bundle, sorted.

Types

filter()

@type filter() ::
  {:type, String.t() | Regex.t()}
  | {:tag, String.t()}
  | {:id, String.t() | Regex.t()}
  | {:has_resource, boolean()}

A single query filter.

  • {:type, String.t() | Regex.t()} — exact or regex match on concept.type

  • {:tag, String.t()} — concept must include this tag
  • {:id, String.t() | Regex.t()} — exact or regex match on concept.id

  • {:has_resource, boolean()} — require / forbid a non-empty resource

Examples

{:type, "BigQuery Table"}
{:type, ~r/Table/}
{:tag, "sales"}
{:id, "tables/orders"}
{:id, ~r/^tables\//}
{:has_resource, true}

Functions

backlinks(bundle, concept_id)

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

Returns concepts that link to concept_id (backlinks).

Parameters

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

Examples

iex> bundle = ExOKF.TestSupport.sample_bundle()
iex> ids = ExOKF.Query.backlinks(bundle, "tables/customers") |> Enum.map(& &1.id)
iex> "tables/orders" in ids
true

get(bundle, id)

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

Finds a concept by id.

Parameters

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

Returns

The concept, or nil if not found.

Examples

iex> bundle = ExOKF.TestSupport.sample_bundle()
iex> ExOKF.Query.get(bundle, "tables/orders").title
"Orders"

query(bundle, filters \\ [])

@spec query(ExOKF.Bundle.t(), [filter()] | keyword()) :: [ExOKF.Concept.t()]

Queries concepts matching all given filters.

Parameters

  • bundle (ExOKF.Bundle.t()) — loaded OKF bundle
  • filters ([t:filter/0] | keyword()) — AND-combined filters

Returns

A list of matching ExOKF.Concept.t() (order follows ExOKF.Bundle.concepts/1).

Examples

iex> bundle = ExOKF.TestSupport.sample_bundle()
iex> ids = ExOKF.Query.query(bundle, type: "BigQuery Table") |> Enum.map(& &1.id)
iex> "tables/orders" in ids
true

tags(bundle)

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

Returns all distinct tags in the bundle, sorted.

Parameters

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

Examples

iex> bundle = ExOKF.TestSupport.sample_bundle()
iex> "sales" in ExOKF.Query.tags(bundle)
true

types(bundle)

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

Returns all distinct concept types in the bundle, sorted.

Parameters

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

Examples

iex> bundle = ExOKF.TestSupport.sample_bundle()
iex> ExOKF.Query.types(bundle)
["BigQuery Dataset", "BigQuery Table"]