correctWord method

String? correctWord(
  1. List<String> expectedWords, {
  2. bool safetyBack = false,
})

Implementation

String? correctWord(List<String> expectedWords, {bool safetyBack = false}) {
  /// define zero initial and increase when add similar from word
  /// this is same with confidence in AI
  double highestSimilarity = 0.0;
  String closestWord = this;

  for (final word in expectedWords) {
    final double similarity = similarityTo(word);
    if (similarity > highestSimilarity) {
      highestSimilarity = similarity;
      closestWord = word;
    }
  }

  if (!safetyBack && highestSimilarity < 0.5) {
    return null;
  }
  return closestWord;
}