Skip to content

Instantly share code, notes, and snippets.

@almogsi
Created August 30, 2021 12:51
Show Gist options
  • Select an option

  • Save almogsi/5306c390d201272a47bc7ad1d6f9148d to your computer and use it in GitHub Desktop.

Select an option

Save almogsi/5306c390d201272a47bc7ad1d6f9148d to your computer and use it in GitHub Desktop.
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