Document to answer the questions of Quiz of Coursera Data Science Capstone.

library(stringr)
library(stringi)
library(tm)
## Loading required package: NLP
library(wordcloud)
## Loading required package: RColorBrewer
library(ggplot2)
## 
## Attaching package: 'ggplot2'
## The following object is masked from 'package:NLP':
## 
##     annotate
w_Blogs <- readLines("en_US.blogs.txt")
#Select ALL DOCUMENTS in News
w_News <- readLines("en_US.news.txt")
## Warning in readLines("en_US.news.txt"): incomplete final line found on
## 'en_US.news.txt'
#Select ALL DOCUMENTS in Twitters
w_Twitter <- readLines("en_US.twitter.txt")
## Warning in readLines("en_US.twitter.txt"): line 167155 appears to contain an
## embedded nul
## Warning in readLines("en_US.twitter.txt"): line 268547 appears to contain an
## embedded nul
## Warning in readLines("en_US.twitter.txt"): line 1274086 appears to contain an
## embedded nul
## Warning in readLines("en_US.twitter.txt"): line 1759032 appears to contain an
## embedded nul
summary(w_Blogs)
##    Length     Class      Mode 
##    899288 character character
summary(w_News)
##    Length     Class      Mode 
##     77259 character character
summary(w_Twitter)
##    Length     Class      Mode 
##   2360148 character character
tokenmaker <- function(x) {
        corpus <- Corpus(VectorSource(x))
        corpus <- tm_map(corpus, content_transformer(tolower))
        corpus <- tm_map(corpus, removePunctuation)
        corpus <- tm_map(corpus, stripWhitespace)
        corpus <- tm_map(corpus, removeWords, stopwords("english"))
        corpus <- tm_map(corpus, removeNumbers)
        corpus <- tm_map(corpus, PlainTextDocument)
        corpus <- Corpus(VectorSource(corpus))
}  

wordcounter <- function(x) {
        dtm<-DocumentTermMatrix(x)
        dtm_matrix <- as.matrix(dtm)
        word_freq <- colSums(dtm_matrix)
        word_freq <- sort(word_freq, decreasing = TRUE)
        words <- names(word_freq)
        return(list(words, word_freq))
}  

Next_Word <- function(x,y){
        BQuest<-grepl(x, w_Blogs, ignore.case=TRUE)
        BDocs<-w_Blogs[BQuest]
        c_text<-'a'
        Next_Word<-'a'
        i<-length(BDocs)
        if (i>0)
                {
                for (i in 1:i)
                {  c_text[i]<- str_extract(BDocs[i], y)
                Next_Word[i]<- stri_extract_last_words(c_text[i]) 
                }
                }
        NQuest<-grepl(x, w_News, ignore.case=TRUE)
        NDocs<-w_News[NQuest]
        j=length(NDocs)
        if (j>0)
                {
                for (j in 1:j)
                {  c_text[i+j]<- str_extract(NDocs[j], y)
                Next_Word[i+j]<- stri_extract_last_words(c_text[i+j]) 
                }
                }
        TQuest<-grepl(x, w_Twitter, ignore.case=TRUE)
        TDocs<-w_Twitter[TQuest]
        k=length(TDocs)
        if (k>0)
                {
                for (k in 1:k)
                {  c_text[i+j+k]<- str_extract(TDocs[k], y)
                Next_Word[i+j+k]<- stri_extract_last_words(c_text[i+j+k]) 
                }
                }
        bundle<-as.data.frame(Next_Word, stringsAsFactors=FALSE)
        summary (bundle)
        blogs_token <- tokenmaker(bundle)
        blogs_words <- wordcounter(blogs_token)
        summary(nchar(bundle))
        head(bundle)
        tdm_Blogs<-TermDocumentMatrix(blogs_token)
        m_Blogs<-as.matrix(tdm_Blogs)
        v_Blogs<-sort(rowSums(m_Blogs),decreasing=TRUE)
        d_Blogs<-data.frame(word=names(v_Blogs),freq=v_Blogs)
        head(v_Blogs, 100)    
        return(list(head(v_Blogs,100)))
}

