From 2f9af449ece1ae1cc88ce6e21246aaff68de46b1 Mon Sep 17 00:00:00 2001 From: Psychedelic Squid Date: Fri, 2 Mar 2012 02:50:31 +0000 Subject: [PATCH 1/6] New regex in place, but the matching pattern changes a little, so I think it probably would break if nothing else is changed. Need to spin up a node server so I can test live. --- modules/spelling.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/spelling.js b/modules/spelling.js index 37b906d..ea0f581 100644 --- a/modules/spelling.js +++ b/modules/spelling.js @@ -36,7 +36,7 @@ var spelling = function(dbot) { return { 'listener': function(data, params) { - var q = data.message.valMatch(/^\*\*?([\d\w\s']*)$/, 2); + var q = data.message.valMatch(/^(?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 2); var otherQ = data.message.valMatch(/^([\d\w\s]*): \*\*?([\d\w\s']*)$/, 3); if(q) { correct(data, q[1], data.user, function (e) { From ad6b354dafc4d8c6bacb894037943a99b54b3b44 Mon Sep 17 00:00:00 2001 From: Psychedelic Squid Date: Tue, 6 Mar 2012 16:34:18 +0000 Subject: [PATCH 2/6] After actually learning how valMatch works, this motherfucker is ready to roll. --- modules/spelling.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/spelling.js b/modules/spelling.js index ea0f581..3dc85e1 100644 --- a/modules/spelling.js +++ b/modules/spelling.js @@ -36,14 +36,14 @@ var spelling = function(dbot) { return { 'listener': function(data, params) { - var q = data.message.valMatch(/^(?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 2); - var otherQ = data.message.valMatch(/^([\d\w\s]*): \*\*?([\d\w\s']*)$/, 3); + var q = data.message.valMatch(/^(?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 3); + var otherQ = data.message.valMatch(/^([\d\w\s]*): (?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 4); if(q) { - correct(data, q[1], data.user, function (e) { + correct(data, q[1] || q[2], data.user, function (e) { dbot.say(data.channel, e.correcter + ' meant: ' + e.fix); }); } else if(otherQ) { - correct(data, otherQ[2], otherQ[1], function (e) { + correct(data, otherQ[2] || otherQ[3], otherQ[1], function (e) { dbot.say(data.channel, e.correcter + ' thinks ' + e.candidate + ' meant: ' + e.fix); }); } else { From 4e2d4017d0a855f1a18bab8c53e8e3e32811ece5 Mon Sep 17 00:00:00 2001 From: Psychedelic Squid Date: Tue, 6 Mar 2012 22:02:52 +0000 Subject: [PATCH 3/6] Check all groupings of words for corrections; makes multi-word corrections behave properly. --- modules/spelling.js | 12 +++++++----- snippets.js | 13 +++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/modules/spelling.js b/modules/spelling.js index 3dc85e1..0f286cc 100644 --- a/modules/spelling.js +++ b/modules/spelling.js @@ -3,23 +3,25 @@ var spelling = function(dbot) { var last = {}; var correct = function (data, correction, candidate, output_callback) { - var candidates = last[data.channel][candidate].split(' '); + var rawCandidates = last[data.channel][candidate].split(' ').allGroupings(); + var candidates = []; + for(var i=0;i Date: Tue, 6 Mar 2012 22:19:11 +0000 Subject: [PATCH 4/6] Sanity check; don't want to match against identical words to the correction. --- modules/spelling.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/spelling.js b/modules/spelling.js index 0f286cc..4f43e83 100644 --- a/modules/spelling.js +++ b/modules/spelling.js @@ -13,7 +13,7 @@ var spelling = function(dbot) { for(var i=0;i 0)) { winner = candidates[i]; winnerDistance = distance; } From 68943d6c8f55ce559fcfff493fefd0e7c030fbf5 Mon Sep 17 00:00:00 2001 From: Psychedelic Squid Date: Tue, 6 Mar 2012 22:58:04 +0000 Subject: [PATCH 5/6] Make max winner distance proportional to correction length, so long strings can match. --- modules/spelling.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/spelling.js b/modules/spelling.js index 4f43e83..edd4fff 100644 --- a/modules/spelling.js +++ b/modules/spelling.js @@ -19,7 +19,7 @@ var spelling = function(dbot) { } } - if(winnerDistance < 7) { + if(winnerDistance < Math.ceil(correction.length * 1.33)) { if(winner !== correction) { var fix = last[data.channel][candidate].replace(winner, correction); if (/^.ACTION/.test(fix)) { From a83b1c2bd5ca5f8ac1437d096127fa54c69a5c4e Mon Sep 17 00:00:00 2001 From: Psychedelic Squid Date: Tue, 6 Mar 2012 23:04:37 +0000 Subject: [PATCH 6/6] Argh! winner, not correction. Old code would match _anything_, not good. --- modules/spelling.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/spelling.js b/modules/spelling.js index edd4fff..5ce2605 100644 --- a/modules/spelling.js +++ b/modules/spelling.js @@ -19,7 +19,7 @@ var spelling = function(dbot) { } } - if(winnerDistance < Math.ceil(correction.length * 1.33)) { + if(winnerDistance < Math.ceil(winner.length * 1.33)) { if(winner !== correction) { var fix = last[data.channel][candidate].replace(winner, correction); if (/^.ACTION/.test(fix)) {