R/helper.R

Defines functions pack_df

Documented in pack_df

#' Pack Output of mecab
#'
#' @param df output of \code{mecabr::mecab}
#' @return data.frame
#'
#' @import dplyr
#' @importFrom purrr map_dfr
#' @importFrom tibble rowid_to_column
#' @export
pack_df <- function(df) {
  res <- df %>%
    dplyr::group_by(doc_id) %>%
    dplyr::group_map(~ paste(.x$surface, collapse = " ")) %>%
    purrr::map_dfr(~ tibble::tibble(text = .)) %>%
    tibble::rowid_to_column("doc_id")
  return(res)
}
paithiov909/mecabr documentation built on Jan. 19, 2021, 12:39 a.m.