Skip to content

Commit edc34c6

Browse files
committed
Finalized greek stemmer
* Added tests * Moved stemmer testing code to a separate class
1 parent 774ee18 commit edc34c6

File tree

6 files changed

+196
-12
lines changed

6 files changed

+196
-12
lines changed

src/NlpTools/Stemmers/GreekStemmer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* http://people.dsv.su.se/~hercules/papers/Ntais_greek_stemmer_thesis_final.pdf
99
*
1010
* It was first ported to php by P. Kyriakakis.
11+
* This stemmer expects lower case characters and not upper case.
1112
*/
1213
class GreekStemmer extends Stemmer
1314
{

tests/NlpTools/Stemmers/GreekStemmerTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,24 @@
22

33
namespace NlpTools\Stemmers;
44

5-
class GreekStemmerTest extends \PHPUnit_Framework_TestCase
5+
class GreekStemmerTest extends StemmerTestBase
66
{
77
/**
88
* Test the words found in Appendix A from Mr. Ntais's thesis.
9+
*
10+
* The words are not tested against the stem reported in the appendix
11+
* but against the results of Mr. Ntais's canonical implementation in js
12+
* found here http://people.dsv.su.se/~hercules/greek_stemmer.gr.html
913
*/
1014
public function testFromAppendixA()
1115
{
12-
$this->fail("This test is not yet implemented");
16+
$words = new \SplFileObject(TEST_DATA_DIR.'/Stemmers/GreekStemmerTest/appendix-a-words');
17+
$stems = new \SplFileObject(TEST_DATA_DIR.'/Stemmers/GreekStemmerTest/appendix-a-stems');
18+
$words->setFlags(\SplFileObject::DROP_NEW_LINE | \SplFileObject::SKIP_EMPTY);
19+
$stems->setFlags(\SplFileObject::DROP_NEW_LINE | \SplFileObject::SKIP_EMPTY);
20+
$stems->rewind();
21+
22+
$stemmer = new GreekStemmer();
23+
$this->checkStemmer($stemmer, $words, $stems);
1324
}
1425
}

tests/NlpTools/Stemmers/PorterStemmerTest.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* words.txt and stems.txt are taken from
99
* http://tartarus.org/~martin/PorterStemmer/
1010
*/
11-
class PorterStemmerTest extends \PHPUnit_Framework_TestCase
11+
class PorterStemmerTest extends StemmerTestBase
1212
{
1313
/**
1414
* Load a set of words and their stems and check if the stemmer
@@ -25,14 +25,6 @@ public function testStemmer()
2525
$stems->rewind();
2626

2727
$stemmer = new PorterStemmer();
28-
foreach ($words as $word) {
29-
$stem = $stems->current();
30-
$this->assertEquals(
31-
$stemmer->stem($word),
32-
$stem,
33-
"The stem for '$word' should be '$stem' not '{$stemmer->stem($word)}'"
34-
);
35-
$stems->next();
36-
}
28+
$this->checkStemmer($stemmer, $words, $stems);
3729
}
3830
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace NlpTools\Stemmers;
4+
5+
/**
6+
* This class simply provides a bit of functioanlity to test
7+
* a stemmer agains two lists of words and stems just to keep
8+
* the test code a bit DRY
9+
*/
10+
class StemmerTestBase extends \PHPUnit_Framework_TestCase
11+
{
12+
protected function checkStemmer(Stemmer $stemmer, \Iterator $words, \Iterator $stems)
13+
{
14+
foreach ($words as $word) {
15+
$stem = $stems->current();
16+
$this->assertEquals(
17+
$stemmer->stem($word),
18+
$stem,
19+
"The stem for '$word' should be '$stem' not '{$stemmer->stem($word)}'"
20+
);
21+
$stems->next();
22+
}
23+
}
24+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
αυτοκινησ
2+
υδροθεραπει
3+
αυτοκινησ
4+
υδροθεραπει
5+
αυτοκινητ
6+
υδροθεραπει
7+
αυτοκινητ
8+
υδροθεραπει
9+
αυτοκινητ
10+
παιδοποδηλατ
11+
αυτοκινητ
12+
παιδοποδηλατ
13+
αυτοκινητ
14+
παιδοποδηλατ
15+
αυτοκινητ
16+
παιδοποδηλατ
17+
αυτοκινητ
18+
παιδοποδηλατ
19+
αυτοκινητ
20+
παιδοποδηλατ
21+
αυτοκινητ
22+
βροχοχορευ
23+
αυτοκινητ
24+
βροχοχορευ
25+
αυτοκινητ
26+
βροχοχορευ
27+
χορδιζ
28+
βροχοχορευ
29+
χορδιζ
30+
βροχοχορεψ
31+
χορδιζατ
32+
βροχοχορεψ
33+
χορδιζ
34+
βροχοχορεψ
35+
χορδιζ
36+
βροχοχορεψ
37+
χορδιζ
38+
επιτροπ
39+
χορδιζομ
40+
επιτροπ
41+
χορδιζ
42+
επιτροπ
43+
χορδιζ
44+
επιτροπ
45+
χορδιζ
46+
επιτροπ
47+
χορδιζ
48+
επιτροπ
49+
χορδιζ
50+
βορειοασιατ
51+
χορδιξ
52+
βορειοασιατικ
53+
χορδισ
54+
βορειοασιατικ
55+
χορδισ
56+
βορειοασιατικ
57+
μελλον
58+
βορειοασιατικ
59+
μελλοντ
60+
βορειοασιατικ
61+
μελλοντ
62+
βορειοασιατ
63+
μελλ
64+
βορειοασιατικ
65+
μελλοντ
66+
βορειοασιατ
67+
μελλοντ
68+
βορειοασιατικ
69+
αρει
70+
βορειοασιατ
71+
αρει
72+
υπομελ
73+
αρει
74+
υπομελ
75+
αρει
76+
υπομελ
77+
αρει
78+
υπομελ
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
αυτοκινηση
2+
υδροθεραπεια
3+
αυτοκινησησ
4+
υδροθεραπειασ
5+
αυτοκινητα
6+
υδροθεραπειεσ
7+
αυτοκινητε
8+
υδροθεραπειων
9+
αυτοκινητεσ
10+
παιδοποδηλατα
11+
αυτοκινητη
12+
παιδοποδηλατο
13+
αυτοκινητη
14+
παιδοποδηλατου
15+
αυτοκινητο
16+
παιδοποδηλατων
17+
αυτοκινητοι
18+
παιδοποδηλατου
19+
αυτοκινητοσ
20+
παιδοποδηλατων
21+
αυτοκινητου
22+
βροχοχορευα
23+
αυτοκινητουσ
24+
βροχοχορευαν
25+
αυτοκινητων
26+
βροχοχορευε
27+
χορδιζαμε
28+
βροχοχορευεσ
29+
χορδιζανε
30+
βροχοχορεψα
31+
χορδιζατε
32+
βροχοχορεψαν
33+
χορδιζει
34+
βροχοχορεψε
35+
χορδιζεισ
36+
βροχοχορεψεσ
37+
χορδιζετε
38+
επιτροπο
39+
χορδιζομε
40+
επιτροποι
41+
χορδιζοντασ
42+
επιτροποσ
43+
χορδιζουμε
44+
επιτροπου
45+
χορδιζουν
46+
επιτροπουσ
47+
χορδιζουνε
48+
επιτροπων
49+
χορδιζω
50+
βορειοασιατικα
51+
χορδιξει
52+
βορειοασιατικε
53+
χορδισαμε
54+
βορειοασιατικεσ
55+
χορδισαν
56+
βορειοασιατικη
57+
μελλον
58+
βορειοασιατικησ
59+
μελλοντα
60+
βορειοασιατικοι
61+
μελλοντ
62+
βορειοασιατικου
63+
μελλοντασ
64+
βορειοασιατικουσ
65+
μελλοντεσ
66+
βορειοασιατικο
67+
μελλοντοσ
68+
βορειοασιατικοσ
69+
αρειε
70+
βορειοασιατικων
71+
αρειο
72+
υπομελη
73+
αρειοι
74+
υπομελοσ
75+
αρειοσ
76+
υπομελουσ
77+
αρειου
78+
υπομελων

0 commit comments

Comments
 (0)