Class: RussianWordForms::Dictionary

Inherits:
Object
  • Object
show all
Defined in:
lib/russian_word_forms/dictionary.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDictionary

Returns a new instance of Dictionary.



8
9
10
11
# File 'lib/russian_word_forms/dictionary.rb', line 8

def initialize
  @dictionary = Hash.new
  load_dictionaries
end

Instance Attribute Details

#dictionaryObject

Returns the value of attribute dictionary.



6
7
8
# File 'lib/russian_word_forms/dictionary.rb', line 6

def dictionary
  @dictionary
end

Instance Method Details

#get_flags(word) ⇒ Object



29
30
31
# File 'lib/russian_word_forms/dictionary.rb', line 29

def get_flags(word)
  @dictionary[word]      
end

#load_dictionariesObject



22
23
24
25
26
27
# File 'lib/russian_word_forms/dictionary.rb', line 22

def load_dictionaries
  files = Dir[File.dirname(__FILE__)+"/dictionaries/*.dic"]
  files.each do |file|
    load_dictionary file
  end
end

#load_dictionary(file) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/russian_word_forms/dictionary.rb', line 13

def load_dictionary(file)
  File.readlines(file).each do |line|
    stem,flags = line.chomp.split('/')
    stem = Unicode::upcase stem
    stem.gsub!("Ё","Е")
    @dictionary[stem]=flags
  end
end