Skip to content

Preparing Transcripts for qdap

trinker edited this page Aug 2, 2012 · 19 revisions

#Import Microsoft Word Transcript Into R

The following video demonstrates how to clean a Microsoft Word based transcript and read it into R.

Some rich text characters to be aware of include:

name rich.char replace
1 ellipsis ...
2 left curly quote
3 right curly quote
4 left curly apostrophe '
5 right curly apostophe '
6 en dash ...
7 em dash ...

R code used in the video

library(qdap);library(gdata)  

#doc is dependant on the name of the researcher's document
doc <- "TCH 7 Pre-data Les 2,  Year 1, 1-15-09.csv"                                   #this changes each time

dat1 <- read.csv(doc, header=FALSE,  strip.white = TRUE, sep=",", 
    as.is=FALSE, na.strings= " ") 

truncdf(dat1, 80)
htruncdf(dat1, 15, 80)
htruncdf(dat1)
left.just(htruncdf(dat1, 15, 80), 2)
library(qdap);library(gdata)  
        
dat1 <- read.csv(doc, header=FALSE,  strip.white = TRUE, sep=",", 
    as.is=FALSE, na.strings= " ")                                                         
colnames(dat1) <- c("person", "dialogue")                                         #rename the columns
is.blank <- function(x)x %in% c("", " ", "   ")                                   #function for finding blank cells
dat1 <- dat1[!apply(apply(dat1, 2, is.blank), 1, all), ]                          #select non blank cases
dat1$person <- as.factor(mgsub(c("#", " ", ":"), "", dat1$person, spacer=FALSE))  #standardize people's names
#strWrap(paste2(bracketXtract(dat1$dialogue, bracket = "curly")," "), 80)         #the story
dat1$dialogue <- bracketX(scrubber(dat1$dialogue))                                #remove extreneous marks
dat1[nchar(dat1$dialogue) < 3, ]                                                  #check to make sure everything looks good 

dat1$person <- drop.levels(dat1$person)                                           #drop unused people names (factor levels)
x <- c("Mrs.", "Ms.", "Mr.", "www.", ".com")                                      #remove abreviated names
dat1$dialogue <- mgsub(c(x, tolower(x)), c("Misses", "Miss", "Mister",  
     "www dot ", " dot com"), dat1$dialogue, fixed=TRUE)
dat1s <- sentSplit(dat1, "dialogue")                                              #splot TOT into sentences and stem                                                 
dat1s$time <- rep(time, nrow(dat1s))                                              #provide a time column for the merged data 
truncdf(dat1s[nchar(as.character(dat1s$dialogue)) < 3, ] )

#SANITY CHECKS
truncdf(dat1s, 50)