omitLessFreq method

void omitLessFreq()

Implementation

void omitLessFreq() {
  if (name == null) return;
  int threshold = max(nWords[0] ~/ lessFreqRatio, minimumFreq);

  int roman = 0;
  final keys = freq.keys.toList();
  for (final key in keys) {
    final count = freq[key]!;
    if (count <= threshold) {
      nWords[key.length - 1] -= count;
      freq.remove(key);
    } else if (romanCharRe.hasMatch(key)) {
      roman += count;
    }
  }

  if (roman < nWords[0] ~/ 3) {
    final keys = freq.keys.toList();
    for (final key in keys) {
      final count = freq[key]!;
      if (romanSubstrRe.hasMatch(key)) {
        nWords[key.length - 1] -= count;
        freq.remove(key);
      }
    }
  }
}