\PorterStemmer

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?

Summary

Methods
Properties
Constants
Stem()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
step1ab()
step1c()
step2()
step3()
step4()
step5()
replace()
m()
doubleConsonant()
cvc()
$regex_consonant
$regex_vowel
N/A

Properties

$regex_consonant

$regex_consonant : string

Regex for matching a consonant

Type

string

$regex_vowel

$regex_vowel : string

Regex for matching a vowel

Type

string

Methods

Stem()

Stem(string  $word) : string

Stems a word. Simple huh?

Parameters

string $word

Word to stem

Returns

string —

Stemmed word

step1ab()

step1ab(string  $word) 

Step 1

Parameters

string $word

Word to stem

step1c()

step1c(string  $word) 

Step 1c

Parameters

string $word

Word to stem

step2()

step2(string  $word) 

Step 2

Parameters

string $word

Word to stem

step3()

step3(string  $word) 

Step 3

Parameters

string $word

String to stem

step4()

step4(string  $word) 

Step 4

Parameters

string $word

Word to stem

step5()

step5(string  $word) 

Step 5

Parameters

string $word

Word to stem

replace()

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

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.

Parameters

string $str

String to check

string $check

Ending to check for

string $repl

Replacement string

integer $m

Optional minimum number of m() to meet

Returns

boolean —

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

m()

m(string  $str) : integer

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

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

string $str

The string to return the m count for

Returns

integer —

The m count

doubleConsonant()

doubleConsonant(string  $str) : boolean

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.

Parameters

string $str

String to check

Returns

boolean —

Result

cvc()

cvc(string  $str) : boolean

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

Parameters

string $str

String to check

Returns

boolean —

Result