Case-insensitive PSpell spell checking?
-
05-10-2020 - |
سؤال
I'd like to use PHP's PSpell check function in my program. Is there an option somewhere for case-insensitive checking in pspell_check()
?
المحلول
I've found a way around the lack of an option for case insensitivity. PSpell's suggestion function seems to always return the correct capitalization of a mis-capitalized word as its first suggestion, so we can check for this if the initial spell check fails:
<?php
function pspell_icheck($dictionary_link, $word) {
return ( pspell_check($dictionary_link, $word) ||
strtolower(reset(pspell_suggest($dictionary_link, $word))) == strtolower($word) );
}
$dict = pspell_new('en');
$word = 'foo';
echo pspell_icheck($dict, $word);
?>
Works on PHP 5.3.2. Happy coding :)
نصائح أخرى
Try this patch http://code.google.com/p/patched-pspell/ . It enables you to set any options.
pspell_config_set($pspell_config, 'ignore-case', 'true');
There is an easy solution. Just do this:
$word = ucfirst($word); //Always capitalize to avoid case sensitive error
if (!pspell_check($dict, $word)) {
$suggestions = pspell_suggest($dictionary, $word);
}
لا تنتمي إلى StackOverflow