LangExtract.Span (LangExtract v0.9.0)

Copy Markdown View Source

An aligned extraction with its byte position in the source text.

byte_start and byte_end are nil when status is :not_found — the aligner refused to guess rather than ground the extraction at wrong offsets. Guard offset arithmetic with located?/1.

Summary

Functions

Whether the aligner grounded this span — status is :exact or :fuzzy, so the byte offsets are present.

Types

status()

@type status() :: :exact | :fuzzy | :not_found

t()

@type t() :: %LangExtract.Span{
  attributes: map(),
  byte_end: non_neg_integer() | nil,
  byte_start: non_neg_integer() | nil,
  class: String.t() | nil,
  status: status(),
  text: String.t()
}

Functions

located?(span)

@spec located?(t()) :: boolean()

Whether the aligner grounded this span — status is :exact or :fuzzy, so the byte offsets are present.

The filtering idiom for consumers doing offset arithmetic:

iex> spans = [
...>   %LangExtract.Span{text: "found", status: :exact, byte_start: 0, byte_end: 5},
...>   %LangExtract.Span{text: "lost", status: :not_found}
...> ]
iex> Enum.filter(spans, &LangExtract.Span.located?/1)
[%LangExtract.Span{text: "found", status: :exact, byte_start: 0, byte_end: 5}]