Class: Yanbi::Dictionary
- Inherits:
-
Object
- Object
- Yanbi::Dictionary
- Defined in:
- lib/dictionary.rb
Instance Attribute Summary collapse
-
#bag_class ⇒ Object
Returns the value of attribute bag_class.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(w, klass) ⇒ Dictionary
constructor
A new instance of Dictionary.
- #save(name) ⇒ Object
- #to_idx(doc) ⇒ Object
Constructor Details
#initialize(w, klass) ⇒ Dictionary
Returns a new instance of Dictionary.
16 17 18 19 20 21 |
# 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 |
Instance Attribute Details
#bag_class ⇒ Object
Returns the value of attribute bag_class.
14 15 16 |
# File 'lib/dictionary.rb', line 14 def bag_class @bag_class end |
Class Method Details
.load(fname) ⇒ Object
28 29 30 31 32 |
# 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 |
Instance Method Details
#save(name) ⇒ Object
34 35 36 37 38 |
# 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) ⇒ Object
23 24 25 26 |
# File 'lib/dictionary.rb', line 23 def to_idx(doc) bag = @klass.new(doc) bag.words.map { |w| @index[w] } end |