Nasty.Interop.IntentRecognizer (Nasty v0.3.0)

View Source

Recognizes 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

  1. Sentence function - Determines intent type:

    • Imperative → :action
    • Interrogative → :query
    • Declarative → :definition
    • Conditional markers → :conditional
  2. Semantic frames - Extracts action and parameters:

    • Predicate → action verb
    • Agent/Theme → target (what to act on)
    • Patient/Goal → arguments
    • Modifiers → constraints
  3. Verb mapping - Maps English verbs to code operations:

    • "sort" → Enum.sort
    • "filter" → Enum.filter
    • "map" → Enum.map
    • "calculate", "compute" → arithmetic ops

Summary

Functions

Recognizes intent from a sentence.

Recognizes intent from text by first parsing it.

Functions

recognize(sentence)

@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"

recognize_from_text(text, opts \\ [language: :en])

@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"