replaceWord method

String replaceWord(
  1. Map<String, String> replaceMap,
  2. Map<String, String> keepMap,
  3. List<List> rules,
  4. String word,
)

Replace a word with the updated word.

replaceMap map of words to be replaced keepMap map of words to keep intact rules List of rules to use for sanitization

Returns a function that accepts a word and returns the updated word

Implementation

String replaceWord(Map<String, String> replaceMap,
    Map<String, String> keepMap, List<List<dynamic>> rules, String word) {
  // Get the correct token and case restoration functions.
  final token = word.toLowerCase();

  // Check against the keep object map.
  if (keepMap.containsKey(token)) {
    return LMFeedPluralizeUtils.restoreCase(word, token);
  }

  // Check against the replacement map for a direct word replacement.
  if (replaceMap.containsKey(token)) {
    return LMFeedPluralizeUtils.restoreCase(word, replaceMap[token]!);
  }

  // Run all the rules against the word.
  return sanitizeWord(token, word, rules);
}