• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP pspell_suggest函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中pspell_suggest函数的典型用法代码示例。如果您正苦于以下问题:PHP pspell_suggest函数的具体用法?PHP pspell_suggest怎么用?PHP pspell_suggest使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了pspell_suggest函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: showSuggestions

function showSuggestions($word, $id)
{
    global $editablePersonalDict;
    //bool to set editability of personal dictionary
    global $allowCustomInserts;
    //bool to set the option to allow custom text inserts
    global $pspell_link;
    //the global link to the pspell module
    global $cp;
    //the CPAINT object
    $retVal = "";
    $suggestions = pspell_suggest($pspell_link, utf8_decode($word));
    //an array of all the suggestions that psepll returns for $word.
    // If the number of suggestions returned by pspell is less than the maximum
    // number, just use the number of suggestions returned.
    $numSuggestions = count($suggestions);
    $tmpNum = min($numSuggestions, MAX_SUGGESTIONS);
    if ($tmpNum > 0) {
        //this creates the table of suggestions.
        //in the onclick event it has a call to the replaceWord javascript function which does the actual replacing on the page
        for ($i = 0; $i < $tmpNum; $i++) {
            $retVal .= "<div class=\"suggestion\"  onmouseover=\"this.className='suggestion_hover'\" onmouseout=\"this.className='suggestion'\" onclick=\"replaceWord('" . addslashes_custom($id) . "', '" . addslashes($suggestions[$i]) . "'); return false;\">" . $suggestions[$i] . "</div>";
        }
        if ($allowCustomInserts) {
            $retVal .= "<div class=\"customInsert\" onmouseover=\"this.className='customInsert_hover'\" onmouseout=\"this.className='customInsert'\"><form name=\"custom_form\" style=\"margin:0px;\"><input type=\"text\" id=\"custom_form_box\" class=\"customInsertText\" onclick=\"get_id('custom_form_box').focus(); return false;\"><input type=\"button\" value=\"Insert\" class=\"customInsertAdd\" onclick=\"addWord('" . addslashes_custom($id) . "'); return false;\"></form></div>";
        }
        if ($editablePersonalDict) {
            $retVal .= "<div class=\"addtoDictionary\" onmouseover=\"this.className='addtoDictionary_hover'\" onmouseout=\"this.className='addtoDictionary'\" onclick=\"addWord('" . addslashes_custom($id) . "'); return false;\">Add To Dictionary</div>";
        }
    } else {
        $retVal .= "No Suggestions";
    }
    $cp->set_data($retVal);
    //the return value - a string containing the table of suggestions.
}
开发者ID:Navdeep736,项目名称:regetp01,代码行数:35,代码来源:spell_checker.php


示例2: spellingSuggestions

 /**
  * Suggestion of words coming from the pspell dictionnary in french and english
  *
  * @param string $q Query string
  * @param string $jsfunc The JS function to launch and pass the query string to
  */
 public function spellingSuggestions($q, $jsfunc = 'sugg')
 {
     $toret = '';
     if ($q == '') {
         return ' ... No suggestion possible, the query is empty ... ';
     }
     if (function_exists(pspell_new)) {
         $ss = 0;
         foreach (array('en' => 'English', "fr" => 'French') as $k => $v) {
             $pspellLink = pspell_new($k);
             $suggs = pspell_suggest($pspellLink, $q);
             if (count($suggs) > 0) {
                 $ss++;
                 $toret .= "<b>In " . $v . "</b> : ";
                 foreach ($suggs as $sug) {
                     $toret .= '<a href="javascript:' . $jsfunc . '(\'' . addslashes($sug) . '\')">' . htmlentities($sug) . '</a> &nbsp; ';
                 }
                 $toret .= "<br>";
             }
         }
         if ($ss == 0) {
             $toret .= '... we could not find anything in our dictionnaries ...';
         }
     } else {
         return ' !!! ERROR: the pspell module is not installed !!! ';
     }
     return $toret;
 }
开发者ID:Cryde,项目名称:sydney-core,代码行数:34,代码来源:SpellingSuggestions.php


