R/extendr-wrappers.R

Defines functions read_cidian_worker import_cidian_worker add_user_words textrank_worker keywords_worker tagging_batch_worker tagging_worker segment_batch_worker segment_worker new_worker

# Generated by extendr: Do not edit by hand
# nolint start

#' @usage NULL
#' @useDynLib jiebaRS, .registration = TRUE
NULL

#' Create an internal native jieba worker.
#'
#' Internal bridge used by [worker()] to allocate a native `JiebaWorker`.
#'
#' @param worker_type Character scalar naming the worker type. Currently
#'   supports `"mix"`, `"mp"`, `"hmm"`, `"full"`, `"query"`, `"tag"`,
#'   `"keywords"`, and `"textrank"`.
#' @param use_hmm Logical scalar indicating whether HMM fallback should be
#'   enabled for segmentation.
#' @param hmm_model Character scalar containing a custom HMM model path, or an
#'   empty string to use the embedded model.
#' @param idf_path Character scalar containing a custom IDF dictionary path, or
#'   an empty string to use the embedded dictionary.
#' @param dict_path Character scalar containing a custom main dictionary path,
#'   or an empty string to use the embedded dictionary. When provided, the
#'   custom file *replaces* the embedded main dictionary entirely.
#' @param user_paths Character vector containing user dictionary paths. User
#'   entries are *appended* to the main dictionary in the supplied order.
#' @param top_n Integer scalar giving the number of keywords retained by
#'   keyword workers.
#' @param min_keyword_length Positive integer scalar giving the minimum number
#'   of Unicode scalar values in terms retained by keyword workers.
#' @param stop_words Character vector of normalized UTF-8 stop words passed to
#'   the native worker.
#'
#' @return A native `JiebaWorker` handle.
#' @noRd
#' @keywords internal
new_worker <- function(worker_type, use_hmm, hmm_model, idf_path, dict_path, user_paths, top_n, min_keyword_length, stop_words) .Call(wrap__new_worker, worker_type, use_hmm, hmm_model, idf_path, dict_path, user_paths, top_n, min_keyword_length, stop_words)

#' Segment text with an internal native worker.
#'
#' Internal bridge used by `segment()` to segment a single UTF-8 string.
#'
#' @param text Character scalar containing the input text.
#' @param worker A native `JiebaWorker` handle created by the internal worker
#'   constructor.
#'
#' @return A character vector of segmented tokens.
#' @noRd
#' @keywords internal
segment_worker <- function(text, worker) .Call(wrap__segment_worker, text, worker)

#' Segment multiple strings with an internal native worker.
#'
#' Internal bridge used by `segment()` to segment many UTF-8 strings.
#'
#' @param texts Character vector containing the input strings.
#' @param worker A native `JiebaWorker` handle created by the internal worker
#'   constructor.
#'
#' @return A list of character vectors, one per input string.
#' @noRd
#' @keywords internal
segment_batch_worker <- function(texts, worker) .Call(wrap__segment_batch_worker, texts, worker)

#' Tag text with an internal native worker.
#'
#' Internal bridge used by [tagging()] to tag a single UTF-8 string.
#'
#' @param text Character scalar containing the input text.
#' @param worker A native `JiebaWorker` handle created by the internal worker
#'   constructor.
#'
#' @return A named list with `term` and `tag` vectors.
#' @noRd
#' @keywords internal
tagging_worker <- function(text, worker) .Call(wrap__tagging_worker, text, worker)

#' Tag multiple strings with an internal native worker.
#'
#' Internal bridge used by `tagging()` to tag many UTF-8 strings.
#'
#' @param texts Character vector containing the input strings.
#' @param worker A native `JiebaWorker` handle created by the internal worker
#'   constructor.
#'
#' @return A list where each element is a named list with `term` and `tag`
#'   vectors.
#' @noRd
#' @keywords internal
tagging_batch_worker <- function(texts, worker) .Call(wrap__tagging_batch_worker, texts, worker)

#' Extract keywords with an internal native worker.
#'
#' Internal bridge used by [keywords()] to extract TF-IDF keywords from a
#' single UTF-8 string.
#'
#' @param text Character scalar containing the input text.
#' @param worker A native `JiebaWorker` handle created by the internal worker
#'   constructor.
#'
#' @return A named list with `keyword` and `weight` vectors.
#' @noRd
#' @keywords internal
keywords_worker <- function(text, worker) .Call(wrap__keywords_worker, text, worker)

#' Extract TextRank keywords with an internal native worker.
#'
#' Internal bridge used by [textrank()] to extract TextRank keywords from a
#' single UTF-8 string.
#'
#' @param text Character scalar containing the input text.
#' @param worker A native `JiebaWorker` handle created by the internal worker
#'   constructor.
#'
#' @return A named list with `keyword` and `weight` vectors.
#' @noRd
#' @keywords internal
textrank_worker <- function(text, worker) .Call(wrap__textrank_worker, text, worker)

#' Add user-defined words with an internal native worker.
#'
#' Internal bridge used by [new_user_word()] to mutate an existing native
#' worker in place.
#'
#' @param worker A mutable native `JiebaWorker` handle.
#' @param words Character vector of custom words.
#' @param tags Character vector of tags aligned with `words`.
#' @param freq Optional integer vector of frequencies aligned with `words`.
#'
#' @return `NULL`, invisibly, after the worker has been updated.
#' @noRd
#' @keywords internal
add_user_words <- function(worker, words, tags, freq) .Call(wrap__add_user_words, worker, words, tags, freq)

#' Import an input-method dictionary into an existing native jieba worker.
#'
#' Internal bridge used by `import_cidian()` to parse a supported input-method
#' dictionary and add its words to an existing worker.
#'
#' @param worker A mutable native `JiebaWorker` handle.
#' @param path Character scalar containing the input-method dictionary path.
#' @param format Character scalar identifying the parser to use.
#' @param tag Optional character scalar containing the tag assigned to every
#'   imported word. `NULL` leaves the tag empty.
#'
#' @return `NULL`, invisibly, after the worker has been updated.
#' @noRd
#' @keywords internal
import_cidian_worker <- function(worker, path, format, tag) .Call(wrap__import_cidian_worker, worker, path, format, tag)

#' Read an input-method dictionary through the internal native bridge.
#'
#' Internal bridge used by `read_cidian()` to parse a supported input-method
#' dictionary and return its entries and coding components.
#'
#' @param path Character scalar containing the input-method dictionary path.
#' @param format Character scalar identifying the parser to use.
#'
#' @return A named list with `entry` and `code` character vectors.
#' @noRd
#' @keywords internal
read_cidian_worker <- function(path, format) .Call(wrap__read_cidian_worker, path, format)

# nolint end

Try the jiebaRS package in your browser

Any scripts or data that you put into this service are public.

jiebaRS documentation built on Oct. 13, 2026, 5:07 p.m.