–Question 1-

result_01<-Next_Word("a case of ", "([Aa]+ +[Cc]ase+ +[Oo]f+ +[^ ]+ )" )
## Warning in tm_map.SimpleCorpus(corpus, content_transformer(tolower)):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(corpus, removePunctuation): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, stripWhitespace): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, removeWords, stopwords("english")):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(corpus, removeNumbers): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, PlainTextDocument): transformation drops
## documents
result_01
## [[1]]
##              beer     character(0),            miller          mistaken 
##                19                 5                 4                 4 
##              wine             first            making           waiting 
##                 4                 3                 3                 3 
##             water           crossed              food             great 
##                 3                 2                 2                 2 
##               jet           knowing              mind               one 
##                 2                 2                 2                 2 
##             pabst              poor               red            severe 
##                 2                 2                 2                 2 
##            spring             trial            trying           whether 
##                 2                 2                 2                 2 
##        "cargument               0),              121,               20, 
##                 1                 1                 1                 1 
## 21.5346229076385,               25,               26,               45, 
##                 1                 1                 1                 1 
##           amnesia            anchor           anxiety             armed 
##                 1                 1                 1                 1 
##          arrested               art        assembling            baboon 
##                 1                 1                 1                 1 
##               bad           bananas             banks            better 
##                 1                 1                 1                 1 
##             bible           bolting             books          boosting 
##                 1                 1                 1                 1 
##           bottles             bowed             boxer               bud 
##                 1                 1                 1                 1 
##              bulk             buyer        bwvaktboom            carpal 
##                 1                 1                 1                 1 
##           carrots          catching               cds        cellulitis 
##                 1                 1                 1                 1 
##          changing    character(0)))          citation             class 
##                 1                 1                 1                 1 
##              cold             colic        collateral       conspicuous 
##                 1                 1                 1                 1 
##              cool             coors            corona           damaged 
##                 1                 1                 1                 1 
##     datetimestamp           defense              deja             delhi 
##                 1                 1                 1                 1 
##        democratic         dependent       description           dialing 
##                 1                 1                 1                 1 
##           digging               dip           dipping        disgusting 
##                 1                 1                 1                 1 
##       disposables           dispute             dodge            double 
##                 1                 1                 1                 1 
##        dragonitis              duct            dundee             ebola 
##                 1                 1                 1                 1 
##         everybody         excusable         exploring           extreme 
##                 1                 1                 1                 1 
##          extremes           fascism           fearing           finding 
##                 1                 1                 1                 1

The answer is “beer” since it is the most frequent word that makes the sentence make sense. –Question 2—

result_02<-Next_Word("would mean the ", "([Ww]ould+ +[Mm]ean+ +[Tt]he+ +[^ ]+ )" )  
## Warning in tm_map.SimpleCorpus(corpus, content_transformer(tolower)):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(corpus, removePunctuation): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, stripWhitespace): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, removeWords, stopwords("english")):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(corpus, removeNumbers): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, PlainTextDocument): transformation drops
## documents
result_02
## [[1]]
##             world     character(0),          absolute               end 
##               168                 5                 2                 2 
##            entire           "cworld               0),              121, 
##                 2                 1                 1                 1 
##               20,               25,               26, 33.9637188911438, 
##                 1                 1                 1                 1 
##               45,           airport            angles           central 
##                 1                 1                 1                 1 
##           century    character(0)))     datetimestamp             death 
##                 1                 1                 1                 1 
##       description           heading              hour             isdst 
##                 1                 1                 1                 1 
##          language       list(author      list(content          list(sec 
##                 1                 1                 1                 1 
##              mday              meta               min               mon 
##                 1                 1                 1                 1 
##            origin            person            sitter             state 
##                 1                 1                 1                 1 
##               sun    transformation              wday           world", 
##                 1                 1                 1                 1 
##            worldd              yday              year             "en") 
##                 1                 1                 1                 1 
##     list(language            list() 
##                 1                 1

