best guess / close match / misspelt name

poyntzj
Kilo Sage

Not quite sure how to phrase this

We have a order guide that currently has an option to allow the user to request 10 new users to access a site.

each needs to be filled in and then each is approved.

It works, however now the same team want a "bulk" import.

I have coded this and they can import via a text box using a specific format.

The routine currently processes each line, does whatever checking it can and if it passes, creates a new cart item and as many RITM's as needed

all works great.

What they now want is instead of importing 25 users and someone getting 25 approvals, they want a single approval request. - OK easy

however, besides allowing the approver to Approve / Reject, they want to have an "Approve with exceptions"

I have done this before for a mobile request where the approver can either approve but force a downgrade of the model of phone, or approve, but only from the best available phone from "stock".

This works as it is based purely on the subject so I can work with it.

My concern with this current option is the following

If the approver were to use the "Approve with exceptions", it would be down to them to type the name(s) correctly. I expect a few typo's and to then give someone site access when they have really been rejected

For example

One of the users on the list something like

Toni Ayest

The approver clicks on the "Approve with exceptions".

the mail message is created and in the body the approver types in

Tony Ayerst

I was looking / reading up on Fuzzy Logic / Levenshtein distances and double metaphone

before I start to delve into this, I wondered if anyone here and done anything similar

1 ACCEPTED SOLUTION

poyntzj
Kilo Sage

OK, not taking the credit here, I'll leave this to Kiro Risk


I followed this and make a Script Include of his Fuse script


Fuse.js | K. Risk - JavaScript Refined



Using the following, it shows I can do what I will need


I can look at the approval email, extract the people the approver has rejected and add to an array arrAppReject


As I then process through the list, I can then simply call the Fuse Script Include and see if the current user I am working on is in the reject list


If so, ignore them, if not, then add them



this little background script is a basic POC, - based on some simple spelling mistakes



var arrAppReject = ['johnathan.lane','julian points'];



var arrUser = ['julian.poyntz','john.mccormack','jonathan.lane','nicholas.godfrey','harry.kha', 'douglas.oram'];


var f = new Fuse(arrAppReject);


for (i=0; i < arrUser.length; i++)


{


      if (JSUtil.nil(f.search(arrUser[i])))


              gs.print('No match');


      else


              gs.print('Close on ' + arrUser[i]);


}



Cheers


View solution in original post

2 REPLIES 2

poyntzj
Kilo Sage

OK, not taking the credit here, I'll leave this to Kiro Risk


I followed this and make a Script Include of his Fuse script


Fuse.js | K. Risk - JavaScript Refined



Using the following, it shows I can do what I will need


I can look at the approval email, extract the people the approver has rejected and add to an array arrAppReject


As I then process through the list, I can then simply call the Fuse Script Include and see if the current user I am working on is in the reject list


If so, ignore them, if not, then add them



this little background script is a basic POC, - based on some simple spelling mistakes



var arrAppReject = ['johnathan.lane','julian points'];



var arrUser = ['julian.poyntz','john.mccormack','jonathan.lane','nicholas.godfrey','harry.kha', 'douglas.oram'];


var f = new Fuse(arrAppReject);


for (i=0; i < arrUser.length; i++)


{


      if (JSUtil.nil(f.search(arrUser[i])))


              gs.print('No match');


      else


              gs.print('Close on ' + arrUser[i]);


}



Cheers


Ok, so after some testing and getting my main routine refined, I saw some odd results when I loaded up with more test records.


Transpires that at the moment, FUSE has a limitation of 32 characters and some the email addresses I am scanning for are more than that. - argh



So, now using this in a Script Include and then calling it via a couple of loop routines


For what I am after which is the checking of the odd spelling mistake, a return value of 4 or less is enough for me to indicate it is a match and the user was not approved.



function levenshtein(str1, str2) {


      var m = str1.length,


              n = str2.length,


              d = [],


              i, j;



      if (!m) return n;


      if (!n) return m;



      for (i = 0; i <= m; i++) d[i] = [i];


      for (j = 0; j <= n; j++) d[0][j] = j;



      for (j = 1; j <= n; j++) {


              for (i = 1; i <= m; i++) {


                      if (str1[i-1] == str2[j-1]) d[i][j] = d[i - 1][j - 1];


                      else d[i][j] = Math.min(d[i-1][j], d[i][j-1], d[i-1][j-1]) + 1;


              }


      }


      return d[m][n];


}