class Greeklish::GreeklishGenerator
Generates greeklish tokens that represent the character that substitutes a digraph.
Constants
- AI
Constant variables that represent the character that substitutes a digraph.
- AY
- CONVERT_STRINGS
The possible string conversions for each case.
- DIGRAPH_CASES
The possible digraph cases.
- EI
- EY
- GG
- GK
- MP
- NT
- OI
- OY
Attributes
This hash has keys all the possible conversions that can be applied and values the strings that can replace the corresponding Greek character.
Each digraph is replaced by a special capital Greek character.
Keep the generated strings in a list. The populated list is returned to the filter.
The maximum greeklish expansions per greek token.
A list of greeklish token per each greek word.
Public Class Methods
# File lib/greeklish/greeklish_generator.rb, line 60 def initialize(max_expansions) @max_expansions = max_expansions @greeklish_list = [] @per_word_greeklish = [] @digraphs = {} @conversions = Hash.new([]) # populate digraphs DIGRAPH_CASES.each do |digraph_case| key = digraph_case[0] value = digraph_case[1] @digraphs[key] = value end # populate conversions CONVERT_STRINGS.each do |convert_string| key = convert_string[0] value = convert_string[1..convert_string.length] @conversions[key] = value end end
Public Instance Methods
Gets a list of greek words and generates the greeklish version of each word.
@param greek_words a list of greek words @return a list of greeklish words
# File lib/greeklish/greeklish_generator.rb, line 87 def generate_greeklish_words(greek_words) @greeklish_list.clear greek_words.each do |greek_word| @per_word_greeklish.clear initial_token = greek_word digraphs.each_key do |key| greek_word = greek_word.gsub(key, digraphs[key]) end # Convert it back to array of characters. The iterations of each # character will take place through this array. input_token = greek_word.split(//) # Iterate through the characters of the token and generate # greeklish words. input_token.each do |greek_char| add_character(conversions[greek_char]) end @greeklish_list << per_word_greeklish.flatten end @greeklish_list.flatten end
Private Instance Methods
Add the matching latin characters to the generated greeklish tokens for a specific Greek character. For each different combination of latin characters, a new token is generated.
@param convert_strings the latin characters that will be added to the tokens
# File lib/greeklish/greeklish_generator.rb, line 122 def add_character(convert_strings) if (per_word_greeklish.empty?) convert_strings.each do |convert_string| if (per_word_greeklish.size >= max_expansions) break end @per_word_greeklish << convert_string end else new_tokens = [] convert_strings.each do |convert_string| per_word_greeklish.each do |token| if (new_tokens.size >= max_expansions) break end new_tokens << "#{token}#{convert_string}" end end @per_word_greeklish = new_tokens end end