|
9 | 9 | * Implements a version of a technique originally proposed by Cavnar & Trenkle
|
10 | 10 | * (1994): "N-Gram-Based Text Categorization"
|
11 | 11 | *
|
12 |
| - * PHP versions 4 and 5 |
| 12 | + * PHP version 5 |
13 | 13 | *
|
14 | 14 | * @category Text
|
15 | 15 | * @package Text_LanguageDetect
|
|
22 | 22 | */
|
23 | 23 |
|
24 | 24 | require_once 'PEAR.php';
|
| 25 | +require_once 'Text/LanguageDetect/Exception.php'; |
25 | 26 | require_once 'Text/LanguageDetect/Parser.php';
|
26 | 27 | require_once 'Text/LanguageDetect/ISO639.php';
|
27 | 28 |
|
@@ -252,9 +253,9 @@ function _readdb($fname)
|
252 | 253 |
|
253 | 254 | // input check
|
254 | 255 | if (!file_exists($fname)) {
|
255 |
| - return PEAR::raiseError('Language database does not exist.'); |
| 256 | + throw new Text_LanguageDetect_Exception('Language database does not exist.'); |
256 | 257 | } elseif (!is_readable($fname)) {
|
257 |
| - return PEAR::raiseError('Language database is not readable.'); |
| 258 | + throw new Text_LanguageDetect_Exception('Language database is not readable.'); |
258 | 259 | }
|
259 | 260 |
|
260 | 261 | if (function_exists('file_get_contents')) {
|
@@ -288,16 +289,12 @@ function _setup_ok(&$err)
|
288 | 289 |
|
289 | 290 | } elseif (!is_array($this->_lang_db)) {
|
290 | 291 | if (ini_get('magic_quotes_runtime')) {
|
291 |
| - $err = PEAR::raiseError('Error loading database. Try turning magic_quotes_runtime off.'); |
| 292 | + throw new Text_LanguageDetect_Exception('Error loading database. Try turning magic_quotes_runtime off.'); |
292 | 293 | } else {
|
293 |
| - $err = PEAR::raiseError('Language database is not an array.'); |
| 294 | + throw new Text_LanguageDetect_Exception('Language database is not an array.'); |
294 | 295 | }
|
295 |
| - return false; |
296 |
| - |
297 | 296 | } elseif (empty($this->_lang_db)) {
|
298 |
| - $err = PEAR::raiseError('Language database has no elements.'); |
299 |
| - return false; |
300 |
| - |
| 297 | + throw new Text_LanguageDetect_Exception('Language database has no elements.'); |
301 | 298 | } else {
|
302 | 299 | return true;
|
303 | 300 | }
|
@@ -424,7 +421,7 @@ function languageExists($lang)
|
424 | 421 |
|
425 | 422 | // other (error)
|
426 | 423 | } else {
|
427 |
| - return PEAR::raiseError('Unknown type passed to languageExists()'); |
| 424 | + throw new Text_LanguageDetect_Exception('Unknown type passed to languageExists()'); |
428 | 425 | }
|
429 | 426 | }
|
430 | 427 | }
|
@@ -774,7 +771,7 @@ function detect($sample, $limit = 0)
|
774 | 771 | if (is_array($blocks)) {
|
775 | 772 | $present_blocks = array_keys($blocks);
|
776 | 773 | } else {
|
777 |
| - return PEAR::raiseError('Error during block detection'); |
| 774 | + throw new Text_LanguageDetect_Exception('Error during block detection'); |
778 | 775 | }
|
779 | 776 |
|
780 | 777 | $possible_langs = array();
|
@@ -964,11 +961,11 @@ function detectUnicodeBlocks($str, $skip_symbols)
|
964 | 961 | {
|
965 | 962 | // input check
|
966 | 963 | if (!is_bool($skip_symbols)) {
|
967 |
| - return PEAR::raiseError('Second parameter must be boolean'); |
| 964 | + throw new Text_LanguageDetect_Exception('Second parameter must be boolean'); |
968 | 965 | }
|
969 | 966 |
|
970 | 967 | if (!is_string($str)) {
|
971 |
| - return PEAR::raiseError('First parameter was not a string'); |
| 968 | + throw new Text_LanguageDetect_Exception('First parameter was not a string'); |
972 | 969 | }
|
973 | 970 |
|
974 | 971 | $sample_obj = new Text_LanguageDetect_Parser($str);
|
@@ -1001,18 +998,18 @@ function unicodeBlockName($unicode) {
|
1001 | 998 |
|
1002 | 999 | // input check
|
1003 | 1000 | if ($this->utf8strlen($unicode) > 1) {
|
1004 |
| - return PEAR::raiseError('Pass this function only a single char'); |
| 1001 | + throw new Text_LanguageDetect_Exception('Pass this function only a single char'); |
1005 | 1002 | }
|
1006 | 1003 |
|
1007 | 1004 | $unicode = $this->_utf8char2unicode($unicode);
|
1008 | 1005 |
|
1009 | 1006 | if ($unicode == -1) {
|
1010 |
| - return PEAR::raiseError('Malformatted char'); |
| 1007 | + throw new Text_LanguageDetect_Exception('Malformatted char'); |
1011 | 1008 | }
|
1012 | 1009 |
|
1013 | 1010 | // input check
|
1014 | 1011 | } elseif (!is_int($unicode)) {
|
1015 |
| - return PEAR::raiseError('Input must be of type string or int.'); |
| 1012 | + throw new Text_LanguageDetect_Exception('Input must be of type string or int.'); |
1016 | 1013 | }
|
1017 | 1014 |
|
1018 | 1015 | $blocks =& $this->_read_unicode_block_db();
|
@@ -1253,7 +1250,7 @@ function clusterLanguages()
|
1253 | 1250 |
|
1254 | 1251 | foreach ($langs as $lang) {
|
1255 | 1252 | if (!isset($this->_lang_db[$lang])) {
|
1256 |
| - return PEAR::raiseError("missing $lang!\n"); |
| 1253 | + throw new Text_LanguageDetect_Exception("missing $lang!\n"); |
1257 | 1254 | }
|
1258 | 1255 | }
|
1259 | 1256 |
|
@@ -1281,7 +1278,7 @@ function clusterLanguages()
|
1281 | 1278 |
|
1282 | 1279 | if (!$highest_key1) {
|
1283 | 1280 | // should not ever happen
|
1284 |
| - return PEAR::raiseError("no highest key? (step: $i)"); |
| 1281 | + throw new Text_LanguageDetect_Exception("no highest key? (step: $i)"); |
1285 | 1282 | }
|
1286 | 1283 |
|
1287 | 1284 | if ($highest_score == 0) {
|
|
0 commit comments