Class: JLDrill::DeinflectionRules

Inherits:
Object
  • Object
show all
Defined in:
lib/jldrill/model/DeinflectionRules.rb

Overview

An array of Deinflection Rules.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDeinflectionRules

Returns a new instance of DeinflectionRules.



141
142
143
144
145
# File 'lib/jldrill/model/DeinflectionRules.rb', line 141

def initialize
    @reasons = []
    @rules = []
    @readHeader = false
end

Instance Attribute Details

#reasonsObject (readonly)

Returns the value of attribute reasons.



139
140
141
# File 'lib/jldrill/model/DeinflectionRules.rb', line 139

def reasons
  @reasons
end

#rulesObject (readonly)

Returns the value of attribute rules.



139
140
141
# File 'lib/jldrill/model/DeinflectionRules.rb', line 139

def rules
  @rules
end

Instance Method Details

#match(string) ⇒ Object



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/jldrill/model/DeinflectionRules.rb', line 171

def match(string)
    retVal = [Deinflection::Match.start(string)]
    i = 0
    while(i < retVal.size) do
        @rules.each do |rule|
            new = retVal[i].apply(rule)
            if !new.nil? && !retVal.any? do |match|
                match.last.dictionary.eql?(new.last.dictionary)
            end
                retVal.push(new)
            end
        end
        i += 1
    end
    return retVal
end

#parse(string) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/jldrill/model/DeinflectionRules.rb', line 147

def parse(string)
          if !@readHeader
              # The first line of the file must be discarded
              @readHeader = true
          else
              entry = Deinflection::Rule.parse(string, @reasons)
              if(!entry.nil?)
                  @rules.push(entry)
              else
                  reason = Deinflection::Reason.parse(string)
                  if !reason.nil?
                      @reasons.push(reason)
                  else
                      Context::Log::warning("JLDrill::DeinflectionRules",
                                            "Could not parse #{string}")
                  end
              end
          end
end

#sizeObject



167
168
169
# File 'lib/jldrill/model/DeinflectionRules.rb', line 167

def size
    return @rules.size + @reasons.size
end

#to_sObject



188
189
190
# File 'lib/jldrill/model/DeinflectionRules.rb', line 188

def to_s
	self.join("\n")
end