示例3: check

 /**
  * Check a word for spelling errors, add to $this->miss_spelled_words
  * array if miss spelled
  *
  * @param string $word
  * @return void
  */
 function check($word)
 {
     global $atmail;
     $word = preg_replace('/[^a-zA-Z\\-]/', '', $word);
     // if the word is in the personal_words array
     // or the ignore list then it is OK. If it is already
     // in the $suggestions array then ignore it
     if (in_array($word, $this->personal_words) || $atmail->isset_chk($this->suggestions[$word]) || in_array($word, $_SESSION['spellcheck_ignore'])) {
         return;
     }
     // if word is OK ignore it
     if ($this->use_pspell) {
         if (pspell_check($this->dict, $word)) {
             return;
         }
         $this->suggestions[$word] = pspell_suggest($this->dict, $word);
     } else {
         fwrite($this->aspell_input, "{$word}\n");
         $result = fgets($this->aspell_output);
         // remove trash from stream
         $trash = fgets($this->aspell_output);
         unset($trash);
         if (preg_match('/.+?\\d:(.+)/', $result, $m)) {
             $this->suggestions[$word] = explode(', ', $m[1]);
         } else {
             return;
         }
     }
 }
开发者ID:BigBlueHat,项目名称:atmailopen,代码行数:36,代码来源:spellChecker.php


示例4: getSuggestions

function getSuggestions($word)
{
    global $editablePersonalDict;
    //bool to set editability of personal dictionary
    global $pspell_link;
    //the global link to the pspell module
    $retVal = "";
    //an array of all the suggestions that psepll returns for $word.
    $suggestions = pspell_suggest($pspell_link, $word);
    // If the number of suggestions returned by pspell is less than the maximum
    // number, just use the number of suggestions returned.
    $numSuggestions = count($suggestions);
    $tmpNum = min($numSuggestions, MAX_SUGGESTIONS);
    if ($tmpNum > 0) {
        //this creates the table of suggestions.
        for ($i = 0; $i < $tmpNum; $i++) {
            $retVal .= '<div class="suggestion">' . $suggestions[$i] . '</div>';
        }
        if ($editablePersonalDict) {
            $retVal .= '<div class="addToDictionary">Add To Dictionary</div>';
        }
    } else {
        $retVal .= "No Suggestions";
    }
    echo $retVal;
    //the return value - a string containing the table of suggestions.
}
开发者ID:jedbrundidge,项目名称:CarischCpm,代码行数:27,代码来源:spell_checker.php


示例5: pspell

 private function pspell()
 {
     foreach ($_REQUEST as $key => $value) {
         ${$key} = html_entity_decode(urldecode(stripslashes(trim($value))));
     }
     // load the dictionary
     $pspell_link = pspell_new_personal($this->pspell_personal_dictionary, $this->lang);
     // return suggestions
     if (isset($suggest)) {
         exit(json_encode(pspell_suggest($pspell_link, urldecode($suggest))));
     } elseif (isset($text)) {
         $words = array();
         foreach ($text = explode(' ', urldecode($text)) as $word) {
             if (!pspell_check($pspell_link, $word) and !in_array($word, $words)) {
                 $words[] = $word;
             }
         }
         exit(json_encode($words));
     } elseif (isset($addtodictionary)) {
         $pspell_config = pspell_config_create('en');
         @pspell_config_personal($pspell_config, $this->pspell_personal_dictionary) or die('can\'t find pspell dictionary');
         $pspell_link = pspell_new_config($pspell_config);
         @pspell_add_to_personal($pspell_link, strtolower($addtodictionary)) or die('You can\'t add a word to the dictionary that contains any punctuation.');
         pspell_save_wordlist($pspell_link);
         exit(array());
     }
 }
开发者ID:muratozden,项目名称:jquery-spellchecker,代码行数:27,代码来源:checkspelling.php


示例6: spellCheckWord

function spellCheckWord($word)
{
    global $pspell, $bad;
    $autocorrect = TRUE;
    $ignore_words = array("wikihows", "blog", "online", "ipod", "nano");
    // Take the string match from preg_replace_callback's array
    $word = $word[0];
    // Ignore ALL CAPS, and numbers
    if (preg_match('/^[A-Z]*$/', $word)) {
        return;
    }
    if (preg_match('/^[0-9]*$/', $word)) {
        return;
    }
    if (in_array(strtolower($word), $ignore_words)) {
        return;
    }
    // Return dictionary words
    if (pspell_check($pspell, $word)) {
        // this word is OK
        return;
    }
    echo "Bad word {$word} - ";
    $bad++;
    $suggestions = pspell_suggest($pspell, $word);
    if (sizeof($suggestions) > 0) {
        if (sizeof($suggestions) > 5) {
            echo implode(",", array_splice($suggestions, 0, 5)) . "\n";
        } else {
            echo implode(",", $suggestions) . "\n";
        }
    } else {
        echo "no suggestions\n";
    }
}
开发者ID:biribogos,项目名称:wikihow-src,代码行数:35,代码来源:aspell_demo.php


