class Lingo::Attendee::Variator

Public Instance Methods

control(*) click to toggle source
# File lib/lingo/attendee/variator.rb, line 91
def control(*)
end
init() click to toggle source
# File lib/lingo/attendee/variator.rb, line 76
def init
  @marker = get_key('marker', '*')
  @max    = get_int('max-var', max = 10000)
  @max    = max unless @max > 0
  @var    = get_key('variations')

  raise MissingConfigError.new(:variations) if @var.empty?

  @check = Hash.new(false)
  get_ary('check', WA_UNKNOWN).each { |s| @check[s.upcase] = true }

  set_dic
  set_gra
end
process(obj) click to toggle source
# File lib/lingo/attendee/variator.rb, line 94
def process(obj)
  if obj.is_a?(Word) && @check[obj.attr]
    vars, max = [obj.form], @max

    @var.each { |args|
      variate(vars, *args)
      break unless vars.length < max
    }

    vars.each { |var|
      next if (word = find_word(var)).unknown? || (
        word.attr == WA_COMPOUND && word.lexicals.any? { |lex|
          lex.attr.start_with?(LA_TAKEITASIS)
        }
      )

      return forward(word.tap { word.form = @marker + var })
    }
  end

  forward(obj)
end

Private Instance Methods

variate(variations, from, to) click to toggle source
# File lib/lingo/attendee/variator.rb, line 119
def variate(variations, from, to)
  add, change, re = [], [from, to], Regexp.new(from)

  variations.each { |form|
    parts = " #{form} ".split(re)

    1.upto(2 ** (n = parts.size - 1) - 1) { |i|
      var = parts.first
      1.upto(n) { |j| var += change[i[j - 1]] + parts[j] }
      add << var.strip
    }
  }

  variations.concat(add)
end