File tree Expand file tree Collapse file tree 3 files changed +70
-1
lines changed
tests/TextAnalysis/Stemmers Expand file tree Collapse file tree 3 files changed +70
-1
lines changed Original file line number Diff line number Diff line change 27
27
"php" : " >=5.5" ,
28
28
"yooper/stop-words" : " ^1.0" ,
29
29
"symfony/console" : " >=2.7" ,
30
- "camspiers/porter-stemmer" : " 1.0.*"
30
+ "camspiers/porter-stemmer" : " 1.0.*" ,
31
+ "wamania/php-stemmer" : " 1.2"
31
32
},
32
33
"require-dev" : {
33
34
"phpunit/phpunit" : " 5.*" ,
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace TextAnalysis \Stemmers ;
4
+
5
+ use TextAnalysis \Interfaces \IStemmer ;
6
+
7
+ /**
8
+ * A wrapper around PHP native snowball implementation
9
+ * @author yooper
10
+ */
11
+ class SnowballStemmer implements IStemmer
12
+ {
13
+ const BASE_NAMESPACE = '\\Wamania \\Snowball \\' ;
14
+
15
+ /**
16
+ *
17
+ * @var \Wamania\Snowball\Stem
18
+ */
19
+ protected $ stemmer ;
20
+
21
+ public function __construct ($ stemmerType = 'English ' )
22
+ {
23
+ $ className = self ::BASE_NAMESPACE .$ stemmerType ;
24
+ if (!class_exists ($ className )) {
25
+ throw new \RuntimeException ("Class {$ stemmerType } does not exist " );
26
+ }
27
+ $ this ->stemmer = new $ className ();
28
+ }
29
+
30
+ public function stem ($ token )
31
+ {
32
+ return $ this ->stemmer ->stem ($ token );
33
+ }
34
+
35
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Tests \TextAnalysis \Stemmers ;
4
+
5
+ use TextAnalysis \Stemmers \SnowballStemmer ;
6
+
7
+ /**
8
+ *
9
+ * @author yooper
10
+ */
11
+ class SnowballStemmerTest extends \PHPUnit_Framework_TestCase
12
+ {
13
+ public function testDefaultEnglish ()
14
+ {
15
+ $ stemmer = new SnowballStemmer ('English ' );
16
+ $ this ->assertEquals ("judg " , $ stemmer ->stem ("judges " ));
17
+ $ this ->assertEquals ('ski ' , $ stemmer ->stem ('skis ' ));
18
+ $ this ->assertEquals ('univers ' , $ stemmer ->stem ('universities ' ));
19
+ $ this ->assertEquals ('news ' , $ stemmer ->stem ('news ' ));
20
+ }
21
+
22
+ public function testSwedish ()
23
+ {
24
+ $ stemmer = new SnowballStemmer ('Swedish ' );
25
+ $ this ->assertEquals ("affärschef " , $ stemmer ->stem ("affärscheferna " ));
26
+ }
27
+
28
+ public function testException ()
29
+ {
30
+ $ this ->setExpectedException ('Exception ' );
31
+ $ stemmer = new SnowballStemmer ('Wookie ' );
32
+ }
33
+ }
You can’t perform that action at this time.
0 commit comments