% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tagging.R
\name{tagging}
\alias{tagging}
\title{Tag text with a jiebaRS worker}
\usage{
tagging(
  code,
  jiebar,
  ...,
  format = c("vector", "data.frame", "legacy"),
  batch = c("list", "flatten")
)
}
\arguments{
\item{code}{A non-empty character vector to tag.}

\item{jiebar}{A \code{jieba_worker} object created with \code{worker(type = "tag")}.}

\item{...}{Must be empty. This enforces that optional arguments such as
\code{format} and \code{batch} are supplied with explicit names.}

\item{format}{Output format for a single tagged string. Must be one of
\code{"vector"}, \code{"data.frame"}, or \code{"legacy"}.}

\item{batch}{Aggregation mode for multi-string input. Must be one of
\code{"list"} or \code{"flatten"}.}
}
\value{
Tagging results in the requested format.
}
\description{
Tag one or more strings with a \code{jieba_worker} created by \code{\link[=worker]{worker()}}.
}
\details{
\code{format} controls the shape of each single-string tagging result:
\itemize{
\item \code{"vector"}: a named character vector with token names and tag values.
\item \code{"data.frame"}: a data frame with \code{term} and \code{tag} columns.
\item \code{"legacy"}: the old \code{jiebaR} layout with token values and tag names.
}

In the current release benchmarks on the bundled \emph{Fortress Besieged} and
\emph{Dream of the Red Chamber} texts, \code{jiebaRS::tagging()} is about \strong{1.6x to
1.8x faster} than \code{jiebaR::tagging()} when each novel is tagged as one long
string. When the same content is split into many strings and processed in
batch, \code{jiebaRS::tagging()} is about \strong{2x to 5x faster} than \code{jiebaR}.

For very long texts, splitting before tagging is usually faster than sending
one huge string. In the same release benchmarks, the best results appeared
around \strong{32 to 128 chunks}, while much finer splitting still helped but was
no longer optimal.

When \code{code} contains multiple strings, \code{batch} controls how the per-string
results are aggregated:
\itemize{
\item \code{"list"}: one single-string result per input string.
\item \code{"flatten"}: concatenate all results into one. The shape is decided by
\code{format}: \code{"vector"}/\code{"legacy"} produce a named character vector, while
\code{"data.frame"} produces a combined data frame with a \code{doc_id} column.
}

When \code{batch} is omitted, \code{jiebaRS} returns \code{"vector"} for single-string
input and \code{"list"} for multi-string input.
}
\examples{
tagger <- worker(type = "tag")
text1 <- "\u8fd9\u662f\u4e00\u4e2a\u6d4b\u8bd5"
text2 <- "\u518d\u6765\u4e00\u6b21"
tagging(text1, tagger)
tagging(c(text1, text2), tagger)
tagging(c(text1, text2), tagger, format = "data.frame", batch = "flatten")
}
