class Greeklish::GreekReverseStemmer

Generates singular/plural variants of a greek word based on a combination of predefined rules.

Constants

SUFFIX_A
SUFFIX_AS
SUFFIX_EIA
SUFFIX_EIO
SUFFIX_EIOY
SUFFIX_EIS
SUFFIX_EIWN
SUFFIX_ES
SUFFIX_H
SUFFIX_HS
SUFFIX_I
SUFFIX_IA
SUFFIX_IOY
SUFFIX_IWN
SUFFIX_MATA
SUFFIX_MATOS

Constant variable that represents suffixes for pluralization of greeklish tokens.

SUFFIX_MATWN
SUFFIX_O
SUFFIX_OI
SUFFIX_OS
SUFFIX_OY
SUFFIX_STRINGS

The possible suffix strings.

SUFFIX_WN

Attributes

greek_words[R]

The greek word list

suffixes[R]

This hash has as keys all the suffixes that we want to handle in order to generate singular/plural greek words.

Public Class Methods

new() click to toggle source
# File lib/greeklish/greek_reverse_stemmer.rb, line 65
def initialize
  @suffixes = {}
  @greek_words = []

  # populate suffixes
  SUFFIX_STRINGS.each do |suffix|
    key = suffix[0]
    val = suffix[1..suffix.length]
    @suffixes[key] = val
  end
end

Public Instance Methods

generate_greek_variants(token_string) click to toggle source

This method generates the greek variants of the greek token that receives.

@param token_string the greek word @return a list of the generated greek word variations

# File lib/greeklish/greek_reverse_stemmer.rb, line 82
def generate_greek_variants(token_string)
  # clear the list from variations of the previous greek token
  @greek_words.clear

  # add the initial greek token in the greek words
  @greek_words << token_string

  # Find the first matching suffix and generate the variants
  # of this word.
  SUFFIX_STRINGS.each do |suffix|
    if (token_string.end_with?(suffix[0]))
      # Add to greek_words the tokens with the desired suffixes
      generate_more_greek_words(token_string, suffix[0])
      break
    end
  end

  greek_words
end
generate_more_greek_words(input_token, input_suffix) click to toggle source

Generates more greek words based on the suffix of the original word.

@param input_suffix the suffix that matched.

# File lib/greeklish/greek_reverse_stemmer.rb, line 106
def generate_more_greek_words(input_token, input_suffix)
  suffixes[input_suffix].each do |suffix|
    @greek_words << input_token.gsub(/#{input_suffix}$/, suffix)
  end
end