Nasty.Translation.ASTTransformer (Nasty v0.3.0)

View Source

Transforms Abstract Syntax Trees between languages.

Orchestrates the complete translation pipeline:

  1. Token translation (word-level)
  2. Word order adjustment (phrase structure)
  3. Agreement enforcement (morphology)

Works recursively on AST nodes from top to bottom.

Usage

alias Nasty.AST.Document
alias Nasty.Translation.ASTTransformer

# Transform complete document
{:ok, translated_doc} = ASTTransformer.transform(document, :en, :es)

Summary

Functions

Transforms an AST node from source to target language.

Functions

transform(node, source_lang, target_lang)

@spec transform(term(), atom(), atom()) :: {:ok, term()} | {:error, term()}

Transforms an AST node from source to target language.

Returns {:ok, transformed_node} or {:error, reason}.

Examples

iex> doc = %Document{language: :en, ...}
iex> ASTTransformer.transform(doc, :en, :es)
{:ok, %Document{language: :es, ...}}