Class: BLEU::NgramCounts

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(n) ⇒ NgramCounts

Returns a new instance of NgramCounts.



6
7
8
9
10
11
12
13
# File 'lib/zipf/bleu.rb', line 6

def initialize(n)
  @n = 0
  @sum = []
  @clipped = []
  @ref_len = 0.0
  @hyp_len = 0.0
  grow(n)
end

Instance Attribute Details

#clippedObject

Returns the value of attribute clipped.



4
5
6
# File 'lib/zipf/bleu.rb', line 4

def clipped
  @clipped
end

#hyp_lenObject

Returns the value of attribute hyp_len.



4
5
6
# File 'lib/zipf/bleu.rb', line 4

def hyp_len
  @hyp_len
end

#nObject

Returns the value of attribute n.



4
5
6
# File 'lib/zipf/bleu.rb', line 4

def n
  @n
end

#ref_lenObject

Returns the value of attribute ref_len.



4
5
6
# File 'lib/zipf/bleu.rb', line 4

def ref_len
  @ref_len
end

#sumObject

Returns the value of attribute sum.



4
5
6
# File 'lib/zipf/bleu.rb', line 4

def sum
  @sum
end

Instance Method Details

#grow(n) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/zipf/bleu.rb', line 15

def grow(n)
  (n-@n).times {
    @sum << 0.0
    @clipped << 0.0
  }
  @n = n
end

#plus_eq(other) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/zipf/bleu.rb', line 23

def plus_eq(other)
  if other.n > @n then grow(other.n) end
  0.upto(other.n-1) { |m|
    @sum[m] += other.sum[m]
    @clipped[m] += other.clipped[m]
  }
  @ref_len += other.ref_len
  @hyp_len += other.hyp_len
end

#to_sObject



33
34
35
# File 'lib/zipf/bleu.rb', line 33

def to_s
  return "n=#{n} sum=#{sum} clipped=#{clipped} ref_len=#{ref_len} hyp_len=#{hyp_len}"
end