filter_segment: Filter segmentation results

View source: R/filter.R

filter_segmentR Documentation

Filter segmentation results

Description

Remove selected words from a segmented character vector or from each element of a list of segmented character vectors.

Usage

filter_segment(input, filter_words, ..., keep_na = TRUE)

Arguments

input

A character vector or a list of character vectors.

filter_words

A character vector of words to remove.

...

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

keep_na

Whether to keep NA values in the returned result. The default TRUE matches jiebaR::filter_segment().

Details

This is a modern reimplementation of jiebaR::filter_segment() with the same core filtering behavior under the default settings.

In the reproducible benchmark, this version is about 110x to 140x faster than jiebaR::filter_segment() on the tested workloads.

Value

An object with the same shape as input, with matching words removed.

Examples

filter_segment(c("abc", "def", " ", "."), c("abc"))
filter_segment(c("a", NA, "b", "a"), c("b"), keep_na = FALSE)
input <- list(
  c("\u6211", "\u662f", "\u6d4b\u8bd5"),
  c("\u6d4b\u8bd5", "\u6587\u672c", "\u6211")
)
filter_segment(input, "\u6211")

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