本文整理汇总了PHP中pspell_config_create函数的典型用法代码示例。如果您正苦于以下问题:PHP pspell_config_create函数的具体用法?PHP pspell_config_create怎么用?PHP pspell_config_create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pspell_config_create函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct($params)
{
$this->lang = (isset($params["lang"]) && $params["lang"] != '') ? $params["lang"] : 'en';
$this->skip_len = $params["skip_length"];
$this->pspell = (function_exists('pspell_config_create') && ($params["use_pspell"] == "Y"));
//$this->custom_spell = $params["use_custom_spell"] == "Y";
$this->custom_spell = false;
$this->pspell_mode = $params["mode"];
$this->dics_path = $this->checkDicPath();
$this->user_dics_path = $this->dics_path."/custom.pws";
$this->custom_dics_path = $this->dics_path.'/custom_dics/'.$this->lang.'_';
if($this->custom_spell)
{
$this->dic = array();
}
if ($this->pspell)
{
$pspell_config = pspell_config_create ($this->lang, null, null, 'utf-8');
pspell_config_ignore($pspell_config, $this->skip_len);
pspell_config_mode($pspell_config, $params["mode"]);
pspell_config_personal($pspell_config, $this->user_dics_path);
$this->pspell_link = pspell_new_config($pspell_config);
}
}
示例2: __construct
/**
* Creates a new Pspell spell checker
*
* @param string $language the language used by this spell checker. This
* should be a two-letter ISO 639 language code
* followed by an optional two digit ISO 3166
* country code separated by a dash or underscore.
* For example, 'en', 'en-CA' and 'en_CA' are
* valid languages.
* @param string $personal_wordlist optional. The filename of the personal
* wordlist for this spell checker. If not
* specified, no personal wordlist is
* used. The personal wordlist may contain
* spellings for words that are correct
* but are not in the regular dictionary.
*
* @throws NateGoSearchException if the Pspell extension is not available.
* @throws NateGoSearchtException if a dictionary in the specified language
* could not be loaded.
*/
public function __construct($language, $path_to_data = '', $repl_pairs = '', $personal_wordlist = '')
{
if (!extension_loaded('pspell')) {
throw new NateGoSearchException('The Pspell PHP extension is ' . 'required for NateGoSearchPSpellSpellChecker.');
}
$config = pspell_config_create($language, '', '', 'utf-8');
pspell_config_mode($config, PSPELL_FAST);
if ($path_to_data != '') {
pspell_config_data_dir($config, $path_to_data);
pspell_config_dict_dir($config, $path_to_data);
}
if ($repl_pairs != '') {
pspell_config_repl($config, $repl_pairs);
}
if ($personal_wordlist != '') {
pspell_config_personal($config, $personal_wordlist);
if (file_exists($personal_wordlist) && fileowner($personal_wordlist) == posix_getuid()) {
// update permissions (-rw-rw----)
chmod($personal_wordlist, 0666);
}
$this->personal_wordlist = $personal_wordlist;
}
$this->dictionary = pspell_new_config($config);
if ($this->dictionary === false) {
throw new NateGoSearchException(sprintf("Could not create Pspell dictionary with language '%s'.", $this->language));
}
$this->loadBlacklistedSuggestions();
}
示例3: 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());
}
}
示例4: pspellConfig
function pspellConfig()
{
$pspell_config = pspell_config_create($this->lang);
pspell_config_ignore($pspell_config, $this->skip_len);
pspell_config_mode($pspell_config, $this->mode);
pspell_config_personal($pspell_config, $this->personal_path);
$this->pspell_link = pspell_new_config($pspell_config);
}
示例5: add_to_dictionary
public function add_to_dictionary()
{
$pspell_config = pspell_config_create('en');
pspell_config_personal($pspell_config, $this->pspell_personal_dictionary) or die('can\'t find pspell dictionary');
$this->pspell_link = pspell_new_config($pspell_config);
pspell_add_to_personal($this->pspell_link, strtolower($addtodictionary)) or die('You can\'t add a word to the dictionary that contains any punctuation.');
pspell_save_wordlist($this->pspell_link);
$this->send_data('success');
}
示例6: loadReplacements
private function loadReplacements()
{
$path = $this->language_path . $this->language . ".repl";
if (file_exists($path)) {
//echo file_get_contents($path);
$this->pspell_config = pspell_config_create($this->language);
pspell_config_repl($this->pspell_config, $path);
$this->pspell = pspell_new_config($this->pspell_config);
}
}
示例7: pspell_config_create
/**
* 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.");
}
$pspell_config = pspell_config_create($lang, $this->_config['PSpell.spelling'], $this->_config['PSpell.jargon'], $this->_config['PSpell.encoding']);
pspell_config_personal($pspell_config, $this->_config['PSpell.dictionary']);
$plink = pspell_new_config($pspell_config);
if (!$plink) {
$this->throwError("No PSpell link found opened.");
}
return $plink;
}
示例8: init
function init()
{
$link = pspell_config_create($this->langcode);
pspell_config_ignore($link, $this->ignore);
if ($this->modus == 0) {
pspell_config_mode($link, PSPELL_FAST);
} elseif ($this->modus == 2) {
pspell_config_mode($link, PSPELL_BAD_SPELLERS);
} else {
pspell_config_mode($link, PSPELL_NORMAL);
}
$this->resid = @pspell_new_config($link);
if (!$this->resid) {
$this->errormsg = 'Could not open dictionary "' . $this->langcode . '"';
}
}
示例9: 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;
}
示例10: GetSpellSuggestionsWithPspell
public static function GetSpellSuggestionsWithPspell($strText, $strSpellLang)
{
if (!function_exists('pspell_new')) {
return true;
}
if (file_exists(__DICTIONARY_PATH__ . '/' . $strSpellLang . '.dat')) {
if (!defined('PSPELL_FAST')) {
return self::GetSpellSuggestionsWithHunspell($strText, $strSpellLang);
}
if (!($pspell_config = pspell_config_create($strSpellLang, null, null, 'utf-8'))) {
return self::GetSpellSuggestionsWithHunspell($strText, $strSpellLang);
}
if (!pspell_config_data_dir($pspell_config, __DICTIONARY_PATH__)) {
return self::GetSpellSuggestionsWithHunspell($strText, $strSpellLang);
}
if (!pspell_config_dict_dir($pspell_config, __DICTIONARY_PATH__)) {
return self::GetSpellSuggestionsWithHunspell($strText, $strSpellLang);
}
if (!($pspell_link = @pspell_new_config($pspell_config))) {
return self::GetSpellSuggestionsWithHunspell($strText, $strSpellLang);
}
} else {
if (file_exists('/usr/lib/aspell-0.60/' . $strSpellLang . '.dat')) {
$strDictPath = '/usr/lib/aspell-0.60/';
$pspell_link = pspell_new($strSpellLang, null, null, 'utf-8');
} elseif (file_exists('/usr/lib64/aspell-0.60/' . $strSpellLang . '.dat')) {
$strDictPath = '/usr/lib64/aspell-0.60/';
$pspell_link = pspell_new($strSpellLang, null, null, 'utf-8');
} else {
return self::GetSpellSuggestionsWithHunspell($strText, $strSpellLang);
}
}
$arrSuggestions = array();
$arrCleanText = mb_split('\\s+', $strText);
foreach ($arrCleanText as $strCleanText) {
if (!pspell_check($pspell_link, trim($strCleanText))) {
$suggestions = pspell_suggest($pspell_link, trim($strCleanText));
if (in_array($strCleanText, $suggestions)) {
continue;
}
$arrSuggestions[$strCleanText] = array_slice($suggestions, 0, 3);
}
}
return $arrSuggestions;
}
示例11: 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 " <a href='{$url}'>{$url}</a><br />\n";
}
}
}
示例12: preg_split
$found_misspell=false;
$words=array();
$htmlitems = preg_split('/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/',$fieldtext);//"
foreach($htmlitems as $item) {
if(strpos($item, "<")===false) {
$wordarray=preg_split('/[\W]+?/', $item);
foreach($wordarray as $worditem) {
if($worditem!=""&&$worditem!=" "&&$worditem!="nbsp")
$words[]=$worditem;
}
}
}
$pspell_config = pspell_config_create("en");
pspell_config_personal($pspell_config, "./dict/".$user_dictionary_file);
$int = pspell_new_config($pspell_config);
if($_POST['dictadd']!="") {
pspell_add_to_personal($int, $_POST['dictadd']);
pspell_save_wordlist($int);
}
for($i=$start;$i<count($words);$i++) {
$currentword=$words[$i];
if(strlen(trim($words[$i]))>2) {
if (!pspell_check($int, $currentword)) {
$suggestions = pspell_suggest($int, $currentword);
$found_misspell=true;
示例13: init_spell
function init_spell($type, $dict)
{
$pspell_config = pspell_config_create($dict);
pspell_config_mode($pspell_config, $type);
pspell_config_personal($pspell_config, $GLOBALS['FORUM_SETTINGS_PATH'] . "forum.pws");
pspell_config_ignore($pspell_config, 2);
define('__FUD_PSPELL_LINK__', pspell_new_config($pspell_config));
return true;
}
示例14: aspell_init
//.........这里部分代码省略.........
$aspell_args = '-a --lang=' . _filter_naughty_harsh($lang);
if (DIRECTORY_SEPARATOR == '\\') {
// See if there is a local install of aspell here
if (file_exists(dirname(__FILE__) . '\\aspell\\bin\\aspell.exe')) {
$aspell = dirname(__FILE__) . '\\aspell\\bin\\aspell.exe';
if (file_exists(dirname(__FILE__) . '\\aspell\\bin\\aspell_wrap.exe')) {
$aspell = dirname(__FILE__) . '\\aspell\\bin\\aspell_wrap.exe ' . dirname(__FILE__) . '\\aspell\\bin\\';
}
//$dic_dir=wrap_exec($aspell.' config dict-dir');
//$dicfil=preg_replace('/^.*\/lib\/(aspell\S*)\n.*/s','$1',$dic_dir);
//$aspell_args.=' --dict-dir='.$dicfil;
} else {
$aspell = 'C:\\Progra~1\\Aspell\\bin\\aspell.exe';
}
if (!file_exists($aspell)) {
exit('ASpell not installed in default locations.');
}
$aspell_version = wrap_exec($aspell . ' version');
} else {
// See if there is a local install of aspell here
if (file_exists(dirname(__FILE__) . '/aspell/bin/aspell')) {
putenv('PATH=' . dirname(__FILE__) . '/aspell/bin:' . getenv('PATH'));
putenv('LD_LIBRARY_PATH=' . dirname(__FILE__) . '/aspell/lib:' . getenv('LD_LIBRARY_PATH'));
//$dic_dir=wrap_exec($aspell.' config dict-dir');
//$dicfil=dirname(__FILE__).'/aspell/lib/'.preg_replace('/^.*\/lib\/(aspell\S*)\n.*/s','$1',$dic_dir);
//$aspell_args.=' --dict-dir='.$dicfil.' --add-filter-path='.$dicfil;
}
$aspell_version = wrap_exec($aspell . ' version');
}
if ($aspell_version === false) {
exit('ASpell would not execute. It is most likely not installed, or a security measure is in place, or file permissions are not correctly set. If on Windows, you may need to give windows\\system32\\cmd.exe execute permissions to the web user.');
}
// Old aspell doesn't know about encoding, which means that unicode will be broke, but we should at least let it try.
$a_ver = array();
preg_match('/really [aA]spell ([0-9]+)\\.([0-9]+)(?:\\.([0-9]+))?/i', $aspell_version, $a_ver);
if (!array_key_exists(1, $a_ver)) {
$a_ver[1] = '1';
}
if (!array_key_exists(2, $a_ver)) {
$a_ver[2] = '0';
}
if (!array_key_exists(3, $a_ver)) {
$a_ver[3] = '0';
}
$a_ver = array('major' => (int) $a_ver[1], 'minor' => (int) $a_ver[2], 'release' => (int) $a_ver[3]);
if ($a_ver['major'] >= 0 && $a_ver['minor'] >= 60) {
$aspell_args .= ' -H --encoding=utf-8';
} elseif (preg_match('/--encoding/', wrap_exec($aspell . ' 2>&1')) != 0) {
$aspell_args .= ' --mode=none --add-filter=sgml --encoding=utf-8';
} else {
$aspell_args .= ' --mode=none --add-filter=sgml';
}
$aspelldictionaries = $aspell . ' dump dicts';
$aspellcommand = $aspell . ' ' . $aspell_args . ' < ' . $temptext;
} else {
//list($lang,$spelling)=explode('_',$lang);
$spelling = '';
$temptext = NULL;
$aspelldictionaries = NULL;
}
// Personal dictionaries
global $SITE_INFO;
if (!isset($SITE_INFO)) {
require_once '../../../../info.php';
}
$cookie_member_id = $SITE_INFO['user_cookie'];
$p_dicts_name = array_key_exists($cookie_member_id, $_COOKIE) ? _filter_naughty_harsh($_COOKIE[$cookie_member_id]) : 'guest';
$p_dict_path = get_custom_file_base() . '/data_custom/spelling/personal_dicts' . DIRECTORY_SEPARATOR . $p_dicts_name;
if (!file_exists($p_dict_path)) {
mkdir($p_dict_path, 02770);
}
if (is_null($temptext)) {
list($lang_stub, ) = explode('_', $lang);
$charset = str_replace('ISO-', 'iso', str_replace('iso-', 'iso', do_lang('charset')));
if (DIRECTORY_SEPARATOR == '\\') {
$aspellcommand = @pspell_new_personal($p_dict_path . '/' . $lang_stub . '.pws', $lang, $spelling, '', $charset);
if ($aspellcommand === false) {
$aspellcommand = pspell_new_personal($p_dict_path . '/' . $lang_stub . '.pws', $lang, $spelling, '', $charset);
}
} else {
$aspellconfig = @pspell_config_create($lang, $spelling, '', $charset);
if ($aspellconfig === false) {
$aspellconfig = pspell_config_create('en', $spelling, '', $charset);
}
pspell_config_personal($aspellconfig, $p_dict_path . '/' . $lang_stub . '.pws');
pspell_config_repl($aspellconfig, $p_dict_path . '/' . $lang_stub . '.prepl');
$aspellcommand = @pspell_new_config($aspellconfig);
if ($aspellcommand === false && $lang != 'en') {
$aspellconfig = pspell_config_create('en', $spelling, '', $charset);
pspell_config_personal($aspellconfig, $p_dict_path . '/' . $lang_stub . '.pws');
pspell_config_repl($aspellconfig, $p_dict_path . '/' . $lang_stub . '.prepl');
$aspellcommand = pspell_new_config($aspellconfig);
}
}
if (is_null($aspellcommand)) {
exit;
}
}
return array($aspelldictionaries, $aspellcommand, $temptext, $lang);
}
示例15: chdir
chdir($mycwd);
# define( 'MEDIAWIKI', true );
# include_once("../../LocalSettings.php");
header('Content-Type: text/xml');
if (isset($_POST["document"])) {
$document = $_POST["document"];
}
# error_log(print_r($_POST, true));
if (get_magic_quotes_gpc()) {
$document = stripslashes($document);
}
$words = split(" ", $document);
# myLog(" *** user: " . $wgUser->getName());
# myLog(" *** language: " . $wgUser->getOption( 'language' ));
$spellcheckext_language = "" . $wgUser->getOption('language');
$pspell_config = pspell_config_create($spellcheckext_language);
global $personalDictionaryLocation, $pspell_data_dir, $pspell_dict_dir;
pspell_config_personal($pspell_config, $personalDictionaryLocation . "_" . $spellcheckext_language);
if (strcmp($pspell_data_dir, "") != 0) {
pspell_config_data_dir($pspell_config, $pspell_data_dir);
error_log("setting the spellcheck data dir to " . $pspell_data_dir);
}
if (strcmp($pspell_dict_dir, "") != 0) {
pspell_config_dict_dir($pspell_config, $pspell_dict_dir);
}
$pspell_link = pspell_new_config($pspell_config);
$words = array_unique($words);
$ret = "";
foreach ($words as $word) {
if (!is_numeric($word) && !pspell_check($pspell_link, $word)) {
$suggestions = pspell_suggest($pspell_link, "{$word}");