Kreuzberg.Keyword (kreuzberg v4.4.2)

Copy Markdown View Source

Structure representing an extracted keyword with score and algorithm info.

Fields

  • :text - The keyword text
  • :score - Relevance score (algorithm-dependent)
  • :algorithm - Algorithm used for extraction (e.g., "yake", "rake")
  • :positions - Optional list of positions where keyword appears

Summary

Functions

Create a Keyword struct from a map.

Convert a Keyword struct to a map.

Types

t()

@type t() :: %Kreuzberg.Keyword{
  algorithm: String.t(),
  positions: [non_neg_integer()] | nil,
  score: float(),
  text: String.t()
}

Functions

from_map(data)

@spec from_map(map()) :: t()

Create a Keyword struct from a map.

Examples

iex> Kreuzberg.Keyword.from_map(%{
...>   "text" => "elixir",
...>   "score" => 0.95,
...>   "algorithm" => "yake"
...> })
%Kreuzberg.Keyword{
  text: "elixir",
  score: 0.95,
  algorithm: "yake",
  positions: nil
}

to_map(kw)

@spec to_map(t()) :: map()

Convert a Keyword struct to a map.

Examples

iex> kw = %Kreuzberg.Keyword{text: "elixir", score: 0.95, algorithm: "yake"}
iex> Kreuzberg.Keyword.to_map(kw)
%{
  "text" => "elixir",
  "score" => 0.95,
  "algorithm" => "yake",
  "positions" => nil
}