Jump to content

Metaphone()


glenelkins

Recommended Posts

Hi

 

Im working on a spell checker. I have a dictionary of words though I could do with some advise on the metaphone() function. It returns the metaphone key of a word, but how does this help in spell checking?? I don't quite see how. Perhaps we need to run the miss-spelled word through, and compare its metaphone key with each word in the dictionary?

Link to comment
https://forums.phpfreaks.com/topic/38754-metaphone/
Share on other sites

here is a quick example of what I mean. Is this the way forward?

 

<?

/* VARS START */
$c=0;
$correct = false;
$test_word = "hello";
$dictionary = array ("hello","bye","yours","mine");
/* VARS END */

// Get the metephone key of the word to test					
$test_word_key = metaphone ( $test_word );

// Debug
//echo "The word $test_word has the following metaphone key: $test_word_key <br><br>";

// Check each dictionary value and take each
// metephone key value
foreach ( $dictionary as $var => $value ) {

// Debug
// echo "$var => $value <br>";

$dic[$c] = metaphone ( $value );

$c++;
}

// Test the word against all metephone keys
foreach ( $dic as $var => $value ) {

// Debug
//echo "$var => $value <br>";

if ( $value == $test_word_key ) {

	$correct = true;

}

}

// Display message
if ( $correct == true ) {

echo "The word $test_word is spelled correctly";

} else {

echo "The word $test_word is spelled incorrectly";

}

?>

Link to comment
https://forums.phpfreaks.com/topic/38754-metaphone/#findComment-186203
Share on other sites

If your just using a word list, then just put your dictionary in to an array, then put the words to check into an array, then use array_diff(), the returned array will give the words not found in the dictionary. Then use what SemiApocalyptic said on the words left in the array to build your suggestion list.

 

I have a really fast PHP spell checking class that uses a scripting based Perl hashing method that I can give you, when I get home tonight I will look for it. The class builds a complete spell checking interface, it can auto change words, ignore bbcode, html. It can handle any form element (div, inputs, ...) It doesn't use a database, everything is scripting based. Just give a word list (any language) and it will build a hash table that avoids using SOUNDEX, levenshtein because those methods work on phonetic similarities, which is really not what spell checking should do, because most spelling errors are typographically similar, not just phonetically similar, which all those formula are based on.

 

Quick Example of what you can do with the class...

 

http://66.31.240.158/spell.php

 

 

Link to comment
https://forums.phpfreaks.com/topic/38754-metaphone/#findComment-186328
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.