anchor.diff:            candidateWeight = candidate.length / token.length;
           } else {
             final candidateNgrams = ngrams(candidate, _minLength, 6);
  -          candidateWeight = _ngramSimilarity(tokenNgrams, candidateNgrams);
  +          tokenWeightSum ??= tokenNgrams.fold<double>(0.0, _ngramWeightSum);
  +          candidateWeight =
  +              _ngramSimilarity(tokenNgrams, candidateNgrams, tokenWeightSum);
           }
           candidateWeight *= tokens[token];
           if (candidateWeight > 0.3) {
  
positive.code:     return tokenMatch;
    }
  
    // Weighted Jaccard-similarity metric of sets of strings.
    double _ngramSimilarity(Set<String> a, Set<String> b) {
      final intersection = a.intersection(b);
      if (intersection.isEmpty) return 0.0;
  
      double sumFn(double sum, String str) =>
          sum + math.min<double>(100.0, math.pow(str.length, 1.5).toDouble());
  
      final intersectionWeight = intersection.fold<double>(0, sumFn);
      final supersetWeight = a.fold<double>(0, sumFn) +
          b.fold<double>(0, sumFn) -
          intersectionWeight;
      return intersectionWeight / supersetWeight;
    }
  
  
negative.code:     return scoreDocs(lookupTokens(text));
    }
  }
  
  /// Pre-calculated weight list for ngram similarity.
  final _ngramSimilarityWeights =
      List<double>.generate(20, (i) => math.pow(i, 1.5).toDouble());
  