Nasty.AST.Intent (Nasty v0.3.0)
View SourceIntent node representing the semantic intent extracted from natural language.
Intent is the bridge between natural language AST and code AST, capturing the action, target, and parameters needed for code generation.
Intent Types
:action- Imperative command to perform an operation (e.g., "Sort the list"):query- Interrogative question requiring a boolean answer (e.g., "Is X greater than Y?"):definition- Declarative statement defining a value (e.g., "X is 5"):conditional- Conditional statement with condition and consequence (e.g., "If X then Y")
Examples
# Action intent: "Sort the numbers"
%Intent{
type: :action,
action: "sort",
target: "numbers",
arguments: [],
confidence: 0.95
}
# Query intent: "Is the count greater than 10?"
%Intent{
type: :query,
action: "is_greater_than",
target: "count",
arguments: [10],
confidence: 0.90
}
# Definition intent: "The result equals X plus Y"
%Intent{
type: :definition,
action: "assign",
target: "result",
arguments: ["+", "x", "y"],
confidence: 0.88
}
Summary
Functions
Checks if intent represents an action (imperative command).
Adds a constraint to the intent.
Returns all arguments including target if present.
Checks if intent represents a conditional statement.
Checks if intent represents a definition (declarative statement).
Checks if intent has high confidence (>= 0.8).
Creates a new intent.
Checks if intent represents a query (interrogative question).
Sets the confidence score for the intent.
Types
Semantic constraint for filtering or predicates.
Examples:
{:comparison, :greater_than, 5}{:equality, "admin"}{:membership, ["active", "pending"]}
@type intent_type() :: :action | :query | :definition | :conditional
Intent type classification.
:action- Imperative command (function call):query- Interrogative question (assertion/test):definition- Declarative statement (variable assignment):conditional- Conditional logic (if/case expression)
@type t() :: %Nasty.AST.Intent{ action: String.t(), arguments: [term()], confidence: float(), constraints: [constraint()], language: Nasty.AST.Node.language(), metadata: map(), span: Nasty.AST.Node.span(), target: String.t() | nil, type: intent_type() }
Functions
Checks if intent represents an action (imperative command).
Examples
iex> intent = %Nasty.AST.Intent{type: :action, ...}
iex> Nasty.AST.Intent.action?(intent)
true
@spec add_constraint(t(), constraint()) :: t()
Adds a constraint to the intent.
Examples
iex> intent = %Nasty.AST.Intent{...}
iex> intent = Nasty.AST.Intent.add_constraint(intent, {:comparison, :greater_than, 5})
iex> intent.constraints
[{:comparison, :greater_than, 5}]
Returns all arguments including target if present.
Examples
iex> intent = %Nasty.AST.Intent{target: "list", arguments: ["fn", "x"]}
iex> Nasty.AST.Intent.all_arguments(intent)
["list", "fn", "x"]
Checks if intent represents a conditional statement.
Examples
iex> intent = %Nasty.AST.Intent{type: :conditional, ...}
iex> Nasty.AST.Intent.conditional?(intent)
true
Checks if intent represents a definition (declarative statement).
Examples
iex> intent = %Nasty.AST.Intent{type: :definition, ...}
iex> Nasty.AST.Intent.definition?(intent)
true
Checks if intent has high confidence (>= 0.8).
Examples
iex> intent = %Nasty.AST.Intent{confidence: 0.9, ...}
iex> Nasty.AST.Intent.high_confidence?(intent)
true
@spec new( intent_type(), String.t(), Nasty.AST.Node.language(), Nasty.AST.Node.span(), keyword() ) :: t()
Creates a new intent.
Examples
iex> span = Nasty.AST.Node.make_span({1, 0}, 0, {1, 15}, 15)
iex> intent = Nasty.AST.Intent.new(:action, "sort", :en, span, target: "list")
iex> intent.type
:action
iex> intent.action
"sort"
iex> intent.target
"list"
Checks if intent represents a query (interrogative question).
Examples
iex> intent = %Nasty.AST.Intent{type: :query, ...}
iex> Nasty.AST.Intent.query?(intent)
true
Sets the confidence score for the intent.
Examples
iex> intent = %Nasty.AST.Intent{...}
iex> intent = Nasty.AST.Intent.set_confidence(intent, 0.95)
iex> intent.confidence
0.95