markfullmer / porter2 Goto Github PK
View Code? Open in Web Editor NEWA PHP implementation of the English (Porter 2) Stemmer.
Home Page: https://stemmer.markfullmer.com/demo/
License: MIT License
A PHP implementation of the English (Porter 2) Stemmer.
Home Page: https://stemmer.markfullmer.com/demo/
License: MIT License
The algorithm is giving different results for 'office' (as 'offic') and 'Office' (as 'office').
I don't know if this is a part of implementation but for this case, the stemmed versions should not be different. This difference is caused probably by the isVowel function that operates on vowel set of (a,e,i,o,u,y) and not (A,E,I,O,U,Y). I modified the function isVowel
protected static function isVowel($position, $word, array $additional = array()) {
$vowels = array_merge(array('a', 'e', 'i', 'o', 'u', 'y'), $additional); //lowercase vowels only
return in_array(self::charAt($position, $word), $vowels);
}
to operatore on $word in lowercase:
protected static function isVowel($position, $word, array $additional = array()) {
$vowels = array_merge(array('a', 'e', 'i', 'o', 'u', 'y'), $additional); //lowercase vowels only
return in_array(self::charAt($position, strtolower($word)), $vowels); //changed parameter word to lowercase
}
This had solved this issue.
There is different output for 'Bearing' and 'bearing' and that is (obviously) not solved by this modification. This needs another modification and before I post that, I may need insights of OP or programmers having decent knowledge of PorterStemmer2 on whether this is in accordance with the algorithm or not.
Well, to the programmers using this library - convert string to lowercase before passing into the entry function.
I ran the code on all 29418 stem example given at https://snowballstem.org/algorithms/english/stemmer.html (Sample English vocabulary, Its stemmed equivalent). It only failed on one :-) - "freely" stemmed to "free", it should stem to "freeli".
In step2 there should be a check to see if the ending is in R1 when the ending is "li" (as well as for all the other endings). So:
if (self::hasEnding($word, 'li')) {
if (strlen($word) > 4 && self::validLi(self::charAt(-3, $word))) {
$word = self::removeEnding($word, 'li');
}
}
should be replaced with:
if (self::inR1($word, "li") && self::hasEnding($word, 'li')) {
if (strlen($word) > 4 && self::validLi(self::charAt(-3, $word))) {
$word = self::removeEnding($word, 'li');
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.