cvs: pear /Text_LanguageDetect/Text/LanguageDetect Parser.php
| From: | Nicholas Pisarro | Date: | Wed, 18 Jan 2006 20:27:18 +0000 |
| Subject: | cvs: pear /Text_LanguageDetect/Text/LanguageDetect Parser.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-37639@lists.php.net to get a copy of this message | ||
taak Wed Jan 18 20:27:18 2006 UTC
Modified files:
/pear/Text_LanguageDetect/Text/LanguageDetect Parser.php
Log:
- speed improvement: store all unicode chars in an array, then convert to ranges all at once
- fixed PHP Notice error in php 5
http://cvs.php.net/viewcvs.cgi/pear/Text_LanguageDetect/Text/LanguageDetect/Parser.php?r1=1.2&r2=1.3&diff_format=u
Index: pear/Text_LanguageDetect/Text/LanguageDetect/Parser.php
diff -u pear/Text_LanguageDetect/Text/LanguageDetect/Parser.php:1.2
pear/Text_LanguageDetect/Text/LanguageDetect/Parser.php:1.3
--- pear/Text_LanguageDetect/Text/LanguageDetect/Parser.php:1.2 Tue Jan 17 23:35:16 2006
+++ pear/Text_LanguageDetect/Text/LanguageDetect/Parser.php Wed Jan 18 20:27:18 2006
@@ -8,7 +8,7 @@
* @author Nicholas Pisarro
* @copyright 2006
* @license BSD
- * @version CVS: $Id: Parser.php,v 1.2 2006/01/17 23:35:16 taak Exp $
+ * @version CVS: $Id: Parser.php,v 1.3 2006/01/18 20:27:18 taak Exp $
* @link http://pear.php.net/package/Text_LanguageDetect/
* @link http://langdetect.blogspot.com/
*/
@@ -229,6 +229,8 @@
} else {
$block_count = count($blocks);
}
+
+ $skipped_count = 0;
}
// trigram startup
@@ -288,44 +290,38 @@
continue;
}
- $unicode = $this->_utf8char2unicode($char);
+ // build an array of all the characters
+ if (isset($unicode_chars[$char])) {
+ $unicode_chars[$char]++;
+ } else {
+ $unicode_chars[$char] = 1;
+ }
+ }
- // since we're usually going to be seeing the same thing,
- // check the last one found first
- if (isset($last_block)
- && $unicode >= $last_block[0]
- && $unicode <= $last_block[1]) {
+ // todo: add byte detection here
+ }
- $this->_unicode_blocks[$last_block[2]]++;
+ // unicode cleanup
+ if ($this->_compile_unicode) {
+ foreach ($unicode_chars as $utf8_char => $count) {
+ $search_result = $this->_unicode_block_name(
+ $this->_utf8char2unicode($utf8_char), $blocks, $block_count);
- // if not the same as the last, search the whole block db
+ if ($search_result != -1) {
+ $block_name = $search_result[2];
} else {
- $search_result = $this->_unicode_block_name($unicode, $blocks,
$block_count);
-
- // if non-error result
- if ($search_result != -1) {
- if (!isset($this->_unicode_blocks[$search_result[2]])) {
- $this->_unicode_blocks[$search_result[2]] = 1;
- } else {
- $this->_unicode_blocks[$search_result[2]]++;
- }
-
- $last_block = $search_result;
+ $block_name = '[Malformatted]';
+ }
- // if error result
- } else {
- if (!isset($this->_unicode_blocks['[Malformatted]'])) {
- $this->_unicode_blocks['[Malformatted]'] = 1;
- } else {
- $this->_unicode_blocks['[Malformatted]']++;
- }
- }
+ if (isset($this->_unicode_blocks[$block_name])) {
+ $this->_unicode_blocks[$block_name] += $count;
+ } else {
+ $this->_unicode_blocks[$block_name] = $count;
}
}
-
- // todo: add byte detection here
}
+
// trigram cleanup
if ($this->_compile_trigram) {
// pad the end