示例7: getSuggestion

 function getSuggestion($word)
 {
     if (!$this->plink) {
         $this->errorMsg[] = "No PSpell link found for getSuggestion.";
         return array();
     }
     return pspell_suggest($this->plink, $word);
 }
开发者ID:aydancoskun,项目名称:octobercms,代码行数:8,代码来源:TinyPspell.class.php


示例8: suggest

 /**
  * Use pspell to get word suggestions
  * @param string $word
  * @return array
  */
 public function suggest($word)
 {
     if (!pspell_check($this->pSpell, $word)) {
         return pspell_suggest($this->pSpell, $word);
     } else {
         return [$word];
     }
 }
开发者ID:WHATNEXTLIMITED,项目名称:php-text-analysis,代码行数:13,代码来源:PspellAdapter.php


示例9: suggest

 function suggest($mistake)
 {
     if ($mistake == FALSE) {
         $mistake = $this->lastword;
     }
     $suggest = pspell_suggest($this->resid, $mistake);
     return $suggest;
 }
开发者ID:BackupTheBerlios,项目名称:viscacha-svn,代码行数:8,代码来源:pspell.class.php


示例10: pspell_suggest

 /**
  * Returns suggestions of for a specific word.
  *
  * @param {String} $lang Language code like sv or en.
  * @param {String} $word Specific word to get suggestions for.
  * @return {Array} Array of suggestions for the specified word.
  */
 function &getSuggestions($lang, $word)
 {
     $words = pspell_suggest($this->_getPLink($lang), $word);
     for ($i = 0; $i < count($words); $i++) {
         $words[$i] = utf8_encode($words[$i]);
     }
     return $words;
 }
开发者ID:grff-alpha,项目名称:grff-alpha-web,代码行数:15,代码来源:PSpell.php


示例11: ewiki_spellcheck_list

function ewiki_spellcheck_list($ws)
{
    global $spell_bin, $pspell_h;
    #-- every word once only
    $words = array();
    foreach (array_unique($ws) as $word) {
        if (!empty($word)) {
            $words[] = $word;
        }
    }
    #print_r($words);
    #-- PHP internal pspell
    if ($pspell_h) {
        #-- build ispell like check list
        $results = array();
        foreach ($words as $w) {
            if (pspell_check($pspell_h, $w)) {
                $results[$word] = "*";
            } else {
                $results[$word] = "& " . implode(", ", pspell_suggest($pspell_h, $w));
            }
        }
    } elseif ($spell_bin) {
        #-- pipe word list through ispell
        $r = implode(" ", $words);
        $results = explode("\n", $r = `echo {$r} | {$spell_bin}`);
        $results = array_slice($results, 1);
    }
    #print_r($results);
    #-- build replacement html hash from results
    $r = array();
    foreach ($words as $n => $word) {
        if ($repl = $results[$n]) {
            switch ($repl[0]) {
                case "-":
                case "+":
                case "*":
                    $repl = $word;
                    break;
                default:
                    $repl = '<s title="' . htmlentities($repl) . '" style="color:#ff5555;" class="wrong">' . $word . '</s>';
            }
        } else {
            $repl = $word;
        }
        $r[$word] = $repl;
    }
    #print_r($r);
    return $r;
}
开发者ID:gpuenteallott,项目名称:rox,代码行数:50,代码来源:pspell.php


示例12: x

function x()
{
    $uncheckedDir = opendir('.');
    readdir($uncheckedDir);
    $uncheckedDir2 = bzopen('.');
    bzclose($uncheckedDir2);
    $uncheckedDir3 = fopen('.', 'r+');
    fclose($uncheckedDir3);
    readdir(opendir('uncheckedDir4'));
    readdir2(opendir('uncheckedDir5'));
    readdir(opendir2('uncheckedDir6'));
    $pspell_new = pspell_new('asdfasdf');
    while ($f = pspell_suggest($pspell_new)) {
        print "{$f}\n";
    }
}
开发者ID:exakat,项目名称:exakat,代码行数:16,代码来源:UncheckedResources.02.php


示例13: getCorrections

 public function getCorrections()
 {
     $wordMatcher = "/\\w+/u";
     preg_match_all($wordMatcher, $this->rawInput, $words);
     if (count($words[0]) == 0) {
         return array();
     }
     foreach ($words[0] as $k => $word) {
         if (!pspell_check($this->pspell, $word)) {
             $suggestions = pspell_suggest($this->pspell, $word);
             $this->corrections[$word]['offset'] = $k;
             $this->corrections[$word]['suggestions'] = $suggestions;
         }
     }
     return $this->corrections;
 }
