Last active
August 23, 2017 05:06
-
-
Save ymattu/7d3bc3ed7cdcd6354e35b561030e3e4d to your computer and use it in GitHub Desktop.
mecabで単純な分かち書き
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' @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) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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