Skip to content

Commit f33d411

Browse files
committed
Enhanced the functionality of the Spell Checker 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 for 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 f33d411

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
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
}

gui/jquery/index.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
$bot_id = (isset($_COOKIE['bot_id'])) ? $_COOKIE['bot_id'] : 1;
1414
setcookie('bot_id', $bot_id);
1515
$display = 'Make sure that you edit this file to change the value of $url below to reflect the correct address, and to remove this message.' . PHP_EOL;
16-
$display = '';
1716
$url = 'http://www.example.com/programo/chatbot/conversation_start.php';
18-
$url = 'http://localhost/Program-O/Program-O/chatbot/conversation_start.php';
1917

2018
function get_convo_id()
2119
{

0 commit comments

Comments
 (0)