The answer is “world” since it is the most frequent word that makes the sentence make sense.

–Question 3-

result_03<-Next_Word("make me the ", "([Mm]ake+ +[Mm]e+ +[Tt]he+ +[^ ]+ )" )  
## Warning in tm_map.SimpleCorpus(corpus, content_transformer(tolower)):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(corpus, removePunctuation): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, stripWhitespace): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, removeWords, stopwords("english")):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(corpus, removeNumbers): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, PlainTextDocument): transformation drops
## documents
result_03
## [[1]]
##          happiest     character(0),              best            worlds 
##                26                 5                 2                 2 
##           "cfirst               0),              121,               20, 
##                 1                 1                 1                 1 
##               25,               26,               45, 47.8151431083679, 
##                 1                 1                 1                 1 
##           asshole               bad           biggest               bun 
##                 1                 1                 1                 1 
##    character(0)))     datetimestamp          daughter       description 
##                 1                 1                 1                 1 
##              girl        happiest",           heading              hour 
##                 1                 1                 1                 1 
##             isdst            jackie             kiddy          language 
##                 1                 1                 1                 1 
##       list(author      list(content          list(sec           manager 
##                 1                 1                 1                 1 
##              mday              meta               min               mon 
##                 1                 1                 1                 1 
##            morbid            mother            number            origin 
##                 1                 1                 1                 1 
##            parent      professional              role             scape 
##                 1                 1                 1                 1 
##            target        undisputed          universe               way 
##                 1                 1                 1                 1 
##              wday            winner              yday              year 
##                 1                 1                 1                 1 
##             "en")     list(language            list() 
##                 1                 1                 1

The answer is “happiest”. –Question 4—

