Coder Social home page Coder Social logo

markfullmer / porter2 Goto Github PK

View Code? Open in Web Editor NEW
16.0 2.0 7.0 270 KB

A PHP implementation of the English (Porter 2) Stemmer.

Home Page: https://stemmer.markfullmer.com/demo/

License: MIT License

PHP 100.00%
stemmer porter php corpus search-algorithm

porter2's People

Contributors

markfullmer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

porter2's Issues

Different results for Title Case

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.

Step 2, "li" ending - should check if the ending is in R1

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');
      }
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.