keywords_batch: Extract keywords from a batch of strings

View source: R/keywords.R

keywords_batchR Documentation

Extract keywords from a batch of strings

Description

Convenience wrapper around keywords() for multi-string input. When batch is not supplied, keywords_batch() returns list output.

Usage

keywords_batch(
  x,
  worker,
  ...,
  format = c("vector", "data.frame", "legacy"),
  batch = c("list", "flatten"),
  texts = deprecated(),
  jiebar = deprecated()
)

Arguments

x

A non-empty character vector to analyze.

worker

A jieba_worker object created with worker(type = "keywords").

...

Must be empty. This enforces that optional arguments such as format and batch are supplied with explicit names.

format

Output format for each document. Must be one of "vector", "data.frame", or "legacy".

batch

Aggregation mode. Must be one of "list" or "flatten".

texts, jiebar

[Deprecated] Use x and worker instead.

Details

Each string is one document; documents are processed in parallel and up to topn keywords are extracted from each one. The returned object depends on both format and batch:

  • batch = "list": one single-document keyword result per input string.

  • batch = "flatten": all results concatenated. "vector"/"legacy" produce one named vector, while "data.frame" produces a combined data frame with a leading doc_id column.

Value

Keyword results in the requested format.

Examples

keys <- worker(type = "keywords", topn = 2)
texts <- c(
  "\u5317\u4eac\u70e4\u9e2d\u771f\u597d\u5403\uff0c\u5317\u4eac\u70e4\u9e2d",
  "\u7ebd\u7ea6\u7684\u5929\u6c14\u771f\u597d\uff0c\u7ebd\u7ea6\u7684\u5929\u6c14"
)
keywords_batch(texts, keys)
keywords_batch(texts, keys, format = "data.frame", batch = "flatten")

jiebaRS documentation built on Dec. 3, 2026, 5:09 p.m.