From 5144a0d26ccafc5a3f243a7828ea9f5b9717c352 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Thu, 4 Oct 2012 15:24:01 +0200 Subject: [PATCH] improved matching of featured artists --- lib/match.js | 66 +++++++++++++++++++++++++--------------------------- lib/room.js | 28 +++++++++++----------- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/lib/match.js b/lib/match.js index 196c6ca..a827441 100644 --- a/lib/match.js +++ b/lib/match.js @@ -6,6 +6,7 @@ * See Algorithms on strings, trees, and sequences: computer science and computational biology. * Cambridge, UK: Cambridge University Press. pp 263-264. ISBN 0-521-58519-8. */ + var checkDistance = function(s1, s2, k) { if (k === 0) { return s1 === s2; @@ -45,7 +46,7 @@ var checkDistance = function(s1, s2, k) { }; /** - * Return `amatch` function. + * Expose `amatch` function. */ module.exports = function(allowederrors) { @@ -61,76 +62,73 @@ module.exports = function(allowederrors) { return true; } - var splitted, trimmed; - // Ignore dots - if (subject.match(/\./) && - checkDistance(subject.replace(/\./g, ""), guess, threshold)) { - return true; - } - // Ignore commas - if (subject.match(/,/) && - checkDistance(subject.replace(/,/g, ""), guess, threshold)) { + if (/\./.test(subject) && + checkDistance(subject.replace(/\./g, ''), guess, threshold)) { return true; } // Ignore dashes - if (subject.match(/\-/) && - checkDistance(subject.replace(/\-/g, ""), guess, threshold)) { + if (/\-/.test(subject) && + checkDistance(subject.replace(/\-/g, ''), guess, threshold)) { return true; } // Allow to write "and" in place of "+" - if (subject.match(/\+/) && - checkDistance(subject.replace(/\+/, "and"), guess, threshold)) { + if (/\+/.test(subject) && + checkDistance(subject.replace(/\+/, 'and'), guess, threshold)) { + return true; + } + // Allow to write "and" in place of " & " + if (/ & /.test(subject) && !/\(/.test(subject) && + checkDistance(subject.replace(/ & /, ' and '), guess, threshold)) { return true; } if (enableartistrules) { // Ignore "the" at the beginning of artist name - if (subject.match(/^the /)) { - var nothe = subject.replace(/^the /, ""); + if (/^the /.test(subject)) { + var nothe = subject.replace(/^the /, ''); if (checkDistance(nothe, guess, threshold)) { return true; } - if (nothe.match(/jimi hendrix experience/) && - checkDistance(nothe.replace(/ experience/, ""), guess, threshold)) { + if (/jimi hendrix experience/.test(nothe) && + checkDistance(nothe.replace(/ experience/, ''), guess, threshold)) { return true; } } - // Split artist name on "&" (artist name can be composed by more names) - splitted = subject.split("&"); + // Split artist name on " & " and ", " (artist name can be composed by more names) + var splitted = subject.split(/ & |, /); if (splitted.length !== 1) { for (var i=0; i