function Test_Word($word_to_test) { global $DB_TableName, $Spell_Config; global $Spelling_DB; echo "<td>" . $word_to_test . "</td><td>"; $tr_word_to_test = Translate_Word($word_to_test); $word_metaphone = Word_Sound_Function($tr_word_to_test); echo $tr_word_to_test . "</td><td>" . $word_metaphone . "</td><td>"; if (DB_Check_Word($word_to_test)) { echo "Found."; } else { echo "NOT IN DB."; } echo "</td><td>"; $Good_Word_Array = DB_Get_Suggestions($word_metaphone, $word_to_test); $Count = count($Good_Word_Array); echo $Count . "</td></tr><tr><td>Suggestions:</td><td colspan=5>"; for ($i = 0; $i < $Count; $i++) { $Word = $Good_Word_Array[$i]; $TR_Fetched_Word = Translate_Word($Word); if ($i > 0) { echo ", "; } $Lev_Distance = levenshtein($tr_word_to_test, $TR_Fetched_Word); if ($Lev_Distance < $Spell_Config["Levenshtein_Distance"]) { echo "<b>"; } else { echo "("; } echo $Word; if ($Lev_Distance < $Spell_Config["Levenshtein_Distance"]) { echo "</b>"; } else { echo ")"; } } echo "</td></tr><tr><td colspan=6> </td>"; }
function Add_Word($word_to_add) { global $words_added, $words_processed, $safe_mode; $word_to_add = strtolower($word_to_add); if (DB_Check_Word($word_to_add)) { return false; } $tr_word_to_add = Translate_Word($word_to_add); $metacode = Word_Sound_Function($tr_word_to_add); DB_Add_Word($word_to_add, $metacode); $words_added++; }
function Do_Check_Word($word_to_check, $word_location) { global $DB_TablePrefix, $Spelling_DB, $DB_TableName; global $wc_count, $corrected_words, $bw_count, $lb_count, $lb_words; global $Spell_Config; global $Fixed_Words_Table, $Skipped_Words, $Document; $wc_count++; // Check Common Word List & SpellLearned List if (strpos($Skipped_Words, ',' . $word_to_check . ',') !== false) { return false; } // Check to see if we already spell checked this word if (isset($Fixed_Words_Table[$word_to_check])) { $word_length = strlen($word_to_check); $original_word_to_check = substr($Document, $word_location, $word_length); $corrected_words .= 'parent.Bad_Words[' . $bw_count . '] = new parent.Add_Word(' . $word_location . ',' . $word_length . ',"' . Language_Encode($original_word_to_check) . '"'; $corrected_words .= $Fixed_Words_Table[$word_to_check]; $corrected_words .= ');' . LINE_FEED; $bw_count++; return false; } // Search for word in Main table if (DB_Check_Word($word_to_check)) { $Skipped_Words .= $word_to_check . ','; return false; } // Drop ('s) or just (s) and see if we find a match $last_char = substr($word_to_check, -1); if ($Spell_Config['Enable_Drop_S_Support'] && $last_char == 's') { $last_char = substr($word_to_check, -2, 1); if ($last_char == '\'') { $tr_word_to_check = substr($word_to_check, 0, -2); } else { $tr_word_to_check = substr($word_to_check, 0, -1); } if (DB_Check_Word($tr_word_to_check)) { $Skipped_Words .= $word_to_check . ','; return false; } } // Word Not found -- now find matches $tr_word_to_check = Translate_Word($word_to_check); $word_sound = Word_Sound_Function($tr_word_to_check); $word_length = strlen($word_to_check); // Create The (Suggestions) Word List $original_word_to_check = substr($Document, $word_location, $word_length); // $original_word_to_check = $word_to_check; $corrected_words .= 'parent.Bad_Words[' . $bw_count . '] = new parent.Add_Word(' . $word_location . ',' . $word_length . ',"' . Language_Encode($original_word_to_check) . '"'; // Check Case if (strtolower($original_word_to_check) == $original_word_to_check) { $Word_Is_Case = 0; } else { if (strtoupper($original_word_to_check) == $original_word_to_check) { $Word_Is_Case = 1; } else { if ($original_word_to_check[0] == strtoupper($original_word_to_check[0])) { $Word_Is_Case = 2; } } } // Sorting of Words $Correct_Word_Array = array(); $Correct_Word_Tag = array(); for ($i = 0; $i < $Spell_Config['Levenshtein_Distance']; $i++) { $Correct_Word_Array[$i] = ''; $Correct_Word_Tag[$i] = 0; } // Add Bad word to Count $bw_count++; $Good_Word_Array = DB_Get_Suggestions($word_sound, $word_to_check); $Count = count($Good_Word_Array); $Corrected_Word_Count = 0; for ($i = 0; $i < $Count; $i++) { $TR_Fetched_Word = Translate_Word($Good_Word_Array[$i]); $Lev_Distance = levenshtein($tr_word_to_check, $TR_Fetched_Word); if ($Lev_Distance < $Spell_Config['Levenshtein_Distance']) { $Corrected_Word_Count++; if ($Word_Is_Case == 1) { $Good_Word_Array[$i] = strtoupper($Good_Word_Array[$i]); } else { if ($Word_Is_Case == 2) { $Good_Word_Array[$i] = ucfirst($Good_Word_Array[$i]); } } $Correct_Word_Array[$Lev_Distance] .= ',"' . $Good_Word_Array[$i] . '"'; } } // Off by One Searching if ($Spell_Config['Off_By_One_Search'] == 2 || $Spell_Config['Off_By_One_Search'] == 1 && $Corrected_Word_Count == 0) { $Good_Word_Array = DB_Get_OBO_Suggestions($word_to_check); $Count = count($Good_Word_Array); for ($i = 0; $i < $Count; $i++) { $TR_Fetched_Word = Translate_Word($Good_Word_Array[$i]); $Lev_Distance = levenshtein($tr_word_to_check, $TR_Fetched_Word); if ($Lev_Distance < $Spell_Config['Levenshtein_Distance']) { if ($Word_Is_Case == 1) { $Good_Word_Array[$i] = strtoupper($Good_Word_Array[$i]); } else { if ($Word_Is_Case == 2) { $Good_Word_Array[$i] = ucfirst($Good_Word_Array[$i]); } } $Correct_Word_Array[$Lev_Distance] .= ',"' . $Good_Word_Array[$i] . '"'; } } } // Add words to list $Corrected_Word_List = ''; for ($i = 0; $i < $Spell_Config['Levenshtein_Distance']; $i++) { $Corrected_Word_List .= $Correct_Word_Array[$i]; } $Corrected_Word_List = Language_Encode($Corrected_Word_List); $corrected_words .= $Corrected_Word_List . ');' . LINE_FEED; $Fixed_Words_Table[$word_to_check] = $Corrected_Word_List; return true; }