generate static method
Given a word will produce a List of greeklish variations.
GreeklishGenerator.generate('αυτοκίνητο') == ['autokinhto','aftokinhto','avtokinhto','aytokinhto','autokinito','aftokinito','avtokinito','aytokinito']
Implementation
static List<String> generate(String word) {
// we work with the lowercase version
word = word.toLowerCase();
// if word does not contain any greek chars then stop
if (!_containsGreekChars(word)) {
return List<String>.from([word]);
}
// replace accents
_ACCENTS.forEach((key, value) => word = word.replaceAll(key, value));
// replace digraphs
_DIGRAPH_CASES.forEach((key, value) => word = word.replaceAll(key, value));
List<String> wordVariations = [];
// generate words from all possible rune conversions
for (final int rune in word.runes) {
if (wordVariations.isEmpty) {
for (final String greeklishVariation
in _produceGreeklishVeriations(rune)) {
wordVariations.add(greeklishVariation);
}
} else {
final List<String> newTokens = [];
for (final String greeklishVariation
in _produceGreeklishVeriations(rune)) {
for (final String token in wordVariations) {
newTokens.add('$token$greeklishVariation');
}
}
wordVariations = newTokens;
}
}
return wordVariations;
}