开发者ID:mauriciogsc,项目名称:ATbarPT,代码行数:16,代码来源:pspell.class.php


示例14: check

function check($word)
{
    $pspell_config = pspell_config_create("ru", "", "", "UTF-8");
    pspell_config_mode($pspell_config, PSPELL_FAST);
    $pspell_link = pspell_new_config($pspell_config);
    if (!pspell_check($pspell_link, $word)) {
        $arr = array();
        $suggestions = pspell_suggest($pspell_link, $word);
        foreach ($suggestions as $suggestion) {
            array_push($arr, $suggestion);
        }
        $json = json_encode($arr);
    } else {
        $json = true;
    }
    echo $json;
}
开发者ID:m304so,项目名称:spellchecker,代码行数:17,代码来源:spellchecker.php


示例15: checkSpelling

 function checkSpelling($text)
 {
     $list = array();
     $this->checked = array();
     $words = $this->getWords($text);
     foreach ($words as $k => $w) {
         // don't check the same word twice
         if (isset($this->checked[$w])) {
             if (is_array($this->checked[$w])) {
                 $list[] = array('word' => $this->escape($w), 'offset' => $k, 'length' => strlen($w), 'suggestions' => $this->escape($this->checked[$w]));
             }
             continue;
         }
         // if it's in the personal dictionary, it's valid
         if ($this->checkPersonal($w)) {
             $this->checked[$w] = true;
             continue;
         }
         // if it's in the suggestions table, we can avoid pspell
         $sug = $this->checkSuggestions($w);
         // if it's an array, the word is incorrect
         if (is_array($sug)) {
             $list[] = array('word' => $this->escape($w), 'offset' => $k, 'length' => strlen($w), 'suggestions' => $this->escape($sug));
             $this->checked[$w] = $sug;
             continue;
             // if it's a boolean true, the word is correct
         } elseif ($sug === true) {
             $this->checked[$w] = true;
             continue;
         }
         // finally, we check with pspell...
         // if it comes up false, it's a mistake
         if (!pspell_check($this->pspell, $w)) {
             $sug = pspell_suggest($this->pspell, $w);
             $list[] = array('word' => $this->escape($w), 'offset' => $k, 'length' => strlen($w), 'suggestions' => $this->escape($sug));
             $this->addSuggestion($w, $sug);
             $this->checked[$w] = $sug;
             // the word is correct, let's have Xspel learn it
         } else {
             $this->addSuggestion($w);
             $this->checked[$w] = true;
         }
     }
     return $list;
 }
开发者ID:vojtajina,项目名称:sitellite,代码行数:45,代码来源:Xspel.php


示例16: getErrors

 function getErrors($text, $max = 10)
 {
     $separator = "!\$%^&*()-_=+{}[]\\|;:\",.?/\n\r|\t ";
     $errors = array('word' => array(), 'suggest' => array());
     $word = strtok($text, $separator);
     while ($word !== false) {
         if (!is_numeric($word) && !in_array($word, $errors['word']) && !pspell_check($this->link, $word)) {
             $errors['word'][] = $word;
             $suggests = pspell_suggest($this->link, $word);
             if (array_key_exists($max, $suggests)) {
                 array_splice($suggests, $max);
             }
             $errors['suggest'][] = $suggests;
         }
         $word = strtok($separator);
     }
     return $errors;
 }
开发者ID:pma-alpha-rho,项目名称:pma-alpha-rho.github.io,代码行数:18,代码来源:spell.php


示例17: onCommandSpell

 /**
  * Intercepts and handles requests for spell checks.
  *
  * @param string $word the string to perform checks against
  *
  * @return void
  */
 public function onCommandSpell($word)
 {
     $source = $this->event->getSource();
     $target = $this->event->getNick();
     $message = $target . ': The word "' . $word;
     $message .= '" seems to be spelled correctly.';
     if (!pspell_check($this->pspell, $word)) {
         $suggestions = pspell_suggest($this->pspell, $word);
         $message = $target;
         $message .= ': I could not find any suggestions for "' . $word . '".';
         if (!empty($suggestions)) {
             $suggestions = array_splice($suggestions, 0, $this->limit);
             $message = $target . ': Suggestions for "';
             $message .= $word . '": ' . implode(', ', $suggestions) . '.';
         }
     }
     $this->doPrivmsg($source, $message);
 }
