2022-12-23

Introduction

This shiny app demonstrates an algorithm I developed for predicting the word that the app user is typing.

The app displays a keyboard where the app user can type. As the user types, the app displays three words that are its predictions of what word is being typed. The user can then either

  • Type the Space Bar (to tell the app that the next word is the exact sequence of letters already typed) or
  • Click on one of the predicted words (to tell the app to select that word)

Preparing Data For The App

The predictions this app makes are based upon an analysis of a file containing a sample of English language text. The text was processed for use by the app as follows:

  • First, the text was “cleaned” by converting all letters to lower case and removing punctuation marks (except for inter-word dashes and apostrophes)
  • Next, the ngram package was used to construct a list of unique words within the cleaned text in order of frequency of usage (List #1)
  • Next, the ngram package was used to construct a list of unique word pairs within the cleaned text in order of frequency of usage (List #2)

How The App Works

Predicting The First Word

When the first word is being typed, word prediction is performed by

  • Comparing the letters typed with the corresponding first letters of the words in List #1
  • Displaying the first three words that match

How The App Works

Predicting Subsequent Words

When the second or later word is being typed, word prediction is performed by

  • Filtering List #2 to select only those word pairs whose first word is the same as the most-recent complete word typed
  • Comparing the letters typed with the corresponding first letters of the second word in the filtered word pairs
  • Displaying the first three matching second words