result_04<-Next_Word("struggling ", "([Ss]truggling+ +[^ ]+ +[^ ]+ +[^ ]+ )" )  
## Warning in tm_map.SimpleCorpus(corpus, content_transformer(tolower)):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(corpus, removePunctuation): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, stripWhitespace): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, removeWords, stopwords("english")):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(corpus, removeNumbers): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, PlainTextDocument): transformation drops
## documents
result_04
## [[1]]
##               ends                bit               fact               life 
##                 15                  8                  7                  6 
##                new              years      character(0),              first 
##                  6                  6                  5                  5 
##               keep             afloat               back             issues 
##                  5                  4                  4                  4 
##                now               part            touring               work 
##                  4                  4                  4                  4 
##               baby                buy                can             eating 
##                  3                  3                  3                  3 
##               even               food               make              money 
##                  3                  3                  3                  3 
##           mortgage               self              sense              since 
##                  3                  3                  3                  3 
##             social              still              stuff             things 
##                  3                  3                  3                  3 
##              think               time             weight            another 
##                  3                  3                  3                  2 
##           anything              awake                bad               care 
##                  2                  2                  2                  2 
##              child            concept         conditions              crust 
##                  2                  2                  2                  2 
##              dance                day             desire            economy 
##                  2                  2                  2                  2 
##             enough         everything               free             gender 
##                  2                  2                  2                  2 
##                god              going              great               head 
##                  2                  2                  2                  2 
##           identity               jobs               just               last 
##                  2                  2                  2                  2 
##             lately                lot            neutral            outside 
##                  2                  2                  2                  2 
##         particular                pay           payments             photos 
##                  2                  2                  2                  2 
##             pounds            readers             really              right 
##                  2                  2                  2                  2 
##               said             school             season          something 
##                  2                  2                  2                  2 
##            started              state              times                way 
##                  2                  2                  2                  2 
##               ways               will               wont              world 
##                  2                  2                  2                  2 
##               year               "cin                0), 0.945008993148804, 
##                  2                  1                  1                  1 
##               121,                20,                25,                26, 
##                  1                  1                  1                  1 
##                46,               able             absent           academic 
##                  1                  1                  1                  1 
##       accidentally          addiction           addition              adult 
##                  1                  1                  1                  1
result_04a<-Next_Word("struggling ", "([Ss]truggling+ +[^ ]+ +[^ ]+ )" )  
## Warning in tm_map.SimpleCorpus(corpus, content_transformer(tolower)):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(corpus, removePunctuation): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, stripWhitespace): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, removeWords, stopwords("english")):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(corpus, removeNumbers): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, PlainTextDocument): transformation drops
## documents
result_04a
## [[1]]
##          find           get          make          keep           bit 
##            54            51            36            33            15 
##       survive          stay        little           pay           now 
##            14            12            10            10             9 
##        figure      maintain    understand          work           fit 
##             8             8             8             7             6 
##          like           put           see     something         carry 
##             6             6             6             6             5 
## character(0),    depression        finish          hold          just 
##             5             5             5             5             5 
##          life         raise         reach          walk        breath 
##             5             5             5             5             4 
##         bring          come       control          cope   infertility 
##             4             4             4             4             4 
##      musician        afford           air        almost       another 
##             4             3             3             3             3 
##       breathe         catch           day        decide          feel 
##             3             3             3             3             3 
##          free          hard        issues         learn          loss 
##             3             3             3             3             3 
##           lot        market          much      preserve       recover 
##             3             3             3             3             3 
##      remember         right          sell         start         write 
##             3             3             3             3             3 
##          year        accept     addiction          back          best 
##             3             2             2             2             2 
##         break    businesses           buy         check         clear 
##             2             2             2             2             2 
##         climb         close        coming       compete      complete 
##             2             2             2             2             2 
##       contain        escape     establish          feed       feeding 
##             2             2             2             2             2 
##         first         focus          gain          half        handle 
##             2             2             2             2             2 
##          hide          high           hit      identity          live 
##             2             2             2             2             2 
##          long         maker        manage          math          meet 
##             2             2             2             2             2 
##          move      negative      overcome        people      practice 
##             2             2             2             2             2
result_04b<-Next_Word("struggling ", "([Ss]truggling+ +[^ ]+ )" )  
## Warning in tm_map.SimpleCorpus(corpus, content_transformer(tolower)):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(corpus, removePunctuation): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, stripWhitespace): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, removeWords, stopwords("english")):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(corpus, removeNumbers): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, PlainTextDocument): transformation drops
## documents
result_04b
## [[1]]
##       financially             right              just           readers 
##                 9                 8                 7                 6 
##        struggling          students     character(0),           economy 
##                 6                 6                 5                 5 
##            writer            artist           artists          mightily 
##                 5                 4                 4                 4 
##               nyc             since         americans              city 
##                 4                 4                 3                 3 
##          families            lately          learners              like 
##                 3                 3                 3                 3 
##               now             today            trying           actress 
##                 3                 3                 3                 2 
##             chain           company       consistency             daily 
##                 2                 2                 2                 2 
##             early             every             going           housing 
##                 2                 2                 2                 2 
##       offensively             quite             radio         residents 
##                 2                 2                 2                 2 
##           schools              team             urban           writers 
##                 2                 2                 2                 2 
##              "cin               0),              121,               20, 
##                 1                 1                 1                 1 
##               25,               26, 27.7474119663239,               46, 
##                 1                 1                 1                 1 
##         abandoned             actor           addicts            adding 
##                 1                 1                 1                 1 
##               air          airlines             along            always 
##                 1                 1                 1                 1 
##             among           anymore       apprentices               art 
##                 1                 1                 1                 1 
##        artist<e2>          attorney              away             baker 
##                 1                 1                 1                 1 
##         barrister            behind               big             black 
##                 1                 1                 1                 1 
##             blues              born         breweries           brewery 
##                 1                 1                 1                 1 
##          business       businessman    character(0)))             child 
##                 1                 1                 1                 1 
##          children     christian<e2>            cities             climb 
##                 1                 1                 1                 1 
##           college         companies        constantly         continued 
##                 1                 1                 1                 1 
##           country            cyster     datetimestamp             david 
##                 1                 1                 1                 1 
##        department       description       desperately         developed 
##                 1                 1                 1                 1 
##          downtown          economic        elementary         employees 
##                 1                 1                 1                 1 
##       engineering          entities               ers               esp 
##                 1                 1                 1                 1

