| 1 |
<?php |
<?php |
| 2 |
// $Id: porterstemmer.module,v 1.2.2.4 2009/10/21 23:39:54 jhodgdon Exp $ |
// $Id: porterstemmer.module,v 1.2.2.5 2009/10/21 23:47:22 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. |
$has_pecl_stem = _porterstemmer_pecl_loaded(); |
|
|
|
|
$has_pecl_stem = FALSE; |
|
|
|
|
|
if (extension_loaded( 'stem')) { |
|
|
$has_pecl_stem = TRUE; |
|
|
} |
|
|
else { |
|
|
// dynamic loading of extensions is going away in PHP 6, so leave this |
|
|
// check here! |
|
|
if (function_exists( 'dl' )) { |
|
|
$has_pecl_stem = dl('stem.so'); |
|
|
} |
|
|
} |
|
|
|
|
|
$has_pecl_stem = $has_pecl_stem && function_exists('stem_english'); |
|
| 30 |
|
|
| 31 |
// Process each word, skipping delimiters |
// Process each word, skipping delimiters |
| 32 |
$isword = !preg_match('/' . PORTERSTEMMER_BOUNDARY . '/', $words[0] ); |
$isword = !preg_match('/' . PORTERSTEMMER_BOUNDARY . '/', $words[0] ); |
| 108 |
} |
} |
| 109 |
|
|
| 110 |
/** |
/** |
| 111 |
|
* Checks to see if the PECL stem extension has been loaded. |
| 112 |
|
* |
| 113 |
|
* @return |
| 114 |
|
* TRUE if the stem_english() function from the PECL stem library can be |
| 115 |
|
* used, FALSE if not. |
| 116 |
|
*/ |
| 117 |
|
function _porterstemmer_pecl_loaded() { |
| 118 |
|
static $has_pecl_stem = FALSE; |
| 119 |
|
static $already_checked = FALSE; |
| 120 |
|
|
| 121 |
|
if ( $already_checked ) { |
| 122 |
|
return $has_pecl_stem; |
| 123 |
|
} |
| 124 |
|
|
| 125 |
|
$has_pecl_stem = extension_loaded('stem') && function_exists('stem_english'); |
| 126 |
|
$already_checked = TRUE; |
| 127 |
|
return $has_pecl_stem; |
| 128 |
|
} |
| 129 |
|
|
| 130 |
|
/** |
| 131 |
* Regular expression defining a vowel for Porter Stemmer purposes. |
* Regular expression defining a vowel for Porter Stemmer purposes. |
| 132 |
*/ |
*/ |
| 133 |
define('PORTERSTEMMER_VOWEL', '[aeiouy]'); |
define('PORTERSTEMMER_VOWEL', '[aeiouy]'); |