Nothing
# Argument names renamed in jiebaRS 0.4.0: `code`/`texts`/`input` became `x`
# and `jiebar` became `worker`. The old names still work but are deprecated
# through lifecycle.
test_that("new argument names work without warnings", {
seg <- worker()
expect_no_warning(segment(x = "南京市长江大桥", worker = seg))
expect_no_warning(lapply(c("南京", "北京"), segment, worker = seg))
expect_no_warning(filter_segment(x = c("a", "b"), filter_words = "a"))
})
test_that("deprecated argument names produce lifecycle warnings", {
withr::local_options(lifecycle_verbosity = "warning")
seg <- worker()
expect_snapshot(segment(code = "南京市长江大桥", jiebar = seg))
expect_snapshot(filter_segment(input = c("a", "b"), "a"))
})
test_that("every renamed function accepts and deprecates its old names", {
seg <- worker()
tagger <- worker(type = "tag")
keys <- worker(type = "keywords", topn = 2)
ranker <- worker(type = "textrank", topn = 2)
text <- "北京烤鸭真好吃,北京烤鸭"
texts <- c("南京市长江大桥", text)
# Each old name is checked on its own, so exactly one warning is raised.
lifecycle::expect_deprecated(segment(code = text, seg), "code")
lifecycle::expect_deprecated(segment(text, jiebar = seg), "jiebar")
lifecycle::expect_deprecated(segment_batch(texts = texts, seg), "texts")
lifecycle::expect_deprecated(segment_batch(texts, jiebar = seg), "jiebar")
lifecycle::expect_deprecated(tagging(code = text, tagger), "code")
lifecycle::expect_deprecated(tagging(text, jiebar = tagger), "jiebar")
lifecycle::expect_deprecated(tagging_batch(texts = texts, tagger), "texts")
lifecycle::expect_deprecated(tagging_batch(texts, jiebar = tagger), "jiebar")
lifecycle::expect_deprecated(keywords(code = text, keys), "code")
lifecycle::expect_deprecated(keywords(text, jiebar = keys), "jiebar")
lifecycle::expect_deprecated(keywords_batch(texts = texts, keys), "texts")
lifecycle::expect_deprecated(keywords_batch(texts, jiebar = keys), "jiebar")
lifecycle::expect_deprecated(keywords_df(texts, jiebar = keys), "jiebar")
lifecycle::expect_deprecated(textrank(code = text, ranker), "code")
lifecycle::expect_deprecated(textrank(text, jiebar = ranker), "jiebar")
lifecycle::expect_deprecated(textrank_batch(texts = texts, ranker), "texts")
lifecycle::expect_deprecated(textrank_batch(texts, jiebar = ranker), "jiebar")
lifecycle::expect_deprecated(textrank_df(texts, jiebar = ranker), "jiebar")
lifecycle::expect_deprecated(filter_segment(input = "a", "a"), "input")
# The old names give the same results as the new ones.
withr::local_options(lifecycle_verbosity = "quiet")
expect_identical(
segment(code = text, jiebar = seg),
segment(text, seg)
)
expect_identical(
segment_batch(texts = texts, jiebar = seg),
segment_batch(texts, seg)
)
expect_identical(
tagging(code = text, jiebar = tagger),
tagging(text, tagger)
)
expect_identical(
tagging_batch(texts = texts, jiebar = tagger),
tagging_batch(texts, tagger)
)
expect_identical(
keywords(code = text, jiebar = keys),
keywords(text, keys)
)
expect_identical(
keywords_batch(texts = texts, jiebar = keys),
keywords_batch(texts, keys)
)
expect_identical(
keywords_df(texts, jiebar = keys),
keywords_df(texts, keys)
)
expect_identical(
textrank(code = text, jiebar = ranker),
textrank(text, ranker)
)
expect_identical(
textrank_batch(texts = texts, jiebar = ranker),
textrank_batch(texts, ranker)
)
expect_identical(
textrank_df(texts, jiebar = ranker),
textrank_df(texts, ranker)
)
expect_identical(
filter_segment(input = c("a", "b"), "a"),
"b"
)
})
test_that("old-style calls with a named first argument still match", {
withr::local_options(lifecycle_verbosity = "quiet")
seg <- worker()
# Under the old signature `segment(code, jiebar)`, a positional worker after
# a named `code` filled `jiebar`.
expect_identical(
segment(code = "南京市长江大桥", seg),
segment("南京市长江大桥", seg)
)
expect_identical(
lapply("南京市长江大桥", segment, jiebar = seg),
list(segment("南京市长江大桥", seg))
)
expect_identical(
filter_segment(input = c("a", "b"), "a"),
filter_segment(c("a", "b"), "a")
)
})
test_that("supplying a new name and its deprecated alias together errors", {
seg <- worker()
expect_snapshot(segment("南京", seg, code = "北京"), error = TRUE)
expect_snapshot(segment("南京", seg, jiebar = seg), error = TRUE)
expect_snapshot(segment(), error = TRUE)
expect_snapshot(segment("南京"), error = TRUE)
})
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.