Method: BLEU.get_counts

Defined in:
lib/zipf/bleu.rb

.get_counts(hypothesis, references, n, times = 1) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/zipf/bleu.rb', line 76

def BLEU::get_counts hypothesis, references, n, times=1
  p = NgramCounts.new n
  r = []
  references.each { |reference|
    r << Ngrams.new
    ngrams(reference, n) { |ng| r.last.add ng }
  }
  h = Ngrams.new
  ngrams(hypothesis, n) { |ng| h.add ng }
  h.each { |ng,count|
    sz = ng.size-1
    p.sum[sz] += count * times
    p.clipped[sz] += [r.map { |i| i.get_count(ng)}.max, count].min * times
  }
  p.hyp_len, p.ref_len = best_match_length hypothesis, references
  p.hyp_len *= times
  p.ref_len *= times
  return p
end