sarcasm = function(sentence, pos.words, neg.words) {
    sentence = gsub("[[:punct:]]", "", sentence)
    sentence = tolower(sentence)
    words = unlist(str_split(sentence, "\\s"))
    pos.matches = match(words, pos.words)
    neg.matches = match(words, neg.words)
    if (sum(!is.na(pos.matches)) > 0 & sum(!is.na(neg.matches)) > 0) {
        print(sentence)
        print("pos.words:")
        print(pos.words[pos.matches])
        print("neg.words:")
        print(neg.words[neg.matches])
    }
}
pos.words = scan("positive_words.txt", what = "char")
neg.words = scan("negative_words.txt", what = "char")
load("cred.RData")
registerTwitterOAuth(cred)
## [1] TRUE
mydata.vectors = laply(searchTwitter("@delta"), function(t) t$getText())
for (mydata.vector in mydata.vectors) {
    sarcasm(mydata.vector, pos.words, neg.words)
    print("*********************************")
}
## [1] "*********************************"
## [1] "delta disappointed with amex companion ticket program too many limitations on flights may need new travel card if this best i can get"
## [1] "pos.words:"
##  [1] NA     NA     NA     NA     NA     NA     NA     NA     NA     NA    
## [11] NA     NA     NA     NA     NA     NA     NA     NA     NA     "best"
## [21] NA     NA     NA    
## [1] "neg.words:"
##  [1] NA             "disappointed" NA             NA            
##  [5] NA             NA             NA             NA            
##  [9] NA             "limitations"  NA             NA            
## [13] NA             NA             NA             NA            
## [17] NA             NA             NA             NA            
## [21] NA             NA             NA            
## [1] "*********************************"
## [1] "called delta 2 reroute due 2 flight delaymissed connection spoke to real person who fixed problem in reasonable time surprise travelwin"
## [1] "pos.words:"
##  [1] NA           NA           NA           NA           NA          
##  [6] NA           NA           NA           NA           NA          
## [11] NA           NA           NA           NA           NA          
## [16] NA           NA           "reasonable" NA           NA          
## [21] NA          
## [1] "neg.words:"
##  [1] NA        NA        NA        NA        NA        NA        NA       
##  [8] NA        NA        NA        NA        NA        NA        NA       
## [15] NA        "problem" NA        NA        NA        NA        NA       
## [1] "*********************************"
## [1] "*********************************"
## [1] "*********************************"
## [1] "*********************************"
## [1] "*********************************"
## [1] "*********************************"
## [1] "*********************************"
## [1] "*********************************"
## [1] "*********************************"
## [1] "*********************************"
## [1] "*********************************"
## [1] "*********************************"
## [1] "*********************************"
## [1] "*********************************"
## [1] "*********************************"
## [1] "in light of a mechanical delay brian and dana are rockstars on flight 960 indatl thanks for doing what you can to comfort us delta"
## [1] "pos.words:"
##  [1] NA          NA          NA          NA          NA         
##  [6] NA          NA          NA          NA          NA         
## [11] "rockstars" NA          NA          NA          NA         
## [16] NA          NA          NA          NA          NA         
## [21] NA          NA          "comfort"   NA          NA         
## [1] "neg.words:"
##  [1] NA      NA      NA      NA      NA      "delay" NA      NA     
##  [9] NA      NA      NA      NA      NA      NA      NA      NA     
## [17] NA      NA      NA      NA      NA      NA      NA      NA     
## [25] NA     
## [1] "*********************************"
## [1] "theres a guy on the floor of the delta sky club snoring loud enough that i had to get up and move no more red eyes for that guy"
## [1] "pos.words:"
##  [1] NA       NA       NA       NA       NA       NA       NA      
##  [8] NA       NA       NA       NA       NA       NA       "enough"
## [15] NA       NA       NA       NA       NA       NA       NA      
## [22] NA       NA       NA       NA       NA       NA       NA      
## [29] NA      
## [1] "neg.words:"
##  [1] NA     NA     NA     NA     NA     NA     NA     NA     NA     NA    
## [11] NA     NA     "loud" NA     NA     NA     NA     NA     NA     NA    
## [21] NA     NA     NA     NA     NA     NA     NA     NA     NA    
## [1] "*********************************"
## [1] "rt joeyhandracing well that didnt work out changed flight to surprise my kids and delta delay in orlando has got me missing my conn "
## [1] "pos.words:"
##  [1] NA     NA     "well" NA     NA     "work" NA     NA     NA     NA    
## [11] NA     NA     NA     NA     NA     NA     NA     NA     NA     NA    
## [21] NA     NA     NA     NA     NA    
## [1] "neg.words:"
##  [1] NA      NA      NA      NA      NA      NA      NA      NA     
##  [9] NA      NA      NA      NA      NA      NA      NA      "delay"
## [17] NA      NA      NA      NA      NA      NA      NA      NA     
## [25] NA     
## [1] "*********************************"
## [1] "rt joeyhandracing well that didnt work out changed flight to surprise my kids and delta delay in orlando has got me missing my conn "
## [1] "pos.words:"
##  [1] NA     NA     "well" NA     NA     "work" NA     NA     NA     NA    
## [11] NA     NA     NA     NA     NA     NA     NA     NA     NA     NA    
## [21] NA     NA     NA     NA     NA    
## [1] "neg.words:"
##  [1] NA      NA      NA      NA      NA      NA      NA      NA     
##  [9] NA      NA      NA      NA      NA      NA      NA      "delay"
## [17] NA      NA      NA      NA      NA      NA      NA      NA     
## [25] NA     
## [1] "*********************************"
## [1] "well that didnt work out changed flight to surprise my kids and delta delay in orlando has got me missing my connectionway bummed"
## [1] "pos.words:"
##  [1] "well" NA     NA     "work" NA     NA     NA     NA     NA     NA    
## [11] NA     NA     NA     NA     NA     NA     NA     NA     NA     NA    
## [21] NA     NA     NA    
## [1] "neg.words:"
##  [1] NA      NA      NA      NA      NA      NA      NA      NA     
##  [9] NA      NA      NA      NA      NA      "delay" NA      NA     
## [17] NA      NA      NA      NA      NA      NA      NA     
## [1] "*********************************"
## [1] "oh how i love and miss you delta and how i hate you aaairlines cancelled"
## [1] "pos.words:"
##  [1] NA     NA     NA     "love" NA     NA     NA     NA     NA     NA    
## [11] NA     NA     NA     NA     NA    
## [1] "neg.words:"
##  [1] NA     NA     NA     NA     NA     "miss" NA     NA     NA     NA    
## [11] NA     "hate" NA     NA     NA    
## [1] "*********************************"
## [1] "*********************************"
## [1] "delta seats were reassigned  wife and i split up glad we went through trouble to pick seats"
## [1] "pos.words:"
##  [1] NA     NA     NA     NA     NA     NA     NA     NA     NA     NA    
## [11] "glad" NA     NA     NA     NA     NA     NA     NA    
## [1] "neg.words:"
##  [1] NA        NA        NA        NA        NA        NA        NA       
##  [8] NA        "split"   NA        NA        NA        NA        NA       
## [15] "trouble" NA        NA        NA       
## [1] "*********************************"