class Lingo::Attendee::LsiFilter

Public Instance Methods

control(cmd, *) click to toggle source
# File lib/lingo/attendee/lsi_filter.rb, line 53
def control(cmd, *)
  :skip_command if cmd == :EOL
end
control_deferred(cmd, *) click to toggle source
# File lib/lingo/attendee/lsi_filter.rb, line 57
def control_deferred(cmd, *)
  @docnum += 1 if TERMINALS.include?(cmd)
end
init() click to toggle source
# File lib/lingo/attendee/lsi_filter.rb, line 33
def init
  require_lib('lsi4r')

  @lex  = get_re('lexicals', '[sy]')
  @skip = get_ary('skip', DEFAULT_SKIP, :upcase)

  @transform = get_key('transform', Lsi4R::DEFAULT_TRANSFORM)
  @cutoff    = get_flo('cut',       Lsi4R::DEFAULT_CUTOFF)

  @min = get_flo('min', false)
  @abs = get_flo('abs', false)
  @nul = get_flo('nul', false)
  @new = get_key('new', true)

  @sort = get_key('sort', false)
  @sort.downcase! if @sort.respond_to?(:downcase!)

  @docnum, @vectors = 0, Hash.new { |h, k| h[k] = [] }
end
process(obj) click to toggle source
# File lib/lingo/attendee/lsi_filter.rb, line 61
def process(obj)
  if obj.is_a?(Word) && !@skip.include?(obj.attr)
    vec = []
    obj.each_lex(@lex) { |lex| vec << Unicode.downcase(lex.form) }
    @vectors[@docnum].concat(vec) unless vec.empty?
  end
end

Private Instance Methods

flush_deferred()
Alias for: send_lsi
send_lsi() { |!sort ? lambda { |docnum| each_norm{ |_, *v| forward(fmt % v) }| ... } click to toggle source
# File lib/lingo/attendee/lsi_filter.rb, line 71
def send_lsi
  lsi = Lsi4R.new(@vectors); @vectors.clear

  if lsi.build(transform: @transform, cutoff: @cutoff)
    options, vec = { min: @min, abs: @abs, nul: @nul, new: @new }, []

    fmt = @sort ? @sort == 'sto' ?
      '%s {%.5f}' : '%2$.5f %1$s' : '%s %.5f' unless @sort == 'normal'

    yield !@sort ? lambda { |docnum|
      lsi.each_norm(docnum, options) { |_, *v| forward(fmt % v) }
    } : lambda { |docnum|
      lsi.each_norm(docnum, options) { |_, *v| vec << v }

      !fmt ? vec.sort!.each { |v, _| forward(v) } :
        vec.sort_by { |v, w| [-w, v] }.each { |v| forward(fmt % v) }

      vec.clear
    }
  end
end
Also aliased as: flush_deferred