BryanA wrote:
Here is what I want to do. I want to be able to load a list of
correctly spelled words in and then the script will come up with
misspelled versions of that word and insert it into a mysql db. My
question is, where would I start?
Thanks,
Bryan
An algorithm such as the one used in:
http://www.norvig.com/spell-correct.html
can be re-written in php as in the following:
$word = "Spelling";
$word = strtolower($word);
$length = strlen($word);
// deletion
for ($i=0;$i<$length;$i++)
$variants[] = substr($word,0,$i) .
substr($word,$i+1,$length-$i-1);
// transposition
for ($i=0;$i<$length-1;$i++)
$variants[] = substr($word,0,$i) .
substr($word,$i+1,1) .
substr($word,$i,1) .
substr($word,$i+2,$length-$i-2);
// alteration
for ($i=0;$i<$length;$i++)
for ($c=ord('a'); $c <= ord('z'); $c++)
$variants[] = substr($word,0,$i) .
chr($c) .
substr($word,$i+1,$length-$i-1);
// insertion
for ($i=0;$i<$length+1;$i++)
for ($c=ord('a'); $c <= ord('z'); $c++)
$variants[] = substr($word,0,$i) .
chr($c) .
substr($word,$i,$length-$i);
// remove identical variants
foreach ($variants as $n =$variant)
if ($variant == $word)
unset($variants[$n]);
print_r($variants);
-Lee