class Yanbi::Dictionary

Attributes

bag_class[RW]

Public Class Methods

load(fname) click to toggle source
# File lib/dictionary.rb, line 28
def self.load(fname)
  c = YAML.load(File.read(fname + '.yml'))
  raise LoadError unless c.is_a? self
  c
end
new(w, klass) click to toggle source
# File lib/dictionary.rb, line 16
def initialize(w, klass)
  @index = {}
  @klass = klass
  i = (0..w.size).to_a
  w.zip(i).each { |x| @index[x.first] = x.last }
end

Public Instance Methods

save(name) click to toggle source
# File lib/dictionary.rb, line 34
def save(name)
  File.open(name + '.yml', 'w') do |out|
    YAML.dump(self, out)
  end
end
to_idx(doc) click to toggle source
# File lib/dictionary.rb, line 23
def to_idx(doc)
  bag = @klass.new(doc)
  bag.words.map { |w| @index[w] }
end