\name{apply_translation_rules}
\alias{apply_translation_rules}
\title{Apply Translation Rules to a Bracketed Structure String}
\description{
Translates a bracketed structure string into English by evaluating sumerian operators (substituting arguments into translation templates) and composing adjacent elements according to grammatical rules. The input is a structure string as produced by \code{\link{add_brackets}}, together with  vectors of types and translations for each tag.
}
\usage{
apply_translation_rules(s, type, translation)
}
\arguments{
  \item{s}{Character string showing the order of evaluation, as produced by \code{\link{add_brackets}}.}
  \item{type}{Character vector of grammatical types. \code{type[k]} is the type string for tag \code{#k} (e.g. \code{"S"}, \code{"V"}, \code{"Sx->V"}).}
  \item{translation}{Character vector of translations. \code{translation[k]} is the translation for tag \code{#k}. Operator translations contain placeholders (e.g. \code{"to deliver S"}).}
}
\details{
Nested \code{\{...\}} groups are evaluated from the inside out. Within each group, an operator (if present) binds its arguments and produces a typed result. Groups without an operator are composed according to the rules described in \code{\link{eval_operator}}.
}
\value{
A character vector of length 2: \code{c(result_type, result_translation)}.

On error (e.g. incompatible types), a character vector of length 1 containing the error message.
}
\examples{
x <- "mec3-ki-aj2-ga-ce-er"
x <- as.cuneiform(x)
x

meaning <- rbind( c("S",      "a man who relies on his own strength"),
                  c("S",      "place {earth}"),
                  c("Sx->A",  ", whose allocated resource is S"),
                  c("xS->A",   ", whose sustenance is S"),
                  c("S",      "grain"),
                  c("Sx->S",  "lamented S"))

df <- data.frame(
    type  = meaning[,1],
    translation = meaning[,2],
    expr  = split_sumerian(x)$signs)

s <- x
for(i in 1:nrow(df)){
 s <- sub(df$expr[i], paste0("#", i), s)
}
s

s_bracketed <- sumer:::add_brackets(s, df$type)
s_bracketed

apply_translation_rules(s_bracketed$string, df$type, df$translation)
}

\seealso{
\code{\link{eval_operator}} for the evaluation rules,
\code{\link{add_brackets}} for the previous pipeline step,
\code{\link{compose_skeleton_entry}} which calls this function
}
