-
Notifications
You must be signed in to change notification settings - Fork 2
Spellcheck Design Document
A tool which, given a text, will search for misspelled words and will suggest alternative spellings.
-
Interactive Mode
Allows the user to interactively correct misspellings through user’s selection of possible suggestions for correction.
-
Batch Mode
Replaces all misspelled words with the best corrections possible given a text file through the command line. The process can be given more detail through several flags following the command line prompt.
Given a dictionary that is either pre-loaded into the Redis server or loaded from scratch, we must be able to determine if words are inside the dictionary. Thus, our definition of whether a word is spelled correctly is if it is contained inside the dictionary. The dictionary will be stored in a trie for efficiency.
Levenshtein Distance is a metric that computes the edit difference between two sequences. The smaller the edit distance between two words, the closer a word will be to another.
cat -> hat : Levenshtein distance = 1
cat -> apricot: Levenshtein distance = 6
By finding the word with the smallest Levenshtein Distance from another word, we can predict that that word was the most likely word the user meant to type. Spellcheck will generate suggestions for a misspelled word by using the words in the dictionary as a list of possible words.
If spellcheck is run without a file, it directs the user to the following screen:
Please load a file to begin. Additionally, select an output mode and/or choose dictionary before running the program.
[f] [/path/file.txt] : Input text file
[d] [/path/dictionary.txt] : Input custom dictionary file
[m] [number] : Mode [1 - Quiet, 2 - Verbose, 3 - Interactive]
[c] : Enable/Disable color
[h] : Help
[q] : Quit program
spellcheck >
For each detected error, the interactive mode produces: (1) An indication of the location of the error
Line: 1:
I have a splling checker
^^^^^^^
(2) Generated suggestions, and options to delete the word, input an alternative word, or skip for users
Possible replacements for word splling are:
[1] : selling
[2] : spelling
[3] : billing
[4] : calling
[d] : Delete
[i] : Input
[s] : Skip
Interactive Mode continues this process until the end of the file. When finished, interactive mode moves onto the saving file page:
Spellcheck complete.
[p] : Print all modifications
[s] : Save to existing file
[c] : Save to custom file
[r] : Re-edit file
[q] : Quit program
The user can then view changes, then either save corrections to the original file, or save to a file of choice.
The user can activate quiet mode through the command line directly. The user runs:
$ ./spellcheck [~/path/file.txt] -q [options]
Alternatively, the user can also activate quiet mode through the main directory. To do this, simply input:
$ ./spellcheck
Note that the default mode is interactive, and that a file input will direct the user immediately to interactive mode.
Running quiet mode edits the given text file by replacing every identified misspelled word with the closest possible correction. The corrections are saved to the same file by default.
Additionally, several flags can be utilized to customize the quiet mode process through the command line. These are:
-q : Quiet mode - The program does not print any statements regarding the replacement process.
-s [~path/file.txt] : Saves the edited version to a new text file instead of modifying the original file.
The user can activate batch mode through the command line directly. The user runs:
$ ./spellcheck [~/path/file.txt] - [options]
If user chooses to utilize the verbose mode, spellcheck produces a list of detected errors, and up to 4 corresponding suggested corrections.
LINE:CHAR WORD SUGGESTIONS
1:9 spellig spelling, selling, spell
1:17 chequer cheque, cheaper, checker, chester
2:3 cme came, ce, cm, cms
3:11 markes makes, marked, marker, markers
3:25 revie review, device, devil, eve
4:0 Misstakes Mistakes, Mistake
5:19 typpe type, tape, types
6:19 asy amy, any, as, ash
7:0 Wether Weather, Whether, Better, Bother
8:12 straigh straight, strain, strange
8:20 waay away, way
Successfully replaced every misspelled word and saved the modifications