diff --git a/lib/natural/distance/dice_coefficient.js b/lib/natural/distance/dice_coefficient.js index 75db0dd1d..adafd907b 100644 --- a/lib/natural/distance/dice_coefficient.js +++ b/lib/natural/distance/dice_coefficient.js @@ -51,7 +51,7 @@ function intersect (set1, set2) { function sanitize (str) { // Turn characters to lower string, remove space at the beginning and end, // replace multiple spaces in the middle by single spaces - return str.toLowerCase().replace(/^\s+|\s+$/g, '').replace(/s+/g, ' ') + return str.toLowerCase().replace(/\s+/g, ' ').replace(/^\s+|\s+$/g, '') } function diceCoefficient (str1, str2) { diff --git a/spec/dice_coefficient_spec.js b/spec/dice_coefficient_spec.js index aede7a124..cb4dcb5e6 100644 --- a/spec/dice_coefficient_spec.js +++ b/spec/dice_coefficient_spec.js @@ -32,6 +32,6 @@ describe('dice', function () { it('should compare complete texts', function () { const text1 = require('./test_data/Wikipedia_EN_FrenchRevolution.json').text const text2 = require('./test_data/Wikipedia_EN_InfluenceOfTheFrenchRevolution.json').text - expect(dice(text1, text2)).toBe(0.7897503285151117) + expect(dice(text1, text2)).toBe(0.7939374395356337) }) })