Question 4 answer: There is no sequence “struggling but the” in whole corpus. I try with struggling and any other 3, 2 and 1 words in sequence. The answer is “defense” because this word have sense in the sentence.

–Question 5—

result_05<-Next_Word("date at the ", "([Dd]ate+ +[Aa]t+ +[Tt]he+ +[^ ]+ )" )  
## Warning in tm_map.SimpleCorpus(corpus, content_transformer(tolower)):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(corpus, removePunctuation): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, stripWhitespace): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, removeWords, stopwords("english")):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(corpus, removeNumbers): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, PlainTextDocument): transformation drops
## documents
result_05
## [[1]]
##     character(0),               end              time           "cwrong 
##                 5                 5                 3                 1 
##               0),              121,               20,               25, 
##                 1                 1                 1                 1 
##               26, 39.9228720664978,               46,               app 
##                 1                 1                 1                 1 
##               art            bottom            braves              cake 
##                 1                 1                 1                 1 
##    character(0)))            cheese     datetimestamp       description 
##                 1                 1                 1                 1 
##          driskill              four         grocery",           heading 
##                 1                 1                 1                 1 
##              hour             isdst              lake          language 
##                 1                 1                 1                 1 
##       list(author      list(content          list(sec              mday 
##                 1                 1                 1                 1 
##              meta               min               mon             movie 
##                 1                 1                 1                 1 
##             naval              next            origin           palafox 
##                 1                 1                 1                 1 
##             prado       prestigious        republican               rex 
##                 1                 1                 1                 1 
##              wday           whiskey              yday              year 
##                 1                 1                 1                 1 
##             "en")     list(language            list() 
##                 1                 1                 1

The correct answer is “beach”, because this word have sense in teh sentence.

–Question 6—

result_06<-Next_Word("be on my ", "([Bb]e+ +[Oo]n+ +[Mm]y+ +[^ ]+ )" )  
## Warning in tm_map.SimpleCorpus(corpus, content_transformer(tolower)):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(corpus, removePunctuation): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, stripWhitespace): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, removeWords, stopwords("english")):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(corpus, removeNumbers): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, PlainTextDocument): transformation drops
## documents
result_06
## [[1]]
##               way              mind              show              best 
##                32                12                 8                 5 
##     character(0),              list              game              ipod 
##                 5                 5                 4                 4 
##             radio        background              side               top 
##                 4                 3                 3                 3 
##           youtube              back             couch              dick 
##                 3                 2                 2                 2 
##          facebook              feet             first           friends 
##                 2                 2                 2                 2 
##              last              next             phone             porch 
##                 2                 2                 2                 2 
##            screen             terms              "cna               0), 
##                 2                 2                 1                 1 
##              121,               20,               25,               26, 
##                 1                 1                 1                 1 
##               46, 51.8344950675964,             album            annual 
##                 1                 1                 1                 1 
##               bad              bday             belly          birthday 
##                 1                 1                 1                 1 
##              blog             board             break               bus 
##                 1                 1                 1                 1 
##            career           channel    character(0)))          children 
##                 1                 1                 1                 1 
##         christmas           college          computer           couch", 
##                 1                 1                 1                 1 
##               cuz              dads             daily     datetimestamp 
##                 1                 1                 1                 1 
##               day       description          deserved      dissertation 
##                 1                 1                 1                 1 
##              dolo             dsixl              etsy           fantasy 
##                 1                 1                 1                 1 
##          favorite             final            flight             grave 
##                 1                 1                 1                 1 
##             grind            guilty           heading           holiday 
##                 1                 1                 1                 1 
##              hour            icloud             ihome             isdst 
##                 1                 1                 1                 1 
##             knees          language               lap            laptop 
##                 1                 1                 1                 1 
##            linked       list(author      list(content          list(sec 
##                 1                 1                 1                 1 
##           lostken              mday  melodifestivalen              menu 
##                 1                 1                 1                 1 
##              meta               min            mobile              moms 
##                 1                 1                 1                 1 
##               mon             mouth               new          official 
##                 1                 1                 1                 1 
##            origin          personal              pone              pure 
##                 1                 1                 1                 1

