Professional Documents
Culture Documents
The Porter Stemming Algorithm
The Porter Stemming Algorithm
html
A consonant will be denoted by c, a vowel by v. A list ccc... of length greater than 0 will
be denoted by C, and a list vvv... of length greater than 0 will be denoted by V. Any
word, or part of a word, therefore has one of the four forms:
CVCV ... C
CVCV ... V
VCVC ... C
VCVC ... V
1 of 12 1/13/2016 5:43 PM
The Porter stemming algorithm http://snowball.tartarus.org/algorithms/porter/stemmer.html
where the square brackets denote arbitrary presence of their contents. Using (VC)m to
denote VC repeated m times, this may again be written as
[C](VC)m[V].
m will be called the measure of any word or word part when represented in this form.
The case m = 0 covers the null word. Here are some examples:
(condition) S1 -> S2
This means that if a word ends with the suffix S1, and the stem before S1 satisfies the
given condition, S1 is replaced by S2. The condition is usually given in terms of m, e.g.
*S - the stem ends with S (and similarly for the other letters).
*v* - the stem contains a vowel.
*d - the stem ends with a double consonant (e.g. -TT, -SS).
*o - the stem ends cvc, where the second c is not W, X or Y (e.g. -WIL, -HOP).
And the condition part may also contain expressions with and, or and not, so that
tests for a stem ending with a double consonant other than L, S or Z. Elaborate
conditions like this are required only rarely.
In a set of rules written beneath each other, only one is obeyed, and this will be the one
with the longest matching S1 for the given word. For example, with
SSES -> SS
IES -> I
2 of 12 1/13/2016 5:43 PM
The Porter stemming algorithm http://snowball.tartarus.org/algorithms/porter/stemmer.html
SS -> SS
S ->
(here the conditions are all null) CARESSES maps to CARESS since SSES is the
longest match for S1. Equally CARESS maps to CARESS (S1=‘SS’) and CARES to
CARE (S1=‘S’).
In the rules below, examples of their application, successful or otherwise, are given on
the right in lower case. The algorithm now follows:
Step 1a
Step 1b
If the second or third of the rules in Step 1b is successful, the following is done:
The rule to map to a single letter causes the removal of one of the double letter pair. The
-E is put back on -AT, -BL and -IZ, so that the suffixes -ATE, -BLE and -IZE can be
recognised later. This E may be removed in step 4.
Step 1c
3 of 12 1/13/2016 5:43 PM
The Porter stemming algorithm http://snowball.tartarus.org/algorithms/porter/stemmer.html
Step 1 deals with plurals and past participles. The subsequent steps are much more
straightforward.
Step 2
The test for the string S1 can be made fast by doing a program switch on the penultimate
letter of the word being tested. This gives a fairly even breakdown of the possible values
of the string S1. It will be seen in fact that the S1-strings in step 2 are presented here in
the alphabetical order of their penultimate letter. Similar techniques may be applied in
the other steps.
Step 3
4 of 12 1/13/2016 5:43 PM
The Porter stemming algorithm http://snowball.tartarus.org/algorithms/porter/stemmer.html
Step 4
The suffixes are now removed. All that remains is a little tidying up.
Step 5a
Step 5b
(m > 1 and *d and *L) -> single letter controll -> control
roll -> roll
The Porter stemmer makes a use of a measure, m, of the length of a word or word part. If
C is a sequence of one or more consonants, and V a sequence of one or more vowels,
any word part has the form
[C](VC)m[V],
5 of 12 1/13/2016 5:43 PM
The Porter stemming algorithm http://snowball.tartarus.org/algorithms/porter/stemmer.html
Most of the rules for suffix removal involve leaving behind a stem whose measure
exceeds some value, for example,
means ‘replace eed with ee if the stem before eed has measure m > 0’. Implementations
of the Porter stemmer usually have a routine that computes m each time there is a
possible candidate for removal.
In fact the only tests on m in the Porter stemmer are m > 0, m > 1, and, at two interesting
points, m = 1. This suggests that there are two critical positions in a word: the point at
which, going from left to right, m > 0 becomes true, and then the point at which m > 1
becomes true. It turns out that m > 0 becomes true at the point after the first consonant
following a vowel, and m > 1 becomes true at the point after the first consonant
following a vowel following a consonant following a vowel. Calling these positions p1
and p2, we can determine them quite simply in Snowball:
define v 'aeiouy'
....
do(
gopast v gopast non-v setmark p1
gopast v gopast non-v setmark p2
)
The region to the right of p1 will be denoted by R1, the region to the right of p2 by R2:
c r e p u s c u l a r
| |
p1 p2
<--- R1 --->
<-- R2 -->
We can test for being in these regions with calls to R1 and R2, defined by,
define R1 as $p1 <= cursor
define R2 as $p2 <= cursor
and using these tests instead of computing m is acceptable, so long as the stemming
process never alters the p1 and p2 positions, which is indeed true in the Porter stemmer.
A particularly interesting feature of the stemmers presented here is the common use they
make of the positions p1 and p2. The details of marking p1 and p2 vary between the
languages because the definitions of vowel and consonant vary. For example, French i
preceded and followed by vowel should be treated as a consonant (inquiétude);
Portuguese (ã and õ should be treated as a vowel-consonant pair (São João). A third
important position is pV, which tries to mark the position of the shortest acceptable verb
6 of 12 1/13/2016 5:43 PM
The Porter stemming algorithm http://snowball.tartarus.org/algorithms/porter/stemmer.html
stem. Its definition varies somewhat between languages. The Porter stemmer does not
use a pV explicitly, but the idea appears when the verb endings ing and ed are removed
only when preceded by a vowel. In English therefore pV would be defined as the
position after the first vowel.
The Porter stemmer is divided into five steps, step 1 is divided further into steps 1a, 1b
and 1c, and step 5 into steps 5a and 5b. Step 1 removes the i-suffixes, and steps 2 to 4
the d-suffixes (*). Composite d-suffixes are reduced to single d-suffixes one at a time.
So for example if a word ends icational, step 2 reduces it to icate and step 3 to ic. Three
steps are sufficient for this process in English. Step 5 does some tidying up.
One can see how easily the stemming rules translate into Snowball by comparing the
definition of Step 1a from the 1980 paper,
Step 1a:
SSES -> SS caresses -> caress
IES -> I ponies -> poni
ties -> ti
SS -> SS caress -> caress
S -> cats -> cat
The word to be stemmed is being scanned right to left from the end. The longest of
'sses', 'ies', 'ss' or 's' is searched for and defined as the slice. (If none are
found, Step_1a signals f.) If 'sses' is found, it is replaced by 'ss', and so on. Of
course, replacing 'ss' by 'ss' is a dummy action, so we can write
'ss' ()
instead of
'ss' (<-'ss')
The really tricky part of the whole algorithm is step 1b, which may be worth looking at
in detail. Here it is, without the example words on the far right,
Step 1b:
(m > 0) EED -> EE
(*v*) ED ->
(*v*) ING ->
7 of 12 1/13/2016 5:43 PM
The Porter stemming algorithm http://snowball.tartarus.org/algorithms/porter/stemmer.html
AT -> ATE
BL -> BLE
IZ -> IZE
(*d and not (*L or *S or *Z)) -> single letter
(m = 1 and *o) -> E
The first part of the rule means that eed maps to ee if eed is in R1 (which is equivalent to
m > 0), or ed and ing are removed if they are preceded by a vowel. In Snowball this is
simply,
define Step_1b as (
[substring] among (
'eed' (R1 <-'ee')
'ed'
'ing' (test gopast v delete)
)
)
But this must be modified by the second part of the rule. *d indicates a test for double
letter consonant — bb, dd etc. *L, *S, *Z are tests for l, s, z. *o is a short vowel test — it
is matched by consonant-vowel-consonant, where the consonant on the right is not w, x
or y. If the short vowel test is satisfied, m = 1 is equivalent to the cursor being at p1. So
the second part of the rule means, map at, bl, iz to ate, ble, ize; map certain double letters
to single letters; and add e after a short vowel in words of one syllable.
(The v_WXY test comes first because we are scanning backwards, from right to left.)
The double to single letter map can be done as follows: first define the slice as the next
non-v_LSZ and copy it to a string, ch, as a single character,
strings ( ch )
....
[non-v_LSZ] ->ch
A further test, ch, tests that the next letter of the string is the same as the one in ch, and
if this gives signal t, delete deletes the slice,
[non-v_LSZ] ->ch ch delete
8 of 12 1/13/2016 5:43 PM
The Porter stemming algorithm http://snowball.tartarus.org/algorithms/porter/stemmer.html
But we can improve the appearance, and speed, of this by turning the second part of the
rule into another among command, noting that the only letters that need undoubling are
b, d, f, g, m, n, p, r and t,
define Step_1b as (
[substring] among (
'eed' (R1 <-'ee')
'ed'
'ing' (
test gopast v delete
test substring among(
'at' 'bl' 'iz'
(<+ 'e')
'bb' 'dd' 'ff' 'gg' 'mm' 'nn' 'pp' 'rr' 'tt'
// ignoring double c, h, j, k, q, v, w, and x
([next] delete)
'' (atmark p1 test shortv <+ 'e')
)
)
)
)
Note the null string in the second among, which acts as a default case.
The Porter stemmer in Snowball is given below. This is an exact implementation of the
algorithm described in the 1980 paper, unlike the other implementations distributed by
the author, which have, and have always had, three small points of difference (clearly
indicated) from the original algorithm. Since all other implementations of the algorithm
seen by the author are in some degree inexact, this may well be the first ever correct
implementation.
integers ( p1 p2 )
booleans ( Y_found )
routines (
shortv
R1 R2
Step_1a Step_1b Step_1c Step_2 Step_3 Step_4 Step_5a Step_5b
9 of 12 1/13/2016 5:43 PM
The Porter stemming algorithm http://snowball.tartarus.org/algorithms/porter/stemmer.html
externals ( stem )
groupings ( v v_WXY )
define v 'aeiouy'
define v_WXY v + 'wxY'
backwardmode (
define Step_1a as (
[substring] among (
'sses' (<-'ss')
'ies' (<-'i')
'ss' ()
's' (delete)
)
)
define Step_1b as (
[substring] among (
'eed' (R1 <-'ee')
'ed'
'ing' (
test gopast v delete
test substring among(
'at' 'bl' 'iz'
(<+ 'e')
'bb' 'dd' 'ff' 'gg' 'mm' 'nn' 'pp' 'rr' 'tt'
// ignoring double c, h, j, k, q, v, w, and x
([next] delete)
'' (atmark p1 test shortv <+ 'e')
)
)
)
)
define Step_1c as (
['y' or 'Y']
gopast v
<-'i'
)
define Step_2 as (
[substring] R1 among (
'tional' (<-'tion')
'enci' (<-'ence')
'anci' (<-'ance')
'abli' (<-'able')
'entli' (<-'ent')
'eli' (<-'e')
'izer' 'ization'
(<-'ize')
'ational' 'ation' 'ator'
(<-'ate')
'alli' (<-'al')
10 of 12 1/13/2016 5:43 PM
The Porter stemming algorithm http://snowball.tartarus.org/algorithms/porter/stemmer.html
'alism' 'aliti'
(<-'al')
'fulness' (<-'ful')
'ousli' 'ousness'
(<-'ous')
'iveness' 'iviti'
(<-'ive')
'biliti' (<-'ble')
)
)
define Step_3 as (
[substring] R1 among (
'alize' (<-'al')
'icate' 'iciti' 'ical'
(<-'ic')
'ative' 'ful' 'ness'
(delete)
)
)
define Step_4 as (
[substring] R2 among (
'al' 'ance' 'ence' 'er' 'ic' 'able' 'ible' 'ant' 'ement'
'ment' 'ent' 'ou' 'ism' 'ate' 'iti' 'ous' 'ive' 'ize'
(delete)
'ion' ('s' or 't' delete)
)
)
define Step_5a as (
['e']
R2 or (R1 not shortv)
delete
)
define Step_5b as (
['l']
R2 'l'
delete
)
)
define stem as (
unset Y_found
do ( ['y'] <-'Y' set Y_found)
do repeat(goto (v ['y']) <-'Y' set Y_found)
$p1 = limit
$p2 = limit
do(
gopast v gopast non-v setmark p1
gopast v gopast non-v setmark p2
)
backwards (
do Step_1a
do Step_1b
do Step_1c
do Step_2
do Step_3
11 of 12 1/13/2016 5:43 PM
The Porter stemming algorithm http://snowball.tartarus.org/algorithms/porter/stemmer.html
do Step_4
do Step_5a
do Step_5b
)
12 of 12 1/13/2016 5:43 PM