Skip to content

Commit ee925da

Browse files
committed
Enhanced functionality of the Spellchecker addon
Added code to the spell checker to attempt to preserve the case of the spelling-corrected word when a spelling error is encountered. now when a misspelled word is found, that word's case is examined, and the script tries to match the case of the correction when performing the replacement. For example: missspelling becomes misspelling MISSSPELLING becomes MISSPELLING Missspelling becomes Misspelling MiSsspelling becomes misspelling Please note that the last example, where the misspelled word has mixed case beyond the first letter, leaves the corrected word as lower case. This is intentional, since case corrections fir such mixed case words would require "letter-by-letter" testing of the original word, and that's outside the intent of this enhancement.
1 parent af4fda0 commit ee925da

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

chatbot/addons/spell_checker/spell_checker.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,44 @@ function spell_check($word, $bot_id)
6262
}
6363
if (in_array($test_word, array_keys($_SESSION['spellcheck'])))
6464
{
65-
$corrected_word = $_SESSION['spellcheck'][$word];
65+
$corrected_word = $_SESSION['spellcheck'][$test_word];
6666
runDebug(__FILE__, __FUNCTION__, __LINE__, "Misspelling found! Replaced $word with $corrected_word.", 4);
6767
}
6868
else
6969
{
7070
runDebug(__FILE__, __FUNCTION__, __LINE__,'Spelling check passed.', 4);
7171
$corrected_word = $word;
7272
}
73+
if (IS_MB_ENABLED)
74+
{
75+
switch ($word){
76+
case mb_strtolower($word):
77+
$corrected_word = mb_strtolower($corrected_word);
78+
break;
79+
case mb_strtoupper($word):
80+
$corrected_word = mb_strtoupper($corrected_word);
81+
break;
82+
case mb_convert_case($word, MB_CASE_TITLE):
83+
$corrected_word = mb_convert_case($corrected_word, MB_CASE_TITLE);
84+
break;
85+
default:
86+
}
87+
}
88+
else
89+
{
90+
switch ($word){
91+
case strtolower($word):
92+
$corrected_word = strtolower($corrected_word);
93+
break;
94+
case strtoupper($word):
95+
$corrected_word = strtoupper($corrected_word);
96+
break;
97+
case ucfirst($word):
98+
$corrected_word = ucfirst($corrected_word);
99+
break;
100+
default:
101+
}
102+
}
73103
//set in global config file
74104
return $corrected_word;
75105
}

0 commit comments

Comments
 (0)