The correct answer is “way”. –Question 7—

result_07<-Next_Word("quite some ", "([Qq]uite+ +[Ss]ome+ +[^ ]+ )" )  
## Warning in tm_map.SimpleCorpus(corpus, content_transformer(tolower)):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(corpus, removePunctuation): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, stripWhitespace): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, removeWords, stopwords("english")):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(corpus, removeNumbers): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, PlainTextDocument): transformation drops
## documents
result_07  
## [[1]]
##              time     character(0),           company          distance 
##               274                 5                 2                 2 
##            people               way            "ctime               0), 
##                 2                 2                 1                 1 
##              121,               20,               25,               26, 
##                 1                 1                 1                 1 
##               47, 5.92976808547974,    character(0)))     datetimestamp 
##                 1                 1                 1                 1 
##       description            extras           freedom               fun 
##                 1                 1                 1                 1 
##              hair           heading              hour       improvement 
##                 1                 1                 1                 1 
##       interesting             isdst          language       list(author 
##                 1                 1                 1                 1 
##      list(content          list(sec              mday              meta 
##                 1                 1                 1                 1 
##               min               mon            months              na", 
##                 1                 1                 1                 1 
##              news            origin          terrible            things 
##                 1                 1                 1                 1 
##         tradition              wday              yday              year 
##                 1                 1                 1                 1 
##             years             "en")     list(language            list() 
##                 1                 1                 1                 1

The answer is “time”, that make sense in the sentence.

–Question 8—

result_08<-Next_Word("his little ", "([Hh]is+ +[Ll]ittle+ +[^ ]+ )" )  
## Warning in tm_map.SimpleCorpus(corpus, content_transformer(tolower)):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(corpus, removePunctuation): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, stripWhitespace): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, removeWords, stopwords("english")):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(corpus, removeNumbers): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, PlainTextDocument): transformation drops
## documents
result_08  
## [[1]]
##          girl           guy           boy           gem          blog 
##            89            60            42            33            28 
##           one       brother        beauty           man        sister 
##            27            22            21            18            18 
##         cutie       project          baby           bit         piece 
##            16            16            15            14            12 
##         piggy           kid        corner          head        number 
##            12            11            10            10            10 
##         thing          book           dog         heart          lady 
##            10             9             9             9             9 
##          game         house          blue         angel          body 
##             8             8             7             6             6 
##           box          face        finger          hand         hands 
##             6             6             6             6             6 
##        league         light           old        person        tidbit 
##             6             6             6             6             6 
##         video         white         break          card character(0), 
##             6             6             5             5             5 
##         ditty          dude        family         girls          legs 
##             5             5             5             5             5 
##          life          note          tiny           bag      brothers 
##             5             5             5             4             4 
##           car         child          feet         fella          film 
##             4             4             4             4             4 
##       fingers       journey        nugget          ones         place 
##             4             4             4             4             4 
##      princess         scene           son          spot         story 
##             4             4             4             4             4 
##    sweetheart       sweetie          town        yellow           ass 
##             4             4             4             4             3 
##         belly          bird        bundle         chair      daughter 
##             3             3             3             3             3 
##      exercise          eyes          gift         girly         group 
##             3             3             3             3             3 
##          idea         kitty          list          mama       miracle 
##             3             3             3             3             3 
##        monkey          peek   personality          pink          post 
##             3             3             3             3             3 
##         quilt          quiz        series         table          trip 
##             3             3             3             3             3

