osaStringSimilarity function

double osaStringSimilarity(
  1. String a,
  2. String b
)

Levenshtein distance is a string metric for measuring the difference between two sequences. Informally, the Levenshtein distance between two words is the minimum number of single-character edits (insertions, deletions or substitutions) required to change one word into the other

Implementation

double osaStringSimilarity(String a, String b) {
  int distance = osaDistance(a.codeUnits, b.codeUnits);
  int maxLength = a.length > b.length ? a.length : b.length;
  double similarity = 1 - (distance / maxLength);
  return similarity;
}