本文整理汇总了PHP中pspell_suggest函数的典型用法代码示例。如果您正苦于以下问题:PHP pspell_suggest函数的具体用法?PHP pspell_suggest怎么用?PHP pspell_suggest使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pspell_suggest函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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.
}
示例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> ';
}
$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;
}
示例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;
}
}
}
示例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.
}
示例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());
}
}
示例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";
}
}
示例7: getSuggestion
function getSuggestion($word)
{
if (!$this->plink) {
$this->errorMsg[] = "No PSpell link found for getSuggestion.";
return array();
}
return pspell_suggest($this->plink, $word);
}
示例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];
}
}
示例9: suggest
function suggest($mistake)
{
if ($mistake == FALSE) {
$mistake = $this->lastword;
}
$suggest = pspell_suggest($this->resid, $mistake);
return $suggest;
}
示例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;
}
示例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;
}
示例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";
}
}
示例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;
}
示例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;
}
示例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;
}