\name{fill_substr_info}
\alias{fill_substr_info}
\title{Read Back a Saved Translation into a Substring Data Frame}
\description{
Reads a saved skeleton file (or character vector) and reconstructs the substring data frame that can be passed as \code{fill} to \code{\link{translate}} or \code{\link{skeleton}}. This allows resuming work on a translation that was saved earlier with \code{writeLines}.

The counterpart to this function is \code{\link{guess_substr_info}}, which fills the substring data frame from dictionaries. In contrast, \code{fill_substr_info} fills it from a skeleton that already contains manually entered types and translations.
}
\usage{
fill_substr_info(skeleton)
}
\arguments{
  \item{skeleton}{A file path to a saved skeleton text file, or a character vector as returned by \code{\link{skeleton}} or \code{\link{translate}}.}
}
\details{
A typical workflow for translating Sumerian texts spans multiple sessions:

\enumerate{
  \item Call \code{\link{translate}} to interactively translate a line.
  \item Save the result with \code{writeLines(result, "Line_29.txt")}.
  \item In a later session, call \code{fill_substr_info("Line_29.txt")} to reload the saved translation.
  \item Pass the result as \code{fill} to \code{\link{translate}} to continue editing.
}

The function parses the skeleton format (header line \code{"Structure: ..."} followed by entry lines starting with \code{|}), extracts the type and translation from each entry, and places them at the correct positions in a substring data frame as created by \code{\link{init_substr_info}}.
}
\value{
A data frame with \eqn{N(N+1)/2} rows (where \eqn{N} is the number of cuneiform tokens) and the following columns:
\describe{
  \item{start}{Integer. The 1-based position of the first token in the substring.}
  \item{n_tokens}{Integer. The number of tokens in the substring.}
  \item{expr}{Character. The concatenated cuneiform signs of the substring.}
  \item{type}{Character. The grammatical type (e.g. \code{"S"}, \code{"V"}, \code{"Sx->V"}), or \code{""} if not yet specified.}
  \item{translation}{Character. The translation, or \code{""} if not yet specified.}
}
Rows without a corresponding skeleton entry have empty type and translation fields. The row order matches \code{\link{init_substr_info}}, so indices can be computed with \code{\link{substr_position}}.
}
\seealso{
\code{\link{translate}} for the interactive translation tool,
\code{\link{skeleton}} for creating and displaying translation templates,
\code{\link{guess_substr_info}} for filling a substring data frame from dictionaries,
\code{\link{init_substr_info}} for the underlying data frame structure
}
\examples{
skeleton_file  <- system.file("extdata", "project/lines/Line_29.txt", package = "sumer")
the_skeleton   <- readLines(skeleton_file)

#Get the cuneiform text of the line:
x <- sub("^Structure: ", "", the_skeleton[1])
x

#See the whole file:
cat(the_skeleton, sep="\n")


df_fill <- fill_substr_info(skeleton_file)


\dontrun{

#Use the result of the function to revise the translation:

dict_file <- system.file("extdata", "sumer-dictionary.txt", package = "sumer")
text_file <- system.file("extdata", "project", "enki_and_the_world_order.txt", package = "sumer")

result <- translate(x,
                text = text_file,
                dic = dict_file,
                fill = df_fill,
                min_freq = c(6, 4, 2),
                sentence_prob = 0.25)
print(result)
# Now you may save the result with writeLines.
}

}
\keyword{utilities}
