a story problem to fix spelling mistakes
Fetching latest commit…
Cannot retrieve the latest commit at this time
Author: Joe Alonso Date: March 7, 2011 ================================================================================ Requirements: PHP 5.3.5 (cli) (built: Feb 11 2011 15:44:50) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans PHPUnit 3.5.12 by Sebastian Bergmann. loads default dictionary > /usr/share/dict/words ================================================================================= Usage: test: > phpunit --coverage-html ./coverage/ test/ run: > php ./src/run.php for the extra credit case: > php ./src/run.php -x code coverage can be seen here: /coverage/index.html ================================================================================= Assumptions: a dictionary exists at /usr/share/dict/words ================================================================================= Story: Write a program that reads a large list of English words (e.g. from /usr/share/dict/words on a unix system) into memory, and then reads words from stdin, and prints either the best spelling suggestion (based on the rules below), or "NO SUGGESTION" if no suggestion can be found. The program should print ">" as a prompt before reading each word, and should loop until killed. This is what an interactive session with your code should look like: > sheeeeep sheep > peepple people > sheeple NO SUGGESTION > Your code should correct the following three classes of spelling mistakes: * Case (upper/lower) errors: "inSIDE" => "inside" * Repeated letters: "jjoobbb" => "job" * Incorrect vowels: "weke" => "wake" Any combination of the above types of error in a single word should be corrected (e.g. "CUNsperrICY" => "conspiracy"). If there are many possible corrections of an input word, your program can choose one in any way you like. It just has to be an English word that is a spelling correction of the input by the above rules. Extra credit: Write a second program that *generates* words with spelling mistakes of the above form, starting with correctly spelled English words. Pipe its output into the first program and verify that there are no occurrences of "NO SUGGESTION" in the output.