Class: BLEU::Ngrams
- Inherits:
-
Object
- Object
- BLEU::Ngrams
- Defined in:
- lib/zipf/bleu.rb
Instance Method Summary collapse
- #add(k) ⇒ Object
- #each ⇒ Object
- #get_count(k) ⇒ Object
-
#initialize ⇒ Ngrams
constructor
A new instance of Ngrams.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Ngrams
Returns a new instance of Ngrams.
39 40 41 42 |
# File 'lib/zipf/bleu.rb', line 39 def initialize @h_ = {} @h_.default = 0 end |
Instance Method Details
#add(k) ⇒ Object
44 45 46 47 |
# File 'lib/zipf/bleu.rb', line 44 def add(k) if k.class == Array then k = k.join ' ' end @h_[k] += 1 end |
#each ⇒ Object
54 55 56 57 58 |
# File 'lib/zipf/bleu.rb', line 54 def each @h_.each_pair { |k,v| yield k.split, v } end |
#get_count(k) ⇒ Object
49 50 51 52 |
# File 'lib/zipf/bleu.rb', line 49 def get_count(k) if k.class == Array then k = k.join ' ' end return @h_[k] end |
#to_s ⇒ Object
60 61 62 |
# File 'lib/zipf/bleu.rb', line 60 def to_s @h_.to_s end |