PSpell 拼写检查不区分大小写?

发布于 2024-09-12 17:53:40 字数 74 浏览 1 评论 0原文

我想在我的程序中使用 PHP 的 PSpell 检查功能。 pspell_check() 中是否有一个选项可以进行不区分大小写的检查?

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()?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浪荡不羁 2024-09-19 17:53:40

我找到了一种解决缺乏区分大小写选项的方法。 PSpell 的建议函数似乎总是返回大写错误的单词的正确大写作为其第一个建议,因此如果初始拼写检查失败,我们可以检查这一点:

<?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);

?>

适用于 PHP 5.3.2。快乐编码:)

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 :)

别闹i 2024-09-19 17:53:40

尝试此补丁http://code.google.com/p/patched-pspell/ .它使您能够设置任何选项。

pspell_config_set($pspell_config, 'ignore-case', 'true');

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');
空名 2024-09-19 17:53:40

有一个简单的解决方案。只需这样做:

$word = ucfirst($word); //Always capitalize to avoid case sensitive error
if (!pspell_check($dict, $word)) {
   $suggestions = pspell_suggest($dictionary, $word);
}

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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文