I already know many edit-distance algorithm implementations in javascript, but I want to calculate the text similarity in percentage based on it. Does anyone know how to implement it?
You have to find the maximum possible distance between a string of length n
and a string of length m
. If for example this maximum distance is n + m
then the percentage will be
100 - 100 * edit_distance(a, b) / (a.length + b.length)
If for example you use Levenshtein distance where each insert, replacement, deletion has cost 1
then this maximum possible distance is max(n, m)
and so the percentage will be
100 - 100 * Levenshtein(a, b) / Math.max(a.length, b.length)