本文整理汇总了PHP中enchant_broker_init函数的典型用法代码示例。如果您正苦于以下问题:PHP enchant_broker_init函数的具体用法?PHP enchant_broker_init怎么用?PHP enchant_broker_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了enchant_broker_init函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: bench_enchant
function bench_enchant($words)
{
// TODO: check return values!!!
echo "Bench Enchant: ";
$tag = 'ru_RU';
$r = enchant_broker_init();
if (!enchant_broker_dict_exists($r, $tag)) {
echo "{$tag} dict not supported by enchant\n";
return false;
}
$d = enchant_broker_request_dict($r, $tag);
$not_found = 0;
$b = microtime(true);
foreach ($words as $word) {
// if(false === enchant_dict_quick_check($d, $word/*, $sugg*/)) { // this cause segfault
if (false === enchant_dict_check($d, $word)) {
enchant_dict_suggest($d, $word);
$not_found++;
}
}
$e = microtime(true);
printf("time = %0.2f sec, words per second = %0.2f, not found = %d\n", $e - $b, count($words) / ($e - $b), $not_found);
enchant_broker_free_dict($d);
enchant_broker_free($r);
}
开发者ID:Garcy111,项目名称:Garcy-Framework-2,代码行数:25,代码来源:bench.php
示例2: 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)
{
$suggestions = array();
$enchant = enchant_broker_init();
$config = $this->getConfig();
if (isset($config["enchant_dicts_path"])) {
enchant_broker_set_dict_path($enchant, ENCHANT_MYSPELL, $config["enchant_dicts_path"]);
enchant_broker_set_dict_path($enchant, ENCHANT_ISPELL, $config["enchant_dicts_path"]);
}
if (!enchant_broker_describe($enchant)) {
throw new Exception("Enchant spellchecker not find any backends.");
}
$lang = $this->normalizeLangCode($enchant, $lang);
if (enchant_broker_dict_exists($enchant, $lang)) {
$dict = enchant_broker_request_dict($enchant, $lang);
foreach ($words as $word) {
if (!enchant_dict_check($dict, $word)) {
$suggs = enchant_dict_suggest($dict, $word);
if (!is_array($suggs)) {
$suggs = array();
}
$suggestions[$word] = $suggs;
}
}
enchant_broker_free_dict($dict);
enchant_broker_free($enchant);
} else {
enchant_broker_free($enchant);
throw new Exception("Enchant spellchecker could not find dictionary for language: " . $lang);
}
return $suggestions;
}
开发者ID:Ariflaw,项目名称:b2evolution,代码行数:39,代码来源:EnchantEngine.php
示例3: __construct
public function __construct($config = array())
{
parent::__construct($config);
if (!function_exists('enchant_broker_init')) {
exit('Enchant library not found');
}
$this->broker = enchant_broker_init();
$this->dictionary = enchant_broker_request_dict($this->broker, $this->_config['lang']);
if (!enchant_broker_dict_exists($this->broker, $this->_config['lang'])) {
exit('Enchant dictionary not found for lang: ' . $this->_config['lang']);
}
}
开发者ID:antoniorodrigues,项目名称:redes-digitais,代码行数:12,代码来源:Enchant.php
示例4: enchant_broker_init
/**
* Returns suggestions for a specific word.
*
* @param String $lang Selected language code (like en_US or de_DE). Shortcodes like "en" and "de" work with enchant >= 1.4.1
* @param String $word Specific word to get suggestions for.
* @return Array of suggestions for the specified word.
*/
function &getSuggestions($lang, $word)
{
$r = enchant_broker_init();
$suggs = array();
if (enchant_broker_dict_exists($r, $lang)) {
$d = enchant_broker_request_dict($r, $lang);
$suggs = enchant_dict_suggest($d, $word);
enchant_broker_free_dict($d);
} else {
}
enchant_broker_free($r);
return $suggs;
}
开发者ID:01J,项目名称:bealtine,代码行数:20,代码来源:enchantspell.php
示例5: enchant_broker_init
/**
* Returns suggestions for a specific word.
*
* @param String $lang Selected language code (like en_US or de_DE). Shortcodes like "en" and "de" work with enchant >= 1.4.1
* @param String $word Specific word to get suggestions for.
* @return Array of suggestions for the specified word.
*/
function &getSuggestions($lang, $word)
{
$r = enchant_broker_init();
$suggs = array();
if (enchant_broker_dict_exists($r, $lang)) {
$d = enchant_broker_request_dict($r, $lang);
$suggs = enchant_dict_suggest($d, $word);
enchant_broker_free_dict($d);
} else {
$this->throwError("Language not installed");
}
enchant_broker_free($r);
return $suggs;
}
开发者ID:jguilloux71,项目名称:crok-notes,代码行数:21,代码来源:enchantspell.php
示例6: init
/**
* Initializes Enchant dictionary
*/
private function init()
{
if (!$this->enchant_broker) {
if (!extension_loaded('enchant')) {
$this->error = "Enchant extension not available";
return;
}
$this->enchant_broker = enchant_broker_init();
}
if (!enchant_broker_dict_exists($this->enchant_broker, $this->lang)) {
$this->error = "Unable to load dictionary for selected language using Enchant";
return;
}
$this->enchant_dictionary = enchant_broker_request_dict($this->enchant_broker, $this->lang);
}
开发者ID:Bergdahls,项目名称:YetiForceCRM,代码行数:18,代码来源:rcube_spellcheck_enchant.php
示例7: enchant_broker_init
/**
* Returns suggestions for a specific word.
*
* @param String $lang Selected language code (like en_US or de_DE). Shortcodes like "en" and "de" work with enchant >= 1.4.1
* @param String $word Specific word to get suggestions for.
* @return Array of suggestions for the specified word.
*/
function &getSuggestions($lang, $word)
{
$r = enchant_broker_init();
if (enchant_broker_dict_exists($r, $lang)) {
$d = enchant_broker_request_dict($r, $lang);
$suggs = enchant_dict_suggest($d, $word);
// enchant_dict_suggest() sometimes returns NULL
if (!is_array($suggs)) {
$suggs = array();
}
enchant_broker_free_dict($d);
} else {
$suggs = array();
}
enchant_broker_free($r);
return $suggs;
}
开发者ID:pzhu2004,项目名称:moodle,代码行数:24,代码来源:EnchantSpell.php
示例8: __construct
function __construct($langCode = null)
{
wfProfileIn(__METHOD__);
parent::__construct();
// create a new broker object
$this->broker = enchant_broker_init();
// set path to directory with extra dictionaries
// @see http://blog.iwanluijks.nl/2010/10/using-enchant-with-php-on-windows-part.html
$ip = $this->app->getGlobal('IP');
$this->path = "{$ip}/lib/dicts";
enchant_broker_set_dict_path($this->broker, ENCHANT_MYSPELL, $this->path);
enchant_broker_set_dict_path($this->broker, ENCHANT_ISPELL, $this->path);
// try to load dictionary
if (!empty($langCode)) {
$this->load($langCode);
}
wfProfileOut(__METHOD__);
}
开发者ID:schwarer2006,项目名称:wikia,代码行数:18,代码来源:SpellCheckerDictionary.class.php
示例9: __construct
public function __construct($options = array())
{
if (!function_exists('enchant_broker_init')) {
throw new InternalErrorException(__('Module %s not installed', 'Enchant'));
}
$this->_Broker = enchant_broker_init();
$defaults = array('path' => VENDORS . 'dictionaries' . DS, 'lang' => 'en_GB', 'engine' => self::ENGINE_MYSPELL);
$defaults = am($defaults, (array) Configure::read('Spell'));
$options = array_merge($defaults, $options);
if (!isset($this->_engines[$options['engine']])) {
throw new InternalErrorException(__('Engine %s not found', (string) $options['engine']));
}
$engineFolder = $this->_engines[$options['engine']];
enchant_broker_set_dict_path($this->_Broker, $options['engine'], $options['path'] . $engineFolder . DS);
if (!enchant_broker_dict_exists($this->_Broker, $options['lang'])) {
throw new InternalErrorException(__('Dictionary %s not found', $options['lang']));
}
$this->_Dict = enchant_broker_request_dict($this->_Broker, $options['lang']);
}
开发者ID:robksawyer,项目名称:grabitdown,代码行数:19,代码来源:SpellLib.php
示例10: check
/**
* @param array|Word[] $words
* @param array|string[] $locales
*
* @return SpellResult
*/
public function check($words, array $locales)
{
$misspelledWords = array();
$enchantResource = enchant_broker_init();
/*$bprovides = enchant_broker_describe($r);
echo "Current broker provides the following backend(s):\n";
print_r($bprovides);*/
/*$dicts = enchant_broker_list_dicts($r);
print_r($dicts);*/
$dictionaries = array();
foreach ($locales as $locale) {
if (!enchant_broker_dict_exists($enchantResource, $locale)) {
// TODO handle and log error
continue;
}
$dictionaries[$locale] = enchant_broker_request_dict($enchantResource, $locale);
}
//$dprovides = enchant_dict_describe($dictionary);
//echo "dictionary $tag provides:\n";
foreach ($words as $word) {
$checked = false;
$suggests = array();
foreach ($dictionaries as $locale => $dictionary) {
$suggests[$locale] = array();
$checked = $checked || enchant_dict_quick_check($dictionary, $word->getWord(), $suggests[$locale]);
}
$word->setChecked($checked);
if (!$word->isChecked()) {
$word->setSuggests($suggests);
$misspelledWords[] = $word;
}
}
foreach ($dictionaries as $dictionary) {
enchant_broker_free_dict($dictionary);
}
enchant_broker_free($enchantResource);
$spellResult = new SpellResult();
$spellResult->setCountOfWords(count($words));
$spellResult->setMisspelledWords($misspelledWords);
return $spellResult;
}
开发者ID:amaxlab,项目名称:speller,代码行数:47,代码来源:PhpSpeller.php
示例11: str_replace
$msg = str_replace('{page}', $page, __('You currently on page <strong>{page}</strong> of <strong>{total_pages}</strong> page(s)'));
//mfc
$msg = str_replace('{total_pages}', $total_pages, $msg);
$search_result_info .= '<div class="search-page-info">' . $msg . '</div>';
} else {
$page = 1;
}
// query time
if (!isset($_SERVER['QUERY_STRING'])) {
$_SERVER['QUERY_STRING'] = '';
}
$search_result_info .= '<div class="search-query-time">' . __('Query took') . ' <b>' . $biblio_list->query_time . '</b> ' . __('second(s) to complete') . '</div>';
if ($biblio_list->num_rows < 1 && $keywords != '') {
// word suggestion with enchant
if (function_exists('enchant_broker_init') && $sysconf['spellchecker_enabled']) {
$enc = enchant_broker_init();
if (enchant_broker_dict_exists($enc, $sysconf['default_lang'])) {
$dict = enchant_broker_request_dict($enc, $sysconf['default_lang']);
} else {
$dict = enchant_broker_request_dict($enc, 'en_US');
}
$search_result_info .= '<div class="search-suggestions">' . __('Did you mean:') . ' ';
$word = strtok($keywords, " \t\n");
$keywords_suggest = array();
while ($word !== false) {
// check if we are inside quote
if (stripos($word, '"', 0) === true) {
$search_result_info .= preg_replace('@[a-z]@i', '', $word);
$word = str_replace('"', '', $word);
}
$wordcorrect = enchant_dict_check($dict, $word);
开发者ID:banumelody,项目名称:slims7_cendana,代码行数:31,代码来源:default.inc.php
示例12: getSuggestions
/**
* Return a collection of suggestion corresponding a query
*
* @param string $query
* @return ArrayCollection An array collection of SearchEngineSuggestion
*/
private function getSuggestions($query, SearchEngineOptions $options)
{
// First we split the query into simple words
$words = explode(" ", $this->cleanupQuery(mb_strtolower($query)));
$tmpWords = [];
foreach ($words as $word) {
if (trim($word) === '') {
continue;
}
$tmpWords[] = $word;
}
$words = array_unique($tmpWords);
$altVersions = [];
foreach ($words as $word) {
$altVersions[$word] = [$word];
}
// As we got words, we look for alternate word for each of them
if (function_exists('enchant_broker_init') && $options->getLocale()) {
$broker = enchant_broker_init();
if (enchant_broker_dict_exists($broker, $options->getLocale())) {
$dictionnary = enchant_broker_request_dict($broker, $options->getLocale());
foreach ($words as $word) {
if (enchant_dict_check($dictionnary, $word) == false) {
$suggs = array_merge(enchant_dict_suggest($dictionnary, $word));
}
$altVersions[$word] = array_unique($suggs);
}
enchant_broker_free_dict($dictionnary);
}
enchant_broker_free($broker);
}
/**
* @todo enhance the trigramm query, as it could be sent in one batch
*/
foreach ($altVersions as $word => $versions) {
$altVersions[$word] = array_unique(array_merge($versions, $this->get_sugg_trigrams($word, $options)));
}
// We now build an array of all possibilities based on the original query
$queries = [$query];
foreach ($altVersions as $word => $versions) {
$tmp_queries = [];
foreach ($versions as $version) {
foreach ($queries as $alt_query) {
$tmp_queries[] = $alt_query;
$tmp_queries[] = str_replace($word, $version, $alt_query);
}
$tmp_queries[] = str_replace($word, $version, $query);
}
$queries = array_unique(array_merge($queries, $tmp_queries));
}
$suggestions = [];
$max_results = 0;
foreach ($queries as $alt_query) {
$results = $this->sphinx->Query($alt_query, $this->getQueryIndex($alt_query, $options));
if ($results !== false && isset($results['total_found'])) {
if ($results['total_found'] > 0) {
$max_results = max($max_results, (int) $results['total_found']);
$suggestions[] = new SearchEngineSuggestion($query, $alt_query, (int) $results['total_found']);
}
}
}
usort($suggestions, ['self', 'suggestionsHitSorter']);
$tmpSuggestions = new ArrayCollection();
foreach ($suggestions as $key => $suggestion) {
if ($suggestion->getHits() < $max_results / 100) {
continue;
}
$tmpSuggestions->add($suggestion);
}
return $tmpSuggestions;
}
开发者ID:romainneutron,项目名称:Phraseanet,代码行数:77,代码来源:SphinxSearchEngine.php
示例13: __construct
public function __construct($language = 'en_US')
{
$r = enchant_broker_init();
$this->enchantBroker = enchant_broker_request_dict($r, $language);
}
开发者ID:WHATNEXTLIMITED,项目名称:php-text-analysis,代码行数:5,代码来源:EnchantAdapter.php
示例14: suggestWithEnchant
/**
* Wiki-specific search suggestions using enchant library.
* Use SphinxSearch_setup.php to create the dictionary
*/
function suggestWithEnchant() {
if (!function_exists('enchant_broker_init')) {
return;
}
$broker = enchant_broker_init();
enchant_broker_set_dict_path($broker, ENCHANT_MYSPELL, dirname( __FILE__ ));
if ( enchant_broker_dict_exists( $broker, 'sphinx' ) ) {
$dict = enchant_broker_request_dict( $broker, 'sphinx' );
$suggestion_found = false;
$full_suggestion = '';
foreach ( $this->mTerms as $word ) {
if ( !enchant_dict_check($dict, $word) ) {
$suggestions = enchant_dict_suggest($dict, $word);
while ( count( $suggestions ) ) {
$candidate = array_shift( $suggestions );
if ( strtolower($candidate) != strtolower($word) ) {
$word = $candidate;
$suggestion_found = true;
break;
}
}
}
$full_suggestion .= $word . ' ';
}
enchant_broker_free_dict( $dict );
if ($suggestion_found) {
$this->mSuggestion = trim( $full_suggestion );
}
}
enchant_broker_free( $broker );
}
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:35,代码来源:SphinxMWSearch.php
示例15: convert
//.........这里部分代码省略.........
/**
* @var $value
*/
$value = ucwords($value);
}
/**
* @fn space_on_short_words
* @brief
* @param $value
* @returns
*/
function space_on_short_words(&$value)
{
/**
* @var $value
*/
$value = preg_replace('/^[\\d\\w]{1,3}$/u', ' $0 ', $value);
}
if (isset($spelling_check) && false !== $spelling_check) {
/**
* @var $stripped_text
*/
$stripped_text = strip_tags($text);
/**
* @var $paragraph
*/
$paragraph = preg_split("/[\\s,]+/s", $stripped_text);
array_walk($paragraph, 'trim_value');
/**
* @var $words_array
*/
$words_array = array_unique($paragraph);
array_multisort($words_array);
if (function_exists('enchant_broker_init')) {
/**
* @var $tag
*/
$tag = 'en_US';
/**
* @var $r
*/
$r = enchant_broker_init();
/**
* @var $bprovides
*/
$bprovides = enchant_broker_describe($r);
/**
* @var $dicts
*/
$dicts = enchant_broker_list_dicts($r);
if (enchant_broker_dict_exists($r, $tag)) {
/**
* @var $d
*/
$d = enchant_broker_request_dict($r, $tag);
/**
* @var $dprovides
*/
$dprovides = enchant_dict_describe($d);
foreach ($words_array as $word) {
if (!empty($word)) {
/**
* @var $wordcorrect
*/
$wordcorrect = enchant_dict_check($d, $word);
if ($wordcorrect) {
开发者ID:kanaung,项目名称:kanaung-web-kit,代码行数:67,代码来源:class-converter.php
注:本文中的enchant_broker_init函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论