1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
<?php
define('SPELLCHECKER_SUGGEST_FAST', 1);
define('SPELLCHECKER_SUGGEST_NORMAL', 2);
define('SPELLCHECKER_SUGGEST_SLOW', 3);
/**
* The IMP_SpellChecker:: class provides a unified spellchecker API.
*
* TODO: This is only needed in IMP for BC - SpellChecker.php wasn't available
* before Horde 3.2.
*
* $Horde: imp/lib/SpellChecker.php,v 1.7.2.3 2008/02/26 16:56:06 slusarz Exp $
*
* Copyright 2005-2008 The Horde Project (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @author Chuck Hagenbuch <chuck@horde.org>
* @package IMP_SpellChecker
*/
class IMP_SpellChecker {
var $_maxSuggestions = 10;
var $_minLength = 3;
var $_locale = 'en';
var $_encoding = 'utf-8';
var $_html = false;
var $_suggestMode = SPELLCHECKER_SUGGEST_FAST;
var $_localDict = array();
/**
* Constructor.
*/
function IMP_SpellChecker($params)
{
$this->__construct($params);
}
/**
*/
function __construct($params)
{
$this->setParams($params);
}
/**
* TODO
*
* @param array $params TODO
*/
function setParams($params)
{
foreach ($params as $key => $val) {
$key = '_' . $key;
$this->$key = $val;
}
}
/**
* TODO
*
* @param string $engine TODO
* @param array $params TODO
*
* @return TODO
*/
function factory($engine, $params = array())
{
$engine = strtolower(basename($engine));
$class = 'IMP_SpellChecker_' . $engine;
if (!class_exists($class)) {
include IMP_BASE . '/lib/SpellChecker/' . $engine . '.php';
}
if (!class_exists($class)) {
return false;
}
return new $class($params);
}
/**
* TODO
*
* @abstract
*
* @param string $text TODO
*
* @return array TODO
*/
function spellCheck($text)
{
}
/**
* TODO
*
* @access private
*
* @param string $text TODO
*
* @return array TODO
*/
function _getWords($text)
{
return array_unique(preg_split('/[\s\[\]]+/s', $text, -1, PREG_SPLIT_NO_EMPTY));
}
/**
* Determine if a word exists in the local dictionary.
*
* @access private
*
* @param string $word The word to check.
*
* @return boolean True if the word appears in the local dictionary.
*/
function _inLocalDictionary($word)
{
return (empty($this->_localDict)) ? false : in_array(String::lower($word, true), $this->_localDict);
}
}
|