#' Call MeCab
#'
#' @param text character vector.
#' @param pos_as_fct logical.
#' @param sys_dic character scalar.
#' @param user_dic character scalar.
#' @return tibble
#'
#' @import dplyr
#' @importFrom stringi stri_enc_toutf8
#' @importFrom tibble as_tibble
#' @export
mecab <- function(text, pos_as_fct = FALSE, sys_dic = "", user_dic = "") {
str <- stringi::stri_enc_toutf8(text)
res <- .Call("_RcppMeCab_posParallelDFRcpp", PACKAGE = "RcppMeCab", str, sys_dic, user_dic)
colnames(res) <- c(
"doc_id",
"sentence_id",
"token_id",
"surface",
"pos1",
"pos2",
"reading"
)
res <- res %>%
dplyr::mutate(doc_id = as.integer(doc_id)) %>%
tibble::as_tibble()
if (pos_as_fct) {
return(dplyr::mutate(res, pos1 = as.factor(pos1), pos2 = as.factor(pos2)))
} else {
return(res)
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.