Skip to content

Instantly share code, notes, and snippets.

@ymattu
Last active August 23, 2017 05:06
Show Gist options
  • Save ymattu/7d3bc3ed7cdcd6354e35b561030e3e4d to your computer and use it in GitHub Desktop.
Save ymattu/7d3bc3ed7cdcd6354e35b561030e3e4d to your computer and use it in GitHub Desktop.
mecabで単純な分かち書き
#' @param ... see RMeCab::RMeCabC()
#' @param pos 品詞(正規表現)
mecab_wakati2 <- function(..., pos = "") {
res <- RMeCabC(...) %>%
map(function(x) {
if(str_detect(names(x), pos) == TRUE) {
return(x[[1]])
} else {
""
}
}
) %>%
unlist() %>%
str_c(collapse = " ") %>%
str_trim()
if(length(res) == 0) {
res <- ""
}
return(res)
}
mecab_wakati3 <- function(..., pos = "") {
res <- RMeCabC(...) %>%
unlist() %>%
.[str_detect(names(.), pos) == TRUE] %>%
str_c(collapse = " ")
if(length(res) == 0) {
res <- ""
}
return(res)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment