Skip to contents

Add one or more custom words to a jieba worker.

Usage

new_user_word(worker, words, ..., tags = "n", freq = NULL)

add_word(worker, words, ..., tags = "n", freq = NULL)

Arguments

worker

A jieba_worker object.

words

A non-empty string or a non-empty character vector of new words.

...

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

tags

A single tag or a character vector of tags. Defaults to "n" for each supplied word. NA values are allowed and will be interpreted as missing tags.

freq

Optional positive integer frequency or integer vector of frequencies. Defaults to NULL. NA values are allowed and will be interpreted as frequencies to infer from the current dictionary.

Value

NULL, invisibly. Called for its side effect of adding the supplied words to worker, thereby modifying the state used by subsequent operations with the same worker.

Examples

cutter <- worker()
segment("\u91cf\u5b50\u673a\u5668\u72d7", cutter)
#> [1] "量子" "机器" "狗"  
new_user_word(cutter, "\u91cf\u5b50\u673a\u5668\u72d7", tags = "n", freq = 1000L)
segment("\u91cf\u5b50\u673a\u5668\u72d7", cutter)
#> [1] "量子机器狗"

cutter2 <- worker()
add_word(
  cutter2,
  c("\u8d85\u5bfc\u91cf\u5b50\u6bd4\u7279", "\u91cf\u5b50\u673a\u5668\u72d7"),
  tags = c(NA, "n"),
  freq = c(NA, 1000L)
)
segment("\u8d85\u5bfc\u91cf\u5b50\u6bd4\u7279", cutter2)
#> [1] "超导量子比特"