You are here

public function TestItemsTrait::retrieveStemWords in Porter-Stemmer 8

Load an associative array of known input/output pairs.

This list comes from http://snowball.tartarus.org/algorithms/english/stemmer.html The array count is determined by parameters, below.

Parameters

int $skipto: Line of file to start on (count starts at 0), not counting short ones.

int $runto: Number of lines to test, not counting short ones.

Return value

str[] An associative array of word=stem pairs where element [0] is the word and element [1] is the expected stem.

12 calls to TestItemsTrait::retrieveStemWords()
Porter2Pecl1::stemDataProvider in tests/src/Unit/Porter2Pecl1.php
Data provider for testStem().
Porter2Pecl2::stemDataProvider in tests/src/Unit/Porter2Pecl2.php
Data provider for testStem().
Porter2Pecl3::stemDataProvider in tests/src/Unit/Porter2Pecl3.php
Data provider for testStem().
Porter2Pecl4::stemDataProvider in tests/src/Unit/Porter2Pecl4.php
Data provider for testStem().
Porter2Pecl5::stemDataProvider in tests/src/Unit/Porter2Pecl5.php
Data provider for testStem().

... See full list

File

tests/src/Unit/TestItemsTrait.php, line 26

Class

TestItemsTrait
Provides a common method for testing the stemmer.

Namespace

Drupal\Tests\porterstemmer\Unit

Code

public function retrieveStemWords($skipto = 0, $runto = 5000) {
  $file = __DIR__ . '/testwords.txt';
  $handle = @fopen($file, "r");
  $tests = [];
  $skipped = 0;
  $ran = 0;
  while (!feof($handle) && $ran < $runto) {

    // Read a line of the file, and split into words.
    $line = trim(fgets($handle, 4096));
    $words = preg_split("/=/", $line, -1, PREG_SPLIT_NO_EMPTY);
    if (count($words) < 2) {
      continue;
    }
    $skipped++;
    if ($skipped < $skipto) {
      continue;
    }
    $tests[] = $words;
    $ran++;
  }
  fclose($handle);
  return $tests;
}