Class: RussianWordForms::Rules

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

Defined Under Namespace

Classes: Rule

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRules

Returns a new instance of Rules.



14
15
16
17
18
# File 'lib/russian_word_forms/rules.rb', line 14

def initialize
  @rules = Hash.new {|h,k| h[k]=Hash.new {|h2,k2| h2[k2]=[]}}
  @rules_without_flags = Hash.new {|h2,k2| h2[k2]=[]}
  load_rules
end

Instance Attribute Details

#rulesObject

Returns the value of attribute rules.



11
12
13
# File 'lib/russian_word_forms/rules.rb', line 11

def rules
  @rules
end

#rules_without_flagsObject

Returns the value of attribute rules_without_flags.



11
12
13
# File 'lib/russian_word_forms/rules.rb', line 11

def rules_without_flags
  @rules_without_flags
end

Instance Method Details

#load_file(file) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/russian_word_forms/rules.rb', line 20

def load_file(file)
  flag = ""
  File.readlines(file).each do |line|
    command,comments = line.chomp.split('#') # get rid of comments
    if command && !command.empty?
      if command.start_with? "flag"
        flag = command[6..-2]
      else
        rule,suffixes = command.split.join.split(">")
        normal_suffix,suffix = suffixes.split(",")
        normal_suffix = normal_suffix[1..-1] if normal_suffix[0] == '-'
        suffix=suffix[1..-1] if suffix && suffix[0] == '-'
        @rules[flag][rule] << Rule.new(rule,normal_suffix,suffix)
        @rules_without_flags[rule] << Rule.new(rule,normal_suffix,suffix)
      end
    end
  end
end

#load_rulesObject



39
40
41
42
43
44
# File 'lib/russian_word_forms/rules.rb', line 39

def load_rules
  files = Dir[File.dirname(__FILE__)+"/dictionaries/*.aff"]
  files.each do |file|
    load_file file
  end
end