本文整理汇总了PHP中pspell_new_config函数的典型用法代码示例。如果您正苦于以下问题:PHP pspell_new_config函数的具体用法?PHP pspell_new_config怎么用?PHP pspell_new_config使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pspell_new_config函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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());
}
}
示例2: __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);
}
}
示例3: 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);
}
示例4: 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');
}
示例5: 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);
}
}
示例6: 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;
}
示例7: 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 . '"';
}
}
示例8: 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;
}
示例9: 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;
}
示例10: 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";
}
}
}
示例11: 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);
}
示例12: split
}
$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}");
$formattedSuggestion = '';
foreach ($suggestions as $suggestion) {
$formattedSuggestion .= "<suggest>{$suggestion}</suggest>";
}
$ret .= "<suggestion><word>{$word}</word>" . $formattedSuggestion . "</suggestion>";
}
}
$xmlFile = "<spellcheck>" . $ret . "</spellcheck>";
#error_log($xmlFile);
print $xmlFile;
示例13: __construct
/**
* Konstrukor zapewniaj±cy ogóln± inicjalizacjê systemu przygotowywania danych:
* tokenizer, korekta ortograficzna, uzupe³nianie polskich znaków, wulgaryzmy.
*
* @param mysqli $dbconn Obiekt po³±czenia z baz± danych u¿ywany w podklasach.
* @param string $dictdir Folder ze s³ownikami, stoplistami itp.
* @param int $idc Identyfikator wykorzystywanego zestawu komentarzy.
* @param bool $copy_unknown Czy pozostawiaæ nierozpoznane wyrazy?
* @param array $options Parametry konkretnego klasyfikatora jako tab. asocjacyjna.
*/
function __construct($dbconn, $dictdir, $idc, $copy_unknown, $options = null)
{
$this->idc = $idc;
$this->copy_unknown = $copy_unknown;
$this->dbconn = $dbconn;
if (is_null(self::$validation)) {
self::$validation = new Validation($dictdir . '/vulgarism.txt');
}
if (is_null(self::$tokenizer)) {
self::$tokenizer = new Tokenizer($dictdir . '/stoplist.txt');
}
if (is_null(self::$fsaa)) {
self::$fsaa = new Fsaa($dictdir . '/lort_acc_full.fsa');
}
if (is_null(self::$fsal)) {
self::$fsal = new Fsal($dictdir . '/llems_full.fsa');
}
if (is_null(self::$pspell)) {
$pspell_config = pspell_config_create("pl");
// opcje zapewniaj±ce wiêksz± szybko¶æ dzia³ania aspell
pspell_config_ignore($pspell_config, 4);
pspell_config_mode($pspell_config, PSPELL_FAST);
pspell_config_runtogether($pspell_config, false);
self::$pspell = pspell_new_config($pspell_config);
}
}
示例14: parseStringP
function parseStringP($txt, $dialects)
{
global $errorstring, $parameters;
$dialect = "british";
if (isset($dialects[1]) && $dialects[1] != "") {
$dialect = $dialects[1];
$lang = $dialects[0];
}
//pspell parse initialisation
//$psp_conf = pspell_config_create ("en", $dialect);
$psp_conf = pspell_config_create($lang);
pspell_config_runtogether($psp_conf, false);
pspell_config_mode($psp_conf, PSPELL_NORMAL);
$psp = pspell_new_config($psp_conf);
//join the string so that it is easier to parse - does not matter when formatting because it is html
$txt = str_replace("\r\n", " ", $txt);
$txt = str_replace("\r", " ", $txt);
$txt = str_replace("\n", " ", $txt);
$jstext = "";
$jsarrindex = 0;
//split string by html tags
$regexp = "#(<[^>]*>)#";
$arr = preg_split($regexp, $txt, -1, PREG_SPLIT_OFFSET_CAPTURE | PREG_SPLIT_DELIM_CAPTURE);
foreach ($arr as $comp) {
$arr2[] = $comp[0];
}
//we now have the $arr2 - containing html tags and plain text portions
for ($i = 0; $i < count($arr2); $i++) {
$portion = $arr2[$i];
//the part
if (strstr($portion, "<a")) {
//we have a link
//$arr2[$i] = str_replace('href', 'href1', $arr2[$i]); //replace so when clicking on the content we do not redirect
}
if (!strstr($portion, "<") && $portion != "") {
//we do not work on html portions and empty text - which should be resolved in the preg_split function
$portion = str_replace(" ", " ", $portion);
//replace for parsing
//get distinct words from string portion
$words = explode(" ", $portion);
$arr2[$i] = $words;
for ($j = 0; $j < count($arr2[$i]); $j++) {
$word = $arr2[$i][$j];
//we check if the "word" is really a word
$cond = true;
//is it a link address ?
if (strstr($word, "http://")) {
$cond = false;
}
/*
//is it a number?
if (preg_match("/^[0-9\.%]*$/", $word)) {
$cond = false;
}
//does it begin with a capital letter ?
if (ucwords($word) == $word) {
//$cond = false;
}
*/
if ($cond) {
$regexp3 = "/([^a-zA-Z]*)([a-zA-Z']*)([^a-zA-Z]*)/";
//get the actual words - we can have strings like ",something.". We separate in 3 portions
preg_match($regexp3, $word, $mt);
$beforeword = $mt[1];
$inword = $mt[2];
if (addedWord($inword)) {
continue;
}
$afterword = $mt[3];
if (!pspell_check($psp, $inword)) {
$sugs = pspell_suggest($psp, $inword);
if (count($sugs) > 0) {
//build the option string
//$arr2[$i][$j] = $beforeword.'<span onclick="fillOptions(this)" options="'.implode('|', $sugs).'" class="havesuggestion">'.$inword.'</span>'.$afterword;
$arr2[$i][$j] = $beforeword . '<span badword=1>' . $inword . '</span>' . $afterword;
$jstext .= "\nwords[" . $jsarrindex . "] = new Object();";
$jstext .= "\nwords[" . $jsarrindex . "].status = 0;";
$jstext .= "\nwords[" . $jsarrindex . "].word = \"" . $word . "\";";
$jstext .= "\nwords[" . $jsarrindex . "].suggestions = new Array();";
$jsarrindex2 = 0;
foreach ($sugs as $suggestion) {
$jstext .= "\nwords[" . $jsarrindex . "].suggestions[" . $jsarrindex2 . "] = \"" . str_replace(array("\r", "\n"), array("", ""), $suggestion) . "\";";
$jsarrindex2++;
}
$jsarrindex++;
} else {
//build the option string with red so that we know there is no replacement
//$arr2[$i][$j] = $beforeword.'<span onclick="fillOptions(this)" options="'.implode('|', $sugs).'" class="nosuggestion">'.$inword.'</span>'.$afterword;
$arr2[$i][$j] = $beforeword . '<span badword=1>' . $inword . '</span>' . $afterword;
$jstext .= "\nwords[" . $jsarrindex . "] = new Object();";
$jstext .= "\nwords[" . $jsarrindex . "].status = 0;";
$jstext .= "\nwords[" . $jsarrindex . "].word = \"" . $word . "\";";
$jstext .= "\nwords[" . $jsarrindex . "].suggestions = new Array();";
$jsarrindex2 = 0;
foreach ($sugs as $suggestion) {
$jstext .= "\nwords[" . $jsarrindex . "].suggestions[" . $jsarrindex2 . "] = \"" . str_replace(array("\r", "\n"), array("", ""), $suggestion) . "\";";
$jsarrindex2++;
}
$jsarrindex++;
}
//.........这里部分代码省略.........
示例15: getLibrary
static function getLibrary()
{
global $IP;
$pspell_config = pspell_config_create("en", 'american');
pspell_config_mode($pspell_config, PSPELL_FAST);
//no longer using the custom dictionary
//pspell_config_personal($pspell_config, $IP . wikiHowDictionary::DICTIONARY_LOC);
$pspell_link = pspell_new_config($pspell_config);
return $pspell_link;
}