/** * SpellCorrector.java * * @author Jeff Ondich * @version 5/3/05 * * This main program uses the Dictionary class to create a primitive * spelling corrector. It takes two command line arguments: first, * the name a file consisting of one lower-case word per line, in * alphabetical order; and second, a file consisting of a list of * words to be spell-corrected. As I said, this is a very primitive * spelling corrector--punctuation will throw it off (for example, * the word "example" from the previous line would be accompanied by * its comma if this comment were the file to be corrected). * * This program is part of an exercise on profiling, and thus has * been left intentionally in a non-optimal state. */ import java.util.*; import java.io.*; public class SpellCorrector { public static void main( String[] args ) { if( args.length != 2 ) { System.err.println( "Usage: java SpellCorrector wordFile fileToCorrect" ); return; } Dictionary d = new Dictionary( args[0] ); try { Scanner in = new Scanner( new File( args[1] ) ); while( in.hasNext() ) { String s = in.next(); System.out.println( s + " --> " + d.getClosestMatch( s ) ); } } catch( IOException e ) { System.err.println( e.getMessage() ); } } }