| 1 |
<?php |
<?php |
| 2 |
// $Id: porterstemmer.module,v 1.2.2.2 2009/09/10 14:50:28 jhodgdon Exp $ |
// $Id: porterstemmer.module,v 1.2.2.3 2009/10/08 16:22:10 jhodgdon Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 26 |
return $text; |
return $text; |
| 27 |
} |
} |
| 28 |
|
|
| 29 |
|
// See if the PECL stemming package is installed and try to load it. |
| 30 |
|
|
| 31 |
|
$has_pecl_stem = FALSE; |
| 32 |
|
|
| 33 |
|
if (extension_loaded( 'stem')) { |
| 34 |
|
$has_pecl_stem = TRUE; |
| 35 |
|
} |
| 36 |
|
else { |
| 37 |
|
// dynamic loading of extensions is going away in PHP 6, so leave this |
| 38 |
|
// check here! |
| 39 |
|
if (function_exists( 'dl' )) { |
| 40 |
|
$has_pecl_stem = dl('stem.so'); |
| 41 |
|
} |
| 42 |
|
} |
| 43 |
|
|
| 44 |
|
$has_pecl_stem = $has_pecl_stem && function_exists('stem_english'); |
| 45 |
|
|
| 46 |
// Process each word, skipping delimiters |
// Process each word, skipping delimiters |
| 47 |
$isword = !preg_match('/' . PORTERSTEMMER_BOUNDARY . '/', $words[0] ); |
$isword = !preg_match('/' . PORTERSTEMMER_BOUNDARY . '/', $words[0] ); |
| 48 |
foreach ($words as $k => $word) { |
foreach ($words as $k => $word) { |
| 49 |
if ($isword) { |
if ($isword) { |
| 50 |
$words[$k] = porterstemmer_stem($word); |
if( $has_pecl_stem ) { |
| 51 |
|
$words[$k] = stem_english($word); |
| 52 |
|
} else { |
| 53 |
|
$words[$k] = porterstemmer_stem($word); |
| 54 |
|
} |
| 55 |
} |
} |
| 56 |
$isword = !$isword; |
$isword = !$isword; |
| 57 |
} |
} |