\name{merge_dictionaries}
\alias{merge_dictionaries}
\title{Merge Two or More Sumerian Dictionaries}
\description{
Combines two or more dictionaries (as produced by \code{\link{make_dictionary}}) into a single dictionary. Translation entries that agree in sign name, grammatical type, and meaning are merged by summing their counts. Cuneiform and reading rows are taken from the first dictionary that contains them.
}
\usage{
merge_dictionaries(...)
}
\arguments{
  \item{...}{Two or more dictionaries, each either a data frame (as returned by \code{\link{make_dictionary}} or \code{\link{read_dictionary}}) or a file path to a dictionary file. A single list of dictionaries is also accepted.}
}
\details{
The function processes the three row types differently:

\describe{
  \item{\code{"cunei."} and \code{"reading"}}{Each sign name has at most one row of each type. If multiple input dictionaries contain a cuneiform or reading row for the same sign, the row from the first dictionary (in argument order) is kept.}
  \item{\code{"trans."}}{Rows that share the same \code{sign_name}, \code{type}, and \code{meaning} are merged into a single row whose \code{count} is the sum of the individual counts. Rows that differ in type or meaning are kept as separate entries.}
}

The result is sorted by \code{sign_name}, then \code{row_type}, then descending \code{count}, matching the order produced by \code{\link{make_dictionary}}.

\bold{Note:} Merging dictionaries is most meaningful when the underlying text corpora come from comparable periods and regions of Mesopotamia. Combining dictionaries from widely different epochs or dialects may produce misleading frequency counts, since the same sign can carry different meanings across time and place.
}
\value{
A data frame with five columns in the standard dictionary format:
\describe{
  \item{sign_name}{Character. The sign name (e.g. \code{"A"}, \code{"LUGAL"}).}
  \item{row_type}{Character. One of \code{"cunei."}, \code{"reading"}, or \code{"trans."}.}
  \item{count}{Numeric. The (merged) occurrence count for translation rows; \code{NA} for cuneiform and reading rows.}
  \item{type}{Character. The grammatical type for translation rows (e.g. \code{"S"}, \code{"V"}); empty for cuneiform and reading rows.}
  \item{meaning}{Character. The cuneiform glyph, the reading notation, or the translation text, depending on \code{row_type}.}
}
}
\seealso{
\code{\link{make_dictionary}} for creating a dictionary from a translated text,
\code{\link{read_dictionary}} for loading a dictionary from file,
\code{\link{save_dictionary}} for saving a dictionary to file,
\code{\link{convert_to_dictionary}} for the aggregation step inside \code{make_dictionary}
}
\examples{
# Load the built-in dictionary
dic1 <- read_dictionary()

# Make a dictionary from some translations of "Enki and the World Order"
path <- system.file("extdata", "project/lines", package = "sumer")
dic2 <- make_dictionary(list.files(path, full.names=TRUE)[1:10])

# Merge both dictionaries
dic <- merge_dictionaries(dic1, dic2)

#Test the function
look_up("IL2", dic1)
look_up("IL2", dic2)
look_up("IL2", dic)

}
\keyword{utilities}
