You are here

function porterstemmer_short_word in Porter-Stemmer 7

Same name and namespace in other branches
  1. 6.2 porterstemmer.module \porterstemmer_short_word()

Checks to see if a word is considered "short" in Porter Stemmer 2.

A word is "short" if region R1 doesn't exist, and if it ends in a short syllable. A short syllable is consonant, followed by vowel, followed by consonant not w, x, Y; or else vowel starting a word, followed by a non-vowel.

Parameters

string $word: Word to check.

int $r1: Start position of R1 region in word.

Return value

bool TRUE if the word is short, false if not.

2 calls to porterstemmer_short_word()
PorterStemmerInternalsUnitTest::testShortWord in ./porterstemmer.test
Tests the function that determines if a word is "short".
porterstemmer_step1b in includes/standard-stemmer.inc
Step 1b of algorithm: eed, eedly, ed, edly, ing, ingly.

File

includes/standard-stemmer.inc, line 176
This is an implementation of the Porter 2 Stemming algorithm.

Code

function porterstemmer_short_word($word, $r1) {
  if (drupal_strlen($word) > $r1) {

    // R1 region exists, so this is not a short word.
    return FALSE;
  }

  // Does it end in one type of short syllable?
  if (preg_match('/^' . PORTERSTEMMER_VOWEL . PORTERSTEMMER_NOT_VOWEL . '$/', $word)) {
    return TRUE;
  }

  // Does it end in the other type of short syllable?
  if (preg_match('/' . PORTERSTEMMER_NOT_VOWEL . PORTERSTEMMER_VOWEL . PORTERSTEMMER_NOT_VOWEL_WXY . '$/', $word)) {
    return TRUE;
  }
  return FALSE;
}