I use the Bigram & Trigram statistic probability to predict next word.The predict word is the word with highest Trigram or Bigram (if input phrase contains only one word. or Trigram has no output) probability. In the results, stopword from package(tm) and letters were removed.
some key codes for these steps were:
v2Fm$Ptwo<-(v2Fm$Freq.y+1)/(v2Fm$Freq.x+nrow(v1F)) #calculate bigram probability
v3Fm$Ptri<-(v3Fm$gram3Freq+1)/(v3Fm$gram2Freq+nrow(v1F)) #calculate trigram probability
regex <- paste0("\\s*\\b(", paste(wordsToRemove, collapse="|"), ")\\b") #get word to remove expression
Thanks for trying! And hope you find my app useful!