Created
August 30, 2021 12:51
-
-
Save almogsi/5306c390d201272a47bc7ad1d6f9148d to your computer and use it in GitHub Desktop.
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
| library(tidyverse) | |
| library(quanteda) | |
| library(spacyr) | |
| get_passive <- function(text, ratio = F){ | |
| d <- spacy_parse(text, dependency = T) | |
| aux_pass <- d %>% | |
| mutate(doc_id = as.numeric(str_remove_all(doc_id, "text"))) %>% | |
| group_by(doc_id) %>% | |
| summarise(aux_pass = sum(dep_rel=="auxpass")) | |
| if (ratio==T){ | |
| total_words <- text %>% | |
| as_tibble() %>% | |
| rowwise %>% | |
| mutate(wc = ngram::wordcount(value)) | |
| return(aux_pass$aux_pass/total_words$wc)} | |
| else{ | |
| return(aux_pass$aux_pass)} | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment