Skip to content

Commit

Permalink
refactor: remove purrr from Imports
Browse files Browse the repository at this point in the history
  • Loading branch information
paithiov909 committed Sep 25, 2024
1 parent ff5288c commit c0fa4b6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Depends:
Imports:
dplyr,
Matrix,
purrr,
Rcpp,
RcppParallel,
readr,
Expand Down
8 changes: 4 additions & 4 deletions R/bind_tf_idf2.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ booled_freq <- function(v) {
}

global_df <- function(sp) {
purrr::set_names(count_nnzero(sp) / nrow(sp), colnames(sp))
rlang::set_names(count_nnzero(sp) / nrow(sp), colnames(sp))
}

# inverse document frequency smooth
global_idf <- function(sp) {
purrr::set_names(log2(nrow(sp) / count_nnzero(sp)) + 1, colnames(sp))
rlang::set_names(log2(nrow(sp) / count_nnzero(sp)) + 1, colnames(sp))
}

# global frequency idf
Expand All @@ -69,7 +69,7 @@ global_idf2 <- function(sp) {
# probabilistic idf
global_idf3 <- function(sp) {
df <- count_nnzero(sp)
purrr::set_names(log2((nrow(sp) - df) / df), colnames(sp))
rlang::set_names(log2((nrow(sp) - df) / df), colnames(sp))
}

# entropy
Expand Down Expand Up @@ -172,7 +172,7 @@ bind_tf_idf2 <- function(tbl,
tbl <-
dplyr::mutate(tbl, tf = log(as.numeric(doc_totals[documents]) / .data$n))
} else {
tbl <- dplyr::mutate(tbl, tf = purrr::flatten_dbl(doc_totals))
tbl <- dplyr::mutate(tbl, tf = as.numeric(unlist(doc_totals, use.names = FALSE)))
}

if (isTRUE(rmecab_compat)) {
Expand Down
2 changes: 1 addition & 1 deletion R/tokenize.R
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ tagger_impl <- function(sentences,
})() %>%
dplyr::mutate(
sentence_id = dplyr::consecutive_id(.data$sentence_id),
.by = .data$doc_id
.by = "doc_id"
) %>%
dplyr::relocate("doc_id", dplyr::everything())
} else {
Expand Down
6 changes: 3 additions & 3 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ as_tokens <- function(tbl,
if (is.null(pos_field)) {
tbl[[token_field]] %>%
split(tbl[[col_names]]) %>%
purrr::set_names(nm)
rlang::set_names(nm)
} else {
purrr::set_names(tbl[[token_field]], tbl[[pos_field]]) %>%
rlang::set_names(tbl[[token_field]], tbl[[pos_field]]) %>%
split(tbl[[col_names]]) %>%
purrr::set_names(nm)
rlang::set_names(nm)
}
}

Expand Down

0 comments on commit c0fa4b6

Please sign in to comment.