\name{compose_skeleton_entry}
\alias{compose_skeleton_entry}
\title{Compose a Skeleton Entry from its Children}
\description{
Composes the \code{type} and \code{translation} fields of a parent skeleton entry from the corresponding fields of its direct children, following the rules of the Sumerian type system. This function is called by \code{\link{translate}} when the user clicks the brown compose button next to a skeleton entry.
}
\usage{
compose_skeleton_entry(df)
}
\arguments{
  \item{df}{A data frame with \eqn{n + 1} rows, where the first row represents the parent entry and the remaining \eqn{n} rows represent its direct children in the skeleton hierarchy.

  The data frame has the following columns:
  \describe{
    \item{expr}{Character. The expression of the entry.}
    \item{n_tokens}{Integer. Number of tokens covered by the entry.}
    \item{start}{Integer. Position (1-based) of the first token.}
    \item{depth}{Integer. Nesting depth in the skeleton hierarchy.}
    \item{type}{Character. The grammatical type annotation: \code{"S"} (substantive), \code{"V"} (verb), \code{"A"} (adjective/attribute), or an operator type like \code{"xS->S"}.}
    \item{translation}{Character. The translation. Operator translations contain type-letter placeholders (e.g. \code{"S"} in \code{"supplier of energy from S"}).}
  }
  }
}
\details{
The algorithm works in three steps:
\enumerate{
  \item \strong{Structure string:} Build a structure string by replacing each child's expression in the parent expression with a numbered tag (\code{#1}, \code{#2}, etc.). Token-group wrappers (\code{<>} and single-tag \code{\{\}}) are removed.
  \item \strong{Bracket insertion:} \code{\link{add_brackets}} groups operators with their arguments and applies compositional rules (S+A, S+S, S+V, SEN+SEN).
  \item \strong{Translation:} \code{\link{apply_translation_rules}} recursively evaluates the bracketed string to produce the final translation.
}
}
\value{
Either the input data frame \code{df} with the \code{type} and \code{translation} fields of the first row filled in, or a character string containing an error message.
}
\examples{
# Minimal example: S + Sx->V
df <- data.frame(
  expr = c("#1 #2", "#1", "#2"),
  n_tokens = c(2L, 1L, 1L),
  start = c(1L, 1L, 2L),
  depth = c(0L, 1L, 1L),
  type = c("", "S", "Sx->V"),
  translation = c("", "water", "to utilize S"),
  stringsAsFactors = FALSE
)
result <- sumer:::compose_skeleton_entry(df)
result
}

\seealso{
\code{\link{add_brackets}}, \code{\link{apply_translation_rules}} for the individual pipeline steps,
\code{\link{translate}} which calls this function
}
\keyword{internal}
