Nasty.Interop.IntentRecognizer (Nasty v0.3.0)
View SourceRecognizes intents from natural language sentences using semantic role labeling.
This module acts as the bridge between natural language AST and code generation, extracting the action, target, and arguments needed to generate executable code.
Intent Recognition Strategy
Sentence function - Determines intent type:
- Imperative → :action
- Interrogative → :query
- Declarative → :definition
- Conditional markers → :conditional
Semantic frames - Extracts action and parameters:
- Predicate → action verb
- Agent/Theme → target (what to act on)
- Patient/Goal → arguments
- Modifiers → constraints
Verb mapping - Maps English verbs to code operations:
- "sort" → Enum.sort
- "filter" → Enum.filter
- "map" → Enum.map
- "calculate", "compute" → arithmetic ops
Summary
Functions
@spec recognize(Nasty.AST.Sentence.t()) :: {:ok, Nasty.AST.Intent.t()} | {:error, term()}
Recognizes intent from a sentence.
Examples
iex> {:ok, document} = English.parse("Sort the list.")
iex> sentence = List.first(document.paragraphs |> List.first() |> Map.get(:sentences))
iex> {:ok, intent} = IntentRecognizer.recognize(sentence)
iex> intent.type
:action
iex> intent.action
"sort"
@spec recognize_from_text( String.t(), keyword() ) :: {:ok, Nasty.AST.Intent.t()} | {:error, term()}
Recognizes intent from text by first parsing it.
Examples
iex> {:ok, intent} = IntentRecognizer.recognize_from_text("Filter the users by role.", language: :en)
iex> intent.action
"filter"