Class: BLEU::NgramCounts
- Inherits:
-
Object
- Object
- BLEU::NgramCounts
- Defined in:
- lib/zipf/bleu.rb
Instance Attribute Summary collapse
-
#clipped ⇒ Object
Returns the value of attribute clipped.
-
#hyp_len ⇒ Object
Returns the value of attribute hyp_len.
-
#n ⇒ Object
Returns the value of attribute n.
-
#ref_len ⇒ Object
Returns the value of attribute ref_len.
-
#sum ⇒ Object
Returns the value of attribute sum.
Instance Method Summary collapse
- #grow(n) ⇒ Object
-
#initialize(n) ⇒ NgramCounts
constructor
A new instance of NgramCounts.
- #plus_eq(other) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(n) ⇒ NgramCounts
Returns a new instance of NgramCounts.
7 8 9 10 11 12 13 14 |
# File 'lib/zipf/bleu.rb', line 7 def initialize(n) @n = 0 @sum = [] @clipped = [] @ref_len = 0.0 @hyp_len = 0.0 grow(n) end |
Instance Attribute Details
#clipped ⇒ Object
Returns the value of attribute clipped.
5 6 7 |
# File 'lib/zipf/bleu.rb', line 5 def clipped @clipped end |
#hyp_len ⇒ Object
Returns the value of attribute hyp_len.
5 6 7 |
# File 'lib/zipf/bleu.rb', line 5 def hyp_len @hyp_len end |
#n ⇒ Object
Returns the value of attribute n.
5 6 7 |
# File 'lib/zipf/bleu.rb', line 5 def n @n end |
#ref_len ⇒ Object
Returns the value of attribute ref_len.
5 6 7 |
# File 'lib/zipf/bleu.rb', line 5 def ref_len @ref_len end |
#sum ⇒ Object
Returns the value of attribute sum.
5 6 7 |
# File 'lib/zipf/bleu.rb', line 5 def sum @sum end |
Instance Method Details
#grow(n) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/zipf/bleu.rb', line 16 def grow(n) (n-@n).times { @sum << 0.0 @clipped << 0.0 } @n = n end |
#plus_eq(other) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/zipf/bleu.rb', line 24 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_s ⇒ Object
34 35 36 |
# File 'lib/zipf/bleu.rb', line 34 def to_s return "n=#{n} sum=#{sum} clipped=#{clipped} ref_len=#{ref_len} hyp_len=#{hyp_len}" end |