-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
101 additions
and
40 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#' A simple function for counting collocates | ||
#' | ||
#' @param collsDB A collocates list, combined with relevant counts, generated by save_collocates | ||
#' | ||
count_collocates <- function(collsDB){ | ||
# Convert duplicates, locations below 1 and above the word count to NA | ||
left_locs <- collsDB[[1]] %>% unlist(.) | ||
right_locs <- collsDB[[1]] %>% unlist(.) | ||
all_locs <- c(left_locs, right_locs) | ||
# Convert duplicates, locations below 1 and above the word count to NA | ||
all_locs[duplicated(all_locs)] <- NA | ||
all_locs[all_locs < 1] <- NA | ||
all_locs[all_locs > nrow(collsDB$doc_table)] <- NA | ||
|
||
# Convert locations into words | ||
coll_counts <- collsDB$doc_table[all_locs,] %>% | ||
table(.) %>% | ||
tibble(word = names(.), coll_count = .) | ||
|
||
return(coll_counts) | ||
} | ||
|
||
# Leaving this here for offering locational collocate data | ||
#left_counts <- doc$doc_table[left_locs, ] %>% | ||
# table(.) %>% | ||
# tibble(word = names(.), count = .) | ||
|
||
#right_counts <- doc$doc_table[right_locs, ] %>% | ||
# table(.) %>% | ||
# tibble(word = names(.), count = .) | ||
#} |
This file contains 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
This file contains 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