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.



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

#eachObject



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_sObject



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

def to_s
  @h_.to_s
end