The answer is “fingers” that make sense in the sentence. –Question 9—

result_09<-Next_Word("during the ", "([Dd]uring+ +[TT]he+ +[^ ]+ )" )  
## Warning in tm_map.SimpleCorpus(corpus, content_transformer(tolower)):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(corpus, removePunctuation): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, stripWhitespace): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, removeWords, stopwords("english")):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(corpus, removeNumbers): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, PlainTextDocument): transformation drops
## documents
result_09 
## [[1]]
##     character(0),         amendment           biggest               day 
##                 5                 2                 2                 2 
##              "cna               0),              121,               20, 
##                 1                 1                 1                 1 
##               25,               26, 33.0719590187073,               47, 
##                 1                 1                 1                 1 
##               act       believetour               big          birthday 
##                 1                 1                 1                 1 
##            bloody             booth              born            buccos 
##                 1                 1                 1                 1 
##        centennial    character(0)))               cnn         communist 
##                 1                 1                 1                 1 
##     datetimestamp       description             first             great 
##                 1                 1                 1                 1 
##           heading              hour             isdst          language 
##                 1                 1                 1                 1 
##              last              lion       list(author      list(content 
##                 1                 1                 1                 1 
##          list(sec            lonely            lovely              mday 
##                 1                 1                 1                 1 
##              meta               min               mon             movie 
##                 1                 1                 1                 1 
##              na",          notebook            origin            oscars 
##                 1                 1                 1                 1 
##             palio              rise              saga              wday 
##                 1                 1                 1                 1 
##             width              yday              year             "en") 
##                 1                 1                 1                 1 
##     list(language            list() 
##                 1                 1

The answer is “bad”. –Question 10-

result_10<-Next_Word("must be ",  "([Mm]ust+ +[Bb]e+ +[^ ]+ )" )  
## Warning in tm_map.SimpleCorpus(corpus, content_transformer(tolower)):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(corpus, removePunctuation): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, stripWhitespace): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, removeWords, stopwords("english")):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(corpus, removeNumbers): transformation drops
## documents
## Warning in tm_map.SimpleCorpus(corpus, PlainTextDocument): transformation drops
## documents
result_10  
## [[1]]
##        able        done   something       taken        made        nice 
##         105          84          80          60          59          59 
##   following     getting      really         one     willing        like 
##          56          50          50          46          43          37 
##        good       going      pretty        said        hard    prepared 
##          36          33          32          32          29          27 
##        true   submitted       given        seen    received     careful 
##          27          25          24          24          23          22 
##       crazy       lived       close         new        time        paid 
##          22          21          20          20          20          19 
##        born     feeling        kept       wrong     present       ready 
##          18          18          18          18          17          17 
##        used         put     stopped       tired   destroyed        felt 
##          17          16          16          16          15          15 
##    followed        read    watching   addressed       aware   completed 
##          15          15          15          14          14          14 
##  considered     removed     allowed       bored        held        part 
##          14          14          13          13          13          13 
##       quite     talking    thinking   wondering      coming       tough 
##          13          13          13          13          12          12 
##        just       noted   protected     someone  understood accompanied 
##          11          11          11          11          11          10 
##        free       great      honest         mad         met       right 
##          10          10          10          10          10          10 
##      strong     treated     another      around       dealt      driven 
##          10          10           9           9           9           9 
##         old      placed    provided        sick       using      almost 
##           9           9           9           9           9           8 
##    balanced       based      better         big      broken  completely 
##           8           8           8           8           8           8 
##   important    involved     missing        open   preserved        real 
##           8           8           8           8           8           8 
##    replaced        sent         set      sought 
##           8           8           8           8

The answer is “insane”, that make sense in the sentence.