CIS 554 Scala 1: Spell Checking
Fall 2015, David Matuszek
Purpose of this assignment
- To get you started in Scala
General idea
In this assignment you are to read in, from a text file, a large list of
English words.
The user will then enter words one at a time. If the word occurs in the
word list, the program will tell the user that it is spelled correctly.
Otherwise, the program will suggest some (zero or more) possible
spellings. Continue until the user enters the word quit
(correctly spelled!).
Details
Down the word list from http://www-01.sil.org/linguistics/wordlists/english/wordlist/wordsEn.txt
and save it in a text file named wordsEn.txt. Put this file
at the top level of your project, so that you can access it easily. When
the program begins, read in this file and save the words in a set.
Spell checking algorithms are moderately complex, and this is not a
course in algorithms, so we will use a fairly simple algorithm. For each
word entered by the user:
- Check if the word is in the list of words. If so, tell the user that
the word is spelled correctly.
- If the word is not in the word list, try each of the transformations
in turn (individually, not in combination):
- Add a letter to the beginning of the word.
- Add a letter to the end of the word.
- Remove a letter from the word.
- Interchange two adjacent letters in the word.
- For each such transformation, see if the resultant "word" is in the
word list, and if it is, add it to a list of possible corrected
spellings.
- Print the list of possible corrected spellings (up to ten words per
line), or
- If no possible corrections were found, so inform the user.
The possible transformations, applied individually, should usually give
fewer than 100 possible "words" to check against the word list, so the
program should be quite fast. If there is a noticeable lag, be sure that you
are not using a data structure that requires a linear search.
For this assignment you need only a single object (call it spellChecker)
and you don't need any classes. There will be two required methods:
def main(args: Array[String])
- You always need this method
- The method should check if a word is spelled correctly, and only
call the
search method if it isn't.
def search(word: String, wordList: List[String]): Set[String]
- Given a misspelled word, find all possible corrections (there may
not be any).
- This method does no I/O.
The purpose of this assignment is to introduce you to Scala. Some of the
functional features of Scala can be useful in this program, but you are not
required to use them.
Due date
Your program is due before 6am Wednesday, November 18 .
Submit via Canvas.