Class: Kotoshu::Readers::CompoundPattern

Inherits:
Object
  • Object
show all
Defined in:
lib/kotoshu/readers/aff_data.rb

Overview

Compound pattern for checking compound words.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(left, right, replacement = nil) ⇒ CompoundPattern

Create a new compound pattern.

Parameters:

  • left (String)

    Left side pattern

  • right (String)

    Right side pattern

  • replacement (String, nil) (defaults to: nil)

    Optional replacement



250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/kotoshu/readers/aff_data.rb', line 250

def initialize(left, right, replacement = nil)
  @left = left
  @right = right
  @replacement = replacement

  # Parse left side
  @left_stem, _, @left_flag = left.partition('/')
  @left_stem = '' if @left_stem == '0'
  @left_no_affix = @left_stem.empty? && left.start_with?('0')

  # Parse right side
  @right_stem, _, @right_flag = right.partition('/')
  @right_stem = '' if @right_stem == '0'
  @right_no_affix = @right_stem.empty? && right.start_with?('0')
end

Instance Attribute Details

#leftString

Left side pattern

Returns:

  • (String)

    the current value of left



241
242
243
# File 'lib/kotoshu/readers/aff_data.rb', line 241

def left
  @left
end

#left_flagObject (readonly)

Returns the value of attribute left_flag.



242
243
244
# File 'lib/kotoshu/readers/aff_data.rb', line 242

def left_flag
  @left_flag
end

#left_no_affixObject (readonly)

Returns the value of attribute left_no_affix.



242
243
244
# File 'lib/kotoshu/readers/aff_data.rb', line 242

def left_no_affix
  @left_no_affix
end

#left_stemObject (readonly)

Returns the value of attribute left_stem.



242
243
244
# File 'lib/kotoshu/readers/aff_data.rb', line 242

def left_stem
  @left_stem
end

#replacementString?

Optional replacement

Returns:

  • (String, nil)

    the current value of replacement



241
242
243
# File 'lib/kotoshu/readers/aff_data.rb', line 241

def replacement
  @replacement
end

#rightString

Right side pattern

Returns:

  • (String)

    the current value of right



241
242
243
# File 'lib/kotoshu/readers/aff_data.rb', line 241

def right
  @right
end

#right_flagObject (readonly)

Returns the value of attribute right_flag.



242
243
244
# File 'lib/kotoshu/readers/aff_data.rb', line 242

def right_flag
  @right_flag
end

#right_no_affixObject (readonly)

Returns the value of attribute right_no_affix.



242
243
244
# File 'lib/kotoshu/readers/aff_data.rb', line 242

def right_no_affix
  @right_no_affix
end

#right_stemObject (readonly)

Returns the value of attribute right_stem.



242
243
244
# File 'lib/kotoshu/readers/aff_data.rb', line 242

def right_stem
  @right_stem
end

Instance Method Details

#match?(left_part, right_part) ⇒ Boolean

Check if this pattern matches the given left and right parts.

Parameters:

  • left_part (AffixForm)

    Left part with stem, flags, is_base?

  • right_part (AffixForm)

    Right part with stem, flags, is_base?

Returns:

  • (Boolean)

    True if matches



271
272
273
274
275
276
277
278
279
280
# File 'lib/kotoshu/readers/aff_data.rb', line 271

def match?(left_part, right_part)
  return false unless left_part.stem.end_with?(@left_stem)
  return false unless right_part.stem.start_with?(@right_stem)
  return false if @left_no_affix && left_part.is_base?
  return false if @right_no_affix && right_part.is_base?
  return false if @left_flag && !left_part.flags.include?(@left_flag)
  return false if @right_flag && !right_part.flags.include?(@right_flag)

  true
end