Last active
May 14, 2018 12:06
-
-
Save summerofgeorge/753a819c6e1a4512010dab14e2c6b5a8 to your computer and use it in GitHub Desktop.
Loop through dictionary for keyword in context of each item in the corpus
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
| #simple example - no loop | |
| #https://docs.quanteda.io/reference/kwic.html | |
| library(quanteda) | |
| library(readtext) | |
| corp <- readtext::readtext("C:/FactivaOut") | |
| c <- corpus(corp) | |
| #check corpus | |
| summary(c,n=3) | |
| head(kwic(data_corpus_inaugural, "secure*", window = 3, valuetype = "glob")) | |
| head(kwic(data_corpus_inaugural, "secur", window = 3, valuetype = "regex")) | |
| #https://docs.quanteda.io/reference/kwic.html | |
| 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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment