• About Me
  • Programming
  • Structural Engineering
  • Photography
  • The Quran Initiative
  • More
    • About Me
    • Programming
    • Structural Engineering
    • Photography
    • The Quran Initiative
  • About Me
  • Programming
  • Structural Engineering
  • Photography
  • The Quran Initiative

Word Suggester Application (c++)

<< back to list of programming projects


The Word Suggester program suggests next words for any given word. The suggestion library is developed by scanning 100 different books (available under: http://www.textfiles.com/etext/ and storing frequencies of occurrence of each word and its immediate next word.


To expedite the storing, loading and look-up procedures, a hash table of hash tables is used as the primary data structure. The primary hash table stores each word that the program scans as the “key”, and links to a secondary hash table that serves as the “value.” The secondary hash table stores all words that followed the “key” word from the primary hash table and the frequency of such occurrences. For example, for the short excerpt: “Dory was a fish who always forgot everything. Unlike other fish who knew where to go, Dory would aimlessly wander around and chat with all fish she came across"


The secondary hash table for "fish" would look like: {who, 2}, {she, 1}


In addition, a separate sorted vector of the 5 most frequent next-words is maintained for each word, in order to return the most frequent word suggestions in O(1) time. The number of frequent words can be changed from 5 to any other value within the code. In future modifications of the program, I would like to have a "context" dependent suggestion that provides word suggestions with respect to the rest of the writing.


The program is written in C++.

Check out the code at: https://github.com/nablul/Word-Suggester

Sample program run:

Welcome to the Word Predictor application! This application provides next word suggestions based on

data from approximately hundred books. Please use the following commands to navigate the application:


Load: Load existing word suggestions saved under wordMap.txt

LoadFile: Load additional .txt file into to increase word suggestions

Size: Displays number of words currently stored in library

Save: Save word suggestions under wordMap.txt

Run: Run application and get word suggestions.

ExitApp: Exit application


>> load


>> run

Enter word:

the

Next word suggestions: {shadow, fellow, period, age, firstrecalled}


red

Next word suggestions: {and, cap, caps, coals, upon}


sky

Next word suggestions: {and, was, in, there, overcast}


my

Next word suggestions: {dear, father, name, friend, business}


tree

Next word suggestions: {and, of, many, when, has}


time

Next word suggestions: {there, was, a, sir, here}


kanyewest

Word not part of loaded library, sorry


school

Next word suggestions: {said, of, was, for, he}


queen

Next word suggestions: {and, the, it, with, all}


exitApp


Copyright © 2022 Nablul - All Rights Reserved.