Class FileCorrector

java.lang.Object
  extended by Corrector
      extended by FileCorrector

public class FileCorrector
extends Corrector

A Corrector whose spelling suggestions are given in a text file.

One way to get corrections for a misspelled word is to consult an external resource. This kind of Corrector uses a file that contains pairs of misspelled and corrected words to generate suggestions.


Constructor Summary
FileCorrector(java.lang.String file)
          Constructs an instance from the text file supplied.
 
Method Summary
 java.util.Set<java.lang.String> getCorrections(java.lang.String wrong)
          Returns a set of proposed corrections for an incorrect word.
 
Methods inherited from class Corrector
matchCase
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileCorrector

public FileCorrector(java.lang.String file)
              throws java.io.IOException
Constructs an instance from the text file supplied. The file should be read once and then closed. Each line of the file should have a single-comma-separated-value format: misspelled_word,corrected_word

For example:
aligatur,alligator
baloon,balloon
inspite,in spite
who'ev,who've

This constructor throws an IOException if the file doesn't adhere to above format.

For methods useful in parsing the lines of the File, see the String class documentation in java.lang.String

Parameters:
file - The name of the corrections file.
Throws:
java.io.IOException
Method Detail

getCorrections

public java.util.Set<java.lang.String> getCorrections(java.lang.String wrong)
Description copied from class: Corrector
Returns a set of proposed corrections for an incorrect word. The corrections should match the case of the input; the matchCase method may be helpful here.

Specified by:
getCorrections in class Corrector
Parameters:
wrong - the misspelled word. Assume any leading or trailing whitespace has already been removed.
Returns:
a (potentially empty) set of proposed corrections