本文整理汇总了PHP中pspell_check函数的典型用法代码示例。如果您正苦于以下问题:PHP pspell_check函数的具体用法?PHP pspell_check怎么用?PHP pspell_check使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pspell_check函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: check
function check($word)
{
//pspell
if ($this->pspell) {
if ($this->lang == 'ru') {
$word = convertCharsetInKOI8($word);
}
return pspell_check($this->pspell_link, $word);
//custom
} elseif ($this->custom_spell) {
if ($this->lang == 'ru') {
$word = convertCharsetInWIN1251($word);
}
if (strlen($word) <= $this->skip_len) {
return true;
}
$first_let = $this->codeLetter(string_lower($word[0]));
if (!isset($this->dic[$first_let])) {
$this->loadDic($first_let);
}
//check if word exist in array
if (isset($this->dic[$first_let][string_lower($word)])) {
return true;
}
return false;
}
}
示例2: obtainData
function obtainData($objDb, $id)
{
$aRes = $objDb->GetDetails($id);
$sText = $objDb->GetRawText($id);
if ($aRes === FALSE || $sText === FALSE) {
// No such record!
return FALSE;
}
// Clean up list of words
$aWords = array_filter(array_unique(str_word_count($sText, 1)), "filter_words");
// Split words into likely and unlikely (based on spelling)
$aLikely = array();
$aUnlikely = array();
$hSpell = pspell_new("en");
if ($hSpell !== FALSE) {
foreach ($aWords as $sWord) {
// Make a spellcheck on it
if (pspell_check($hSpell, $sWord)) {
array_push($aLikely, $sWord);
} else {
array_push($aUnlikely, $sWord);
}
}
} else {
$aLikely = $aWords;
}
return array("likely" => $aLikely, "unlikely" => $aUnlikely);
}
示例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: __invoke
/**
* Checks spelling.
*
* @since 150424 Adding password strength.
*
* @param string $word Input word to check.
* @param int $flags Dictionary flags.
*
* @return bool True if spelled correctly.
*/
public function __invoke(string $word, int $flags = PSPELL_NORMAL) : bool
{
if (is_null($dictionary =& $this->cacheKey(__FUNCTION__, $flags))) {
$dictionary = pspell_new('en', '', '', 'utf-8', $flags);
}
return pspell_check($dictionary, $word);
}
示例5: 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";
}
}
示例6: getSuggestions
/**
* Spellchecks an array of words.
*
* @param String $lang Selected language code (like en_US or de_DE). Shortcodes like "en" and "de" work with enchant >= 1.4.1
* @param Array $words Array of words to check.
* @return Name/value object with arrays of suggestions.
*/
public function getSuggestions($lang, $words)
{
$config = $this->getConfig();
switch ($config['PSpell.mode']) {
case "fast":
$mode = PSPELL_FAST;
break;
case "slow":
$mode = PSPELL_SLOW;
break;
default:
$mode = PSPELL_NORMAL;
}
// Setup PSpell link
$plink = pspell_new($lang, $config['pspell.spelling'], $config['pspell.jargon'], $config['pspell.encoding'], $mode);
if (!$plink) {
throw new Exception("No PSpell link found opened.");
}
$outWords = array();
foreach ($words as $word) {
if (!pspell_check($plink, trim($word))) {
$outWords[] = utf8_encode($word);
}
}
return $outWords;
}
示例7: check
function check($word)
{
$word = trim($word);
$ret = pspell_check($this->resid, $word);
$this->lastword = $word;
return $ret;
}
示例8: 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());
}
}
示例9: checkWord
public function checkWord($word)
{
//pspell
if ($this->pspell) {
return pspell_check($this->pspell_link, $word);
}
//custom
// elseif($this->custom_spell)
// {
// if ($this->lang == 'ru')
// {
// $word = $APPLICATION->ConvertCharset($word, "UTF-8", "Windows-1251");
// }
//
// if (strlen($word) <= $this->skip_len)
// {
// return true;
// }
//
// $first_let = $this->codeLetter(strtolower($word{0}));
//
// if (!isset($this->dic[$first_let]))
// {
// $this->loadDic($first_let);
// }
// //check if word exist in array
// if (isset($this->dic[$first_let][strtolower($word)]))
// {
// return true;
// }
// return false;
// }
}
示例10: 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];
}
}
示例11: valid
/**
* Validates word first in cache then in pspell
* @param string $word
* @return boolean
*/
public function valid($word)
{
$wordLower = mb_strtolower($word, 'UTF-8');
$this->parseCache();
if (!isset($this->words[$wordLower])) {
$this->words[$wordLower] = pspell_check($this->getPspell(), $word);
}
return $this->words[$wordLower];
}
示例12: check
/**
* Checks a word against the dictionary.
*
* @param boolean Returns true if word is in dictionary, false if not.
*/
public function check($word) {
$this->word = $word;
if ($this->handle !== false && pspell_check($this->handle, $word) == true) {
return true;
}
else {
return false;
}
}
示例13: array
/**
* Spellchecks an array of words.
*
* @param {String} $lang Language code like sv or en.
* @param {Array} $words Array of words to spellcheck.
* @return {Array} Array of misspelled words.
*/
function &checkWords($lang, $words)
{
$plink = $this->_getPLink($lang);
$outWords = array();
foreach ($words as $word) {
if (!pspell_check($plink, trim($word))) {
$outWords[] = utf8_encode($word);
}
}
return $outWords;
}
示例14: check
function check($data)
{
$recognized = array();
if (is_string($data)) {
$data = array($data);
}
foreach ($data as $word) {
if (pspell_check($this->_ps, $word)) {
$recognized[] = $word;
}
}
return $recognized;
}
示例15: 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;
}