apply method

  1. @override
int apply(
  1. String s1,
  2. String s2
)
override

Returns the score of similarity computed from s1 and s2

Implementation

@override
int apply(String s1, String s2) {
  var len1 = s1.length;
  var len2 = s2.length;

  if (len1 == 0 || len2 == 0) {
    return 0;
  }

  var tryPartials = tryPartialsConst;
  var unbaseScale = unbaseScaleConst;
  var partialScale = partialScaleConst;

  var base = ratio(s1, s2);
  var lenRatio = max(len1, len2) / min(len1, len2);

  tryPartials = lenRatio >= 1.5;
  if (lenRatio > 8) partialScale = 0.6;

  if (tryPartials) {
    var partial = partialRatio(s1, s2) * partialScale;
    var partialSor =
        tokenSortPartialRatio(s1, s2) * unbaseScale * partialScale;
    var partialSet =
        tokenSetPartialRatio(s1, s2) * unbaseScale * partialScale;

    return [base, partial, partialSor, partialSet].reduce(max).round();
  } else {
    var tokenSort = tokenSortRatio(s1, s2) * unbaseScale;
    var tokenSet = tokenSetRatio(s1, s2) * unbaseScale;

    return [base, tokenSort, tokenSet].reduce(max).round();
  }
}