summerofgeorge
3/19/2018 - 1:39 PM

Loop through dictionary for keyword in context of each item in the corpus

Loop through dictionary for keyword in context of each item in the corpus

library(quanteda)
library(readtext)

#read corpus
corp <- readtext::readtext("C:/FactivaOut")
c <- corpus(corp)

#check corpus
summary(c,n=3)

#read dictionary
agile <- read.csv("C:/AgilityDict/Dictionary.csv")
terms <- as.vector(agile$term)

#check dictionary
head(terms,5)

#set up data frame 
df_total <- data.frame()

#loop terms
for (term in terms){
  kwickout <- kwic(c, term, window = 9, valuetype = "glob")
  df <- data.frame(kwickout)
  df_total <- rbind(df_total, df)
}

#check
dim(df_total)
dim(df)

#write to csv
write.csv(df_total,"C:/FactivaAnalysis/dfout.csv")