BuiltOnAir

Linking Script Block using the Levenshtein Distance Algorithm

Created by: Creator: Jonathan Bowen

Algorithms

My linking script block entry is an implementation of the Levenshtein Distance Algorithm to suggest links between two sets/tables of data. The algorithm produces a metric that determines how alike two strings are and in this base, we make a link between the records that are “sufficiently” similar.

This script could be used to match two sets of data – for example a “master” customer list and a second set of customer data from another source. The script would suggest that, perhaps “Mr Jonathon Bowe” could be matched with “Jonathan Bowen”.

Check out the Airtable Universe base with this script in action here.

See the source for examples and how to use the script.

Script Code


							// Levenshtein distance function
let levenshteinDistance = function(a, b){
    if(!a || !b) return (a || b).length;
    var m = [];
    for(var i = 0; i <= b.length; i++){
        m[i] = [i];
        if(i === 0) continue;
        for(var j = 0; j  Number(inputRatio)) {
            // add the master id to the array
            matchedIds.push(
                {id: masterRecord.id}
            )
        }
    }
    // update the match record with the array of master ids
    let update = await matchTable.updateRecordAsync(matchRecord, {
            "Suggested Link to Master": matchedIds
        }
    );
}