PHP5 Implementation of the Porter Stemmer algorithm. Certain elements were borrowed from the (broken) implementation by Jon Abernathy.

Usage:

$stem = PorterStemmer::Stem($word);

How easy is that?

package core

 Methods

Stems a word. Simple huh?

stem(string $word) : string
Static

Parameters

$word

string

Word to stem

Returns

stringStemmed word

Checks for ending CVC sequence where second C is not W, X or Y

cvc(string $str) : boolean
Static

Parameters

$str

string

String to check

Returns

booleanResult

Returns true/false as to whether the given string contains two of the same consonant next to each other at the end of the string.

doubleConsonant(string $str) : boolean
Static

Parameters

$str

string

String to check

Returns

booleanResult

What, you mean it's not obvious from the name?

m(string $str) : integer
Static

m() measures the number of consonant sequences in $str. if c is a consonant sequence and v a vowel sequence, and <..> indicates arbitrary presence,

gives 0 vc gives 1 vcvc gives 2 vcvcvc gives 3

Parameters

$str

string

The string to return the m count for

Returns

integerThe m count

Replaces the first string with the second, at the end of the string. If third arg is given, then the preceding string must match that m count at least.

replace(string $str, string $check, string $repl, integer $m = null) : boolean
Static

Parameters

$str

string

String to check

$check

string

Ending to check for

$repl

string

Replacement string

$m

integer

Optional minimum number of m() to meet

Returns

booleanWhether the $check string was at the end of the $str string. True does not necessarily mean that it was replaced.

Step 1

step1ab($word) 
Static

Parameters

$word

Step 1c

step1c(string $word) 
Static

Parameters

$word

string

Word to stem

Step 2

step2(string $word) 
Static

Parameters

$word

string

Word to stem

Step 3

step3(string $word) 
Static

Parameters

$word

string

String to stem

Step 4

step4(string $word) 
Static

Parameters

$word

string

Word to stem

Step 5

step5(string $word) 
Static

Parameters

$word

string

Word to stem

 Properties

 

Regex for matching a consonant

$regex_consonant : string

Default

'(?:[bcdfghjklmnpqrstvwxz]|(?<=[aeiou])y|^y)'
Static
 

Regex for matching a vowel

$regex_vowel : string

Default

'(?:[aeiou]|(?
Static