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.
40 41 42 43 |
# File 'lib/zipf/bleu.rb', line 40 def initialize @h_ = {} @h_.default = 0 end |
Instance Method Details
#add(k) ⇒ Object
45 46 47 48 |
# File 'lib/zipf/bleu.rb', line 45 def add(k) if k.class == Array then k = k.join ' ' end @h_[k] += 1 end |
#each ⇒ Object
55 56 57 58 59 |
# File 'lib/zipf/bleu.rb', line 55 def each @h_.each_pair { |k,v| yield k.split, v } end |
#get_count(k) ⇒ Object
50 51 52 53 |
# File 'lib/zipf/bleu.rb', line 50 def get_count(k) if k.class == Array then k = k.join ' ' end return @h_[k] end |
#to_s ⇒ Object
61 62 63 |
# File 'lib/zipf/bleu.rb', line 61 def to_s @h_.to_s end |