To find the words that best fits the input text, the application does as follows:
- Process the input text the same way the text data was preprocesses
- Find the largest N-grams that matches the last words of the input text
- Extract the next word of each of these N-grams
- Return the most frequent next word
The application starts by looking 5-Grams (if the input text is long enough), and if it does not find any that match the input, looks at 4-Grams, and so on until unigrams. If no N-grams matches the input text, the application assumes the end of sentence is reached and returns ".".