def self.stem(word)
word = word.dup.to_str
return word if word.length < 3
word[0] = 'Y' if word[0] == y
if word =~ /(ss|i)es$/
word = $` + $1
elsif word =~ /([^s])s$/
word = $` + $1
end
if word =~ /eed$/
word.chop! if $` =~ MGR0
elsif word =~ /(ed|ing)$/
stem = $`
if stem =~ VOWEL_IN_STEM
word = stem
case word
when /(at|bl|iz)$/ then word << "e"
when /([^aeiouylsz])\1$/ then word.chop!
when /^#{CC}#{V}[^aeiouwxy]$/ then word << "e"
end
end
end
if word =~ /y$/
stem = $`
word = stem + "i" if stem =~ VOWEL_IN_STEM
end
if word =~ SUFFIX_1_REGEXP
stem = $`
suffix = $1
if stem =~ MGR0
word = stem + STEP_2_LIST[suffix]
end
end
if word =~ /(icate|ative|alize|iciti|ical|ful|ness)$/
stem = $`
suffix = $1
if stem =~ MGR0
word = stem + STEP_3_LIST[suffix]
end
end
if word =~ SUFFIX_2_REGEXP
stem = $`
if stem =~ MGR1
word = stem
end
elsif word =~ /(s|t)(ion)$/
stem = $` + $1
if stem =~ MGR1
word = stem
end
end
if word =~ /e$/
stem = $`
if (stem =~ MGR1) ||
(stem =~ MEQ1 && stem !~ /^#{CC}#{V}[^aeiouwxy]$/)
word = stem
end
end
if word =~ /ll$/ && word =~ MGR1
word.chop!
end
word[0] = 'y' if word[0] == Y
word
end