Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{"name": "porter-stemmer",
"description": "Martin Porter's stemmer wrapped in CommonJS for use in node.js",
"version": "0.9.1",
"version": "0.9.3",

"authors": ["Jed Parsons <jed@jedparsons.com> (http://jedparsons.com)",
"Christoper McKenzie <cmckenzie@iizuu.com> (http://qaa.ath.cx/porter_js_demo.html",
Expand Down
6 changes: 5 additions & 1 deletion porter.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,14 @@
}

// memoize at the module level
var memo = {};
var memo = Object.create(null);
var memoizingStemmer = function(w) {
if (!memo[w]) {
memo[w] = stemmer(w);
// the stemmed output should stem to itself, cache this too for a small performance boost
if (w !== memo[w]) {
memo[memo[w]] = memo[w];
}
}
return memo[w];
}
Expand Down
1 change: 1 addition & 0 deletions test/input.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4355,6 +4355,7 @@ constrains
constraint
constring
construction
constructor
construe
consul
consuls
Expand Down
8 changes: 8 additions & 0 deletions test/memoizing_stemmer_vows.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ vows.describe('The memoizing stemmer')
assert(results[0] === results[1]);
}
}
},
"passes Dr Porter's test": function() {
var vocabulary = fs.readFileSync('./input.txt').toString().trim().split('\n');
var expected = fs.readFileSync('./output.txt').toString().trim().split('\n');

for (var i=0; i<vocabulary.length; i++) {
assert(memoizingStemmer(vocabulary[i]) === expected[i]);
}
}
})

Expand Down
1 change: 1 addition & 0 deletions test/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4355,6 +4355,7 @@ constrain
constraint
constr
construct
constructor
constru
consul
consul
Expand Down