Class: BLEU::Ngrams

Inherits:
Object
  • Object
show all
Defined in:
lib/zipf/bleu.rb

Instance Method Summary collapse

Constructor Details

#initializeNgrams

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

#eachObject



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_sObject



61
62
63
# File 'lib/zipf/bleu.rb', line 61

def to_s
  @h_.to_s
end