Changeset View
Changeset View
Standalone View
Standalone View
externals/porter-stemmer/src/Porter.php
Context not available. | |||||
*/ | */ | ||||
public static function Stem($word) | public static function Stem($word) | ||||
{ | { | ||||
if (strlen($word) <= 2) { | if (@strlen($word) <= 2) { | ||||
return $word; | return $word; | ||||
} | } | ||||
Context not available. | |||||
private static function step1ab($word) | private static function step1ab($word) | ||||
{ | { | ||||
// Part a | // Part a | ||||
if (substr($word, -1) == 's') { | if (@substr($word, -1) == 's') { | ||||
self::replace($word, 'sses', 'ss') | self::replace($word, 'sses', 'ss') | ||||
OR self::replace($word, 'ies', 'i') | OR self::replace($word, 'ies', 'i') | ||||
Context not available. | |||||
} | } | ||||
// Part b | // Part b | ||||
if (substr($word, -2, 1) != 'e' OR !self::replace($word, 'eed', 'ee', 0)) { // First rule | if (@substr($word, -2, 1) != 'e' OR !self::replace($word, 'eed', 'ee', 0)) { // First rule | ||||
$v = self::$regex_vowel; | $v = self::$regex_vowel; | ||||
// ing and ed | // ing and ed | ||||
if ( preg_match("#$v+#", substr($word, 0, -3)) && self::replace($word, 'ing', '') | if ( @preg_match("#$v+#", @substr($word, 0, -3)) && self::replace($word, 'ing', '') | ||||
OR preg_match("#$v+#", substr($word, 0, -2)) && self::replace($word, 'ed', '')) { // Note use of && and OR, for precedence reasons | OR @preg_match("#$v+#", @substr($word, 0, -2)) && self::replace($word, 'ed', '')) { // Note use of && and OR, for precedence reasons | ||||
// If one of above two test successful | // If one of above two test successful | ||||
if ( !self::replace($word, 'at', 'ate') | if ( !self::replace($word, 'at', 'ate') | ||||
Context not available. | |||||
// Double consonant ending | // Double consonant ending | ||||
if ( self::doubleConsonant($word) | if ( self::doubleConsonant($word) | ||||
AND substr($word, -2) != 'll' | AND @substr($word, -2) != 'll' | ||||
AND substr($word, -2) != 'ss' | AND @substr($word, -2) != 'ss' | ||||
AND substr($word, -2) != 'zz') { | AND @substr($word, -2) != 'zz') { | ||||
$word = substr($word, 0, -1); | $word = @substr($word, 0, -1); | ||||
} elseif (self::m($word) == 1 AND self::cvc($word)) { | } elseif (self::m($word) == 1 AND self::cvc($word)) { | ||||
$word .= 'e'; | $word .= 'e'; | ||||
Context not available. | |||||
{ | { | ||||
$v = self::$regex_vowel; | $v = self::$regex_vowel; | ||||
if (substr($word, -1) == 'y' && preg_match("#$v+#", substr($word, 0, -1))) { | if (@substr($word, -1) == 'y' && @preg_match("#$v+#", @substr($word, 0, -1))) { | ||||
self::replace($word, 'y', 'i'); | self::replace($word, 'y', 'i'); | ||||
} | } | ||||
Context not available. | |||||
*/ | */ | ||||
private static function step2($word) | private static function step2($word) | ||||
{ | { | ||||
switch (substr($word, -2, 1)) { | switch (@substr($word, -2, 1)) { | ||||
case 'a': | case 'a': | ||||
self::replace($word, 'ational', 'ate', 0) | self::replace($word, 'ational', 'ate', 0) | ||||
OR self::replace($word, 'tional', 'tion', 0); | OR self::replace($word, 'tional', 'tion', 0); | ||||
Context not available. | |||||
*/ | */ | ||||
private static function step3($word) | private static function step3($word) | ||||
{ | { | ||||
switch (substr($word, -2, 1)) { | switch (@substr($word, -2, 1)) { | ||||
case 'a': | case 'a': | ||||
self::replace($word, 'ical', 'ic', 0); | self::replace($word, 'ical', 'ic', 0); | ||||
break; | break; | ||||
Context not available. | |||||
*/ | */ | ||||
private static function step4($word) | private static function step4($word) | ||||
{ | { | ||||
switch (substr($word, -2, 1)) { | switch (@substr($word, -2, 1)) { | ||||
case 'a': | case 'a': | ||||
self::replace($word, 'al', '', 1); | self::replace($word, 'al', '', 1); | ||||
break; | break; | ||||
Context not available. | |||||
break; | break; | ||||
case 'o': | case 'o': | ||||
if (substr($word, -4) == 'tion' OR substr($word, -4) == 'sion') { | if (@substr($word, -4) == 'tion' OR @substr($word, -4) == 'sion') { | ||||
self::replace($word, 'ion', '', 1); | self::replace($word, 'ion', '', 1); | ||||
} else { | } else { | ||||
self::replace($word, 'ou', '', 1); | self::replace($word, 'ou', '', 1); | ||||
Context not available. | |||||
private static function step5($word) | private static function step5($word) | ||||
{ | { | ||||
// Part a | // Part a | ||||
if (substr($word, -1) == 'e') { | if (@substr($word, -1) == 'e') { | ||||
if (self::m(substr($word, 0, -1)) > 1) { | if (self::m(@substr($word, 0, -1)) > 1) { | ||||
self::replace($word, 'e', ''); | self::replace($word, 'e', ''); | ||||
} elseif (self::m(substr($word, 0, -1)) == 1) { | } elseif (self::m(@substr($word, 0, -1)) == 1) { | ||||
if (!self::cvc(substr($word, 0, -1))) { | if (!self::cvc(@substr($word, 0, -1))) { | ||||
self::replace($word, 'e', ''); | self::replace($word, 'e', ''); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Part b | // Part b | ||||
if (self::m($word) > 1 AND self::doubleConsonant($word) AND substr($word, -1) == 'l') { | if (self::m($word) > 1 AND self::doubleConsonant($word) AND @substr($word, -1) == 'l') { | ||||
$word = substr($word, 0, -1); | $word = @substr($word, 0, -1); | ||||
} | } | ||||
return $word; | return $word; | ||||
Context not available. | |||||
*/ | */ | ||||
private static function replace(&$str, $check, $repl, $m = null) | private static function replace(&$str, $check, $repl, $m = null) | ||||
{ | { | ||||
$len = 0 - strlen($check); | $len = 0 - @strlen($check); | ||||
if (substr($str, $len) == $check) { | if (@substr($str, $len) == $check) { | ||||
$substr = substr($str, 0, $len); | $substr = @substr($str, 0, $len); | ||||
if (is_null($m) OR self::m($substr) > $m) { | if (is_null($m) OR self::m($substr) > $m) { | ||||
$str = $substr . $repl; | $str = $substr . $repl; | ||||
} | } | ||||
Context not available. | |||||
{ | { | ||||
$c = self::$regex_consonant; | $c = self::$regex_consonant; | ||||
return preg_match("#$c{2}$#", $str, $matches) AND $matches[0][0] == $matches[0][1]; | return @preg_match("#$c{2}$#", $str, $matches) AND $matches[0][0] == $matches[0][1]; | ||||
} | } | ||||
/** | /** | ||||
Context not available. | |||||
$c = self::$regex_consonant; | $c = self::$regex_consonant; | ||||
$v = self::$regex_vowel; | $v = self::$regex_vowel; | ||||
return preg_match("#($c$v$c)$#", $str, $matches) | return @preg_match("#($c$v$c)$#", $str, $matches) | ||||
AND strlen($matches[1]) == 3 | AND @strlen($matches[1]) == 3 | ||||
AND $matches[1][2] != 'w' | AND $matches[1][2] != 'w' | ||||
AND $matches[1][2] != 'x' | AND $matches[1][2] != 'x' | ||||
AND $matches[1][2] != 'y'; | AND $matches[1][2] != 'y'; | ||||
Context not available. |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0