Nasty.AST.Answer (Nasty v0.3.0)
View SourceAnswer node representing an extracted answer to a question.
Used by question answering systems to represent candidate answers with confidence scores and supporting evidence.
Summary
Functions
Checks if answer meets a minimum confidence threshold.
Creates a new answer.
Sorts answers by confidence (highest first).
Types
@type answer_span() :: {sentence_idx :: non_neg_integer(), token_start :: non_neg_integer(), token_end :: non_neg_integer()}
Answer span location within a document.
The span consists of:
sentence_idx- Index of the sentence containing the answertoken_start- Starting token index within the sentencetoken_end- Ending token index (inclusive) within the sentence
@type t() :: %Nasty.AST.Answer{ confidence: float(), language: Nasty.AST.Node.language(), reasoning: String.t() | nil, source_sentence: Nasty.AST.Sentence.t() | nil, span: answer_span() | nil, text: String.t() }
Functions
Checks if answer meets a minimum confidence threshold.
Examples
iex> answer = Nasty.AST.Answer.new("test", 0.8, :en)
iex> Nasty.AST.Answer.confident?(answer, 0.7)
true
iex> Nasty.AST.Answer.confident?(answer, 0.9)
false
@spec new(String.t(), float(), Nasty.AST.Node.language(), keyword()) :: t()
Creates a new answer.
Examples
iex> answer = Nasty.AST.Answer.new("John Smith", 0.95, :en)
iex> answer.text
"John Smith"
iex> answer.confidence
0.95
Sorts answers by confidence (highest first).
Examples
iex> answers = [
...> Nasty.AST.Answer.new("low", 0.3, :en),
...> Nasty.AST.Answer.new("high", 0.9, :en),
...> Nasty.AST.Answer.new("mid", 0.6, :en)
...> ]
iex> sorted = Nasty.AST.Answer.sort_by_confidence(answers)
iex> Enum.map(sorted, & &1.text)
["high", "mid", "low"]