开发者ID:hjr3,项目名称:phergie,代码行数:25,代码来源:SpellCheck.php


示例18: check

 function check($string)
 {
     if (is_null($this->pspell_link)) {
         return NULL;
     }
     $words = explode(' ', $string);
     $new_words = array();
     foreach ($words as $word) {
         if (!pspell_check($this->pspell_link, $word)) {
             $suggestions = pspell_suggest($this->pspell_link, $word);
             // get suggestions from pspell
             // for now simply use the first suggestion in the list
             if (count($suggestions) > 0) {
                 $has_hyphen = strpos($word, '-') !== FALSE;
                 $suggestion = $suggestions[0];
                 // look for a suggestion that is one word (not two as pspell sometimes does)
                 // also ignore suggestions with hyphens if the given word is not hyphenated
                 if (strpos($suggestion, ' ') !== FALSE || !$has_hyphen && strpos($suggestion, '-') !== FALSE) {
                     // only search through the first 20 suggestions
                     $count = min(20, count($suggestions));
                     for ($i = 1; $i < $count; $i++) {
                         if (strpos($suggestions[$i], ' ') === FALSE && $has_hyphen) {
                             $suggestion = $suggestions[$i];
                             break;
                         } else {
                             if (strpos($suggestions[$i], ' ') === FALSE && !$has_hyphen && strpos($suggestions[$i], '-') === FALSE) {
                                 $suggestion = $suggestions[$i];
                                 break;
                             }
                         }
                     }
                 }
                 $new_words[] = strtolower($suggestion);
             } else {
                 $new_words[] = $word;
             }
         } else {
             $new_words[] = $word;
         }
     }
     $suggestion = join(' ', $new_words);
     return $suggestion != $string ? $suggestion : '';
 }
开发者ID:bufvc,项目名称:bufvc-potnia-framework,代码行数:43,代码来源:SpellingCorrector.class.php


示例19: find_my_page

function find_my_page()
{
    // get the name of the 'missing' file
    $page = basename($_SERVER['REDIRECT_URL']);
    // used to pick the correct dictionary
    $dir = dirname($_SERVER['REDIRECT_URL']);
    $key = md5($dir);
    // load spelling dictionaries
    $ps = pspell_config_create("en");
    pspell_config_personal($ps, "./{$key}.pws");
    $pl = pspell_new_config($ps);
    // find alternatives
    $alt = pspell_suggest($pl, $page);
    if (!$alt) {
        // no matches, no choice but to show site map
        display_site_map();
        return;
    }
    // escape data for sqlite
    foreach ($alt as $key => $file) {
        $alt[$key] = sqlite_escape_string($file);
    }
    // fetch all matching pages;
    $db = new sqlite_db("./typos.sqlite");
    $alt = $db->single_query("SELECT url FROM typo WHERE key IN('" . implode("','", $alt) . "')");
    switch (@count($alt)) {
        case 1:
            // if only one suggestion is avaliable redirect the user to that page
            header("Location: {$alt[0]}");
            return;
            break;
        case 0:
            // no matches, no choice but to show site map
            display_site_map();
            break;
        default:
            // show the user possible alternatives if >1 is found
            echo "The page you requested, '{$_SERVER['REDIRECT_URL']}' cannot be found.<br />\nDid you mean:\n";
            foreach ($alt as $url) {
                echo "&nbsp;&nbsp;<a href='{$url}'>{$url}</a><br />\n";
            }
    }
}
开发者ID:SandyS1,项目名称:presentations,代码行数:43,代码来源:spelling.php


示例20: arrCheck

 public function arrCheck($words)
 {
     //find misspelled words
     foreach ($words as $word) {
         if (!pspell_check($this->speller, $word)) {
             $misspelled[] = $word;
         }
     }
     $suggestions = array();
     if (!empty($misspelled)) {
         // return contains a list of suggestions for each mispelled words
         foreach ($misspelled as $value) {
             // don't get suggestions for the same word twice
             if (!array_key_exists($value, $suggestions)) {
                 $suggestions[$value] = pspell_suggest($this->speller, $value);
             }
         }
     }
     return $suggestions;
 }
开发者ID:BackupTheBerlios,项目名称:shelveit-svn,代码行数:20,代码来源:Spellcheck.php



注:本文中的pspell_suggest函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP pt2pt函数代码示例发布时间:2022-05-15
下一篇:
PHP pspell_new_config函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap