PHP 类似于 Google 的 "Did you mean: " 的拼写检查和建议

PHP Spell Check and Suggestions Similar to Google's "Did you mean: "

我正在尝试使用与 Google 的 "Did you mean: " 类似的系统对用户查询应用拼写检查,使用 PHP。

有没有办法用插件或API做到这一点?如果没有,您有什么建议?

可能的简化代码?

API

<?php
    function checkSpelling($query) {
        //Boolean where false value means a word is spelt wrong in string
        return file_get_contents("http://foo.com/?q=$query");
    }

    function getSuggestions($query) {
        //data with suggestions for word
        return file_get_contents("http://foo.com/?q=$query");
    }

    if (!checkSpelling(foo)) {
        echo getSuggestions(foo);
    }
?>

插件

<?php
    require("plugin.php");

    //plugin functions similar to the functions above are defined already

    if (!checkSpelling(foo)) {
        echo getSuggestions(foo);
    }
?>

NOTE: Pspell is not an option because I have PHP 5.X.X and am unable to install it on the server.

NOTE: PHP Spell Check does not have the disired interface.

使用 Levenshtein Distance 将是我想到的第一个解决方案,我希望使用自动完成的混合方法,一个常见的拼写错误关键字集,然后 Levenshtein and/or SOUNDEX 会让你在您正在寻找的可用性范围内。是的,这是一个项目。

想到这样的事情的另一条建议是问问自己。 "What is it that I'm really trying to do?"

通常,成熟的 Google 级解决方案可能就像喷砂饼干一样,因为您的用例不是他们的。如果目标是以一种非常简单的方式让访问者 A 获得信息 B,那么有多种方法可以实现这一点,这可能更简单 and/or 对您来说更好,而不是尝试逐字逆向工程。