本文整理汇总了PHP中pspell_new函数的典型用法代码示例。如果您正苦于以下问题:PHP pspell_new函数的具体用法?PHP pspell_new怎么用?PHP pspell_new使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pspell_new函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pspell_new
/**
* Opens a link for pspell.
*/
function &_getPLink($lang) {
// Check for native PSpell support
if (!function_exists("pspell_new"))
$this->throwError("PSpell support not found in PHP installation.");
// Setup PSpell link
$plink = pspell_new(
$lang,
$this->_config['PSpell.spelling'],
$this->_config['PSpell.jargon'],
empty($this->_config['PSpell.encoding']) ? 'utf-8' : $this->_config['PSpell.encoding'],
$this->_config['PSpell.mode']
);
// Setup PSpell link
/* if (!$plink) {
$pspellConfig = pspell_config_create(
$lang,
$this->_config['PSpell.spelling'],
$this->_config['PSpell.jargon'],
$this->_config['PSpell.encoding']
);
$plink = pspell_new_config($pspell_config);
}*/
if (!$plink)
$this->throwError("No PSpell link found opened.");
return $plink;
}
示例2: __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);
}
示例3: get_pspell
public static function get_pspell()
{
if (!isset(self::$_pspell_instance)) {
self::$_pspell_instance = pspell_new('en');
}
return self::$_pspell_instance;
}
示例4: spellChecker
/**
* Constructor
*
* @param string $dict the dictionary (language) to use
* @param string $account the current users account name
*/
function spellChecker($dict, $account, $use_pspell = false)
{
global $atmail, $pref;
$this->personal_words = $atmail->db->sqlarray("select Word from SpellCheck where SUnique='0' and Account=?", $account);
$this->suggestions = array();
// check for availability of pspell functions
$this->use_pspell = $use_pspell && extension_loaded('pspell');
//function_exists('pspell_new');
// use pspell functions if they are available otherwise
// use the aspell binary directly
if ($this->use_pspell && function_exists('pspell_new')) {
$this->dict = pspell_new($dict, null, null, 'utf-8', PSPELL_FAST);
} else {
$dict = escapeshellarg($dict);
// Execute the aspell command and open file pointers for input/output
$descriptorspec = array(array("pipe", "r"), array("pipe", "w"));
$this->aspell_proc = proc_open("{$pref['aspell_path']} -a -l {$dict} --sug-mode=fast --encoding=utf-8", $descriptorspec, $pipes);
$this->aspell_input = $pipes[0];
$this->aspell_output = $pipes[1];
// remove version info from stream
$trash = fgets($this->aspell_output);
unset($trash);
}
if (!$atmail->isset_chk($_SESSION['spellcheck_ignore'])) {
$_SESSION['spellcheck_ignore'] = array();
}
}
示例5: 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);
}
示例6: getPspell
/**
* Returns pspell resource
* @return int
*/
protected function getPspell()
{
if ($this->pspell === null) {
$this->pspell = pspell_new($this->language, "", "", "UTF-8");
}
return $this->pspell;
}
示例7: 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;
}
示例8: 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;
}
示例9: configurePSpell
/**
* Set up custom PSpell dictionary.
*/
private function configurePSpell()
{
$this->pspellLink = pspell_new('en');
foreach ($this->config['spellcheck']['custom_words'] as $word) {
pspell_add_to_session($this->pspellLink, $word);
}
}
示例10: SpellCheck
function SpellCheck($text)
{
//depends on fnSpell()
// Extracts text from HTML code. In addition to normal word separators, HTML tags
// and HTML entities also function as word delimiters
$pspell_link = pspell_new("en_GB");
//0. Get the dictionary
$strings = explode(">", $text);
//1. Split $text on '>' to give us $strings with 0 or 1 HTML tags at the end
$nStrings = count($strings);
for ($cStrings = 0; $cStrings < $nStrings; $cStrings++) {
$string = $strings[$cStrings];
//2. For each string from 1
if ($string == '') {
continue;
}
$temp = explode('<', $string);
//2.1 Split $string from $strings on '>' to give us a $tag and $cdata
$tag = $temp[1];
$cdata = $temp[0];
$subCdatas = explode(";", $cdata);
//2.2 Split &cdata on ';' to give $subcdatas with 0 or 1 HTML entities on the end
$nSubCdatas = count($subCdatas);
//2.3 For each $subCdata from $subcdatas in 2.2
for ($cSubCdatas = 0; $cSubCdatas < $nSubCdatas; $cSubCdatas++) {
$subCdata = $subCdatas[$cSubCdatas];
if ($subCdata == '') {
continue;
}
$temp = explode('&', $subCdata);
//2.3.1 Split the $subCdata on '&' to give us a $subCdataEntity and a $subCdataWithNoEntities
$subCdataEntity = $temp[1];
$subCdataWithNoEntities = $temp[0];
$subCdataWithNoEntities = fnSpell($pspell_link, $subCdataWithNoEntities);
//2.3.2 Spellcheck the $cdataWithNoEntities
if (!$subCdataEntity) {
//2.3.3 Put the $subCdataEntity, a '&' and the $cdataWithNoEntities back into the $subCdata from 2.2
$subCdata = $subCdataWithNoEntities;
} else {
$subCdata = $subCdataWithNoEntities . '&' . $subCdataEntity . ';';
}
$subCdatas[$cSubCdatas] = $subCdata;
//2.3.4 Put the $subCdata back into the array of $subCdatas
}
$cdata = implode("", $subCdatas);
//2.4 Implode the array of $subCdatas back into the $cdata
if ($tag) {
//2.5 Put the $tag , '>' and $cdata back into $string
$string = $cdata . '<' . $tag . '>';
} else {
$string = $cdata;
}
$strings[$cStrings] = $string;
//2.6 Put $string back in its place in $strings
}
$text = implode('', $strings);
//3 Implode the $strings back into $text
return $text;
}
示例11: __construct
function __construct()
{
if (!function_exists('pspell_new')) {
$this->pspell_link = NULL;
} else {
$this->pspell_link = pspell_new($this->dict, "", "", "", PSPELL_FAST);
}
}
示例12: __construct
/**
* Constructor
*
* @see php://pspell_new
* @param string language
* @param string spelling
* @param string jargon
* @param string encoding
* @param int mode
* @throws lang.IllegalArgumentException
*/
public function __construct($language, $spelling = NULL, $jargon = NULL, $encoding = NULL, $mode = PSPELL_NORMAL)
{
if (FALSE === ($this->handle = pspell_new($language, $spelling, $jargon, $encoding, $mode))) {
$e = new IllegalArgumentException('Could not create spell checker');
xp::gc(__FILE__);
throw $e;
}
}
示例13: __construct
public function __construct($language, $input)
{
$this->language = $language;
$this->rawInput = $input;
$this->pspell = pspell_new($this->language, "", "", "utf-8");
// Set up config
//$this->loadReplacements();
}
示例14: testPspell
function testPspell($isocode)
{
if (function_exists('pspell_new') && @pspell_new($isocode)) {
return 1;
} else {
return 0;
}
}
示例15: misspellingsOnly
private function misspellingsOnly(array $arr)
{
$pspell = pspell_new("en", "", "", "", PSPELL_FAST | PSPELL_RUN_TOGETHER);
$miss = [];
foreach ($arr as $w) {
if (!pspell_check($pspell, $w)) {
$miss[] = $w;
}
}
return $miss;
}