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.
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
#clipped ⇒ Object
Returns the value of attribute clipped.
4 5 6 |
# File 'lib/zipf/bleu.rb', line 4 def clipped @clipped end |
#hyp_len ⇒ Object
Returns the value of attribute hyp_len.
4 5 6 |
# File 'lib/zipf/bleu.rb', line 4 def hyp_len @hyp_len end |
#n ⇒ Object
Returns the value of attribute n.
4 5 6 |
# File 'lib/zipf/bleu.rb', line 4 def n @n end |
#ref_len ⇒ Object
Returns the value of attribute ref_len.
4 5 6 |
# File 'lib/zipf/bleu.rb', line 4 def ref_len @ref_len end |
#sum ⇒ Object
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_s ⇒ Object
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 |