word_aligner 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a4c26333b5e0991c70d0e61ef5435268672a112
4
- data.tar.gz: 2ec6efcb6606676f2e30bd26425bd21843278018
3
+ metadata.gz: c32d9ee5728f79dcb8f723768c832ec8807a321d
4
+ data.tar.gz: f51260981c579aac86155c91e2b11184d5663929
5
5
  SHA512:
6
- metadata.gz: 199f2c4f5288a60c907a9d842951e740ec712eeaca1a9371a74b96db92d2053107543809b107c23bd025f532f5a75add474f5ff7f12cd163d0c99cb728cb5ffd
7
- data.tar.gz: 95ae32a917c4e2578bb6087973c0cf195eb4b41b56e771b37d1d138b336440163e8bee9e1ebf015bb48b9690831654ed08fcce8c962dcbae3f11d765f9f01d86
6
+ metadata.gz: 64d4796c1231a2a758d744bde20177c2bf867e4ad8134f576ebb9e3a0fb1cd43e49f3ab4b797b151f1c24cc4ed71e0441c2e68b1b79dc2759f64cfcb844305a7
7
+ data.tar.gz: 9b97b27165cee5f997f4fd4a057e33342e71d37415e115b5295a524697f8ff1459b4b0d8a85541a6ae838832587f8bd141e025b0213174049c2ddea76917e407
data/README.md CHANGED
@@ -31,11 +31,14 @@ $ bundle
31
31
 
32
32
  error_rate.correct => 2
33
33
  error_rate.errors => 1
34
- error_rate.percent_correct => 66.0
35
- error_rate.percent_error => 33.0
36
- error_rate.percent_accuracy => 66.0
34
+ error_rate.percentage_correct => 66.0
35
+ error_rate.percentage_incorrect => 33.0
36
+ error_rate.percentage_accurate => 66.0
37
37
  ```
38
38
 
39
+ There is also ```WordErrorRateCollection``` if you need to calculate
40
+ the word error rate for multiple hypotheses.
41
+
39
42
  ## Contributing
40
43
 
41
44
  1. Fork it
@@ -1,3 +1,4 @@
1
+ require 'word_error_rate_collection'
1
2
  require 'word_aligner/aligner'
2
3
  require 'word_aligner/word_error_rate'
3
4
 
@@ -0,0 +1,55 @@
1
+ class WordErrorRateCollection
2
+
3
+ attr_reader :entries
4
+
5
+ def initialize(entries)
6
+ @entries = entries
7
+ end
8
+
9
+ def correct_words
10
+ entries.map(&:correct_words).inject(0, :+)
11
+ end
12
+
13
+ def incorrect_words
14
+ entries.map(&:incorrect_words).inject(0, :+)
15
+ end
16
+
17
+ def words
18
+ entries.map(&:words).inject(0, :+)
19
+ end
20
+
21
+ def percentage_correct
22
+ percent_rate(correct_words)
23
+ end
24
+
25
+ def percentage_incorrect
26
+ percent_rate(incorrect_words)
27
+ end
28
+
29
+ def percentage_accurate
30
+ 100 - percentage_incorrect
31
+ end
32
+
33
+ def aligned_transcription
34
+ 'TOTAL'
35
+ end
36
+
37
+ def aligned_hypothesis
38
+ 'TOTAL'
39
+ end
40
+
41
+ def method_missing(name)
42
+ 'N/A'
43
+ end
44
+
45
+ def to_partial_path
46
+ 'word_error_rates/word_error_rate'
47
+ end
48
+
49
+ private
50
+
51
+ def percent_rate(value)
52
+ value * 100.0 / [words, 1].max
53
+ end
54
+
55
+ end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'yaml'
2
3
 
3
4
  class Sample < OpenStruct
4
5
  def aligner_result
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe WordErrorRateCollection do
4
+
5
+ word_error_rates = []
6
+ word_error_rates << WordAligner.align('hello and welcome', 'hullo and wulcome')
7
+ word_error_rates << WordAligner.align('good morning', 'good lulz')
8
+
9
+ subject { WordErrorRateCollection.new(word_error_rates) }
10
+
11
+ its(:entries) { should eq word_error_rates }
12
+ its(:aligned_transcription) { should eq 'TOTAL' }
13
+ its(:aligned_hypothesis) { should eq 'TOTAL' }
14
+
15
+ its(:correct_words) { should eq 2 }
16
+ its(:incorrect_words) { should eq 3 }
17
+ its(:words) { should eq 5 }
18
+
19
+ its(:percentage_correct) { should be_within(0.1).of(40) }
20
+ its(:percentage_incorrect) { should be_within(0.1).of(60) }
21
+ its(:percentage_accurate) { should be_within(0.1).of(40) }
22
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: word_aligner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej
@@ -100,8 +100,10 @@ files:
100
100
  - lib/word_aligner.rb
101
101
  - lib/word_aligner/aligner.rb
102
102
  - lib/word_aligner/word_error_rate.rb
103
+ - lib/word_error_rate_collection.rb
103
104
  - spec/lib/word_aligner/aligner_spec.rb
104
105
  - spec/lib/word_aligner/word_error_rate_spec.rb
106
+ - spec/lib/word_error_rate_collection.rb_spec.rb
105
107
  - spec/lib/word_aligner_spec.rb
106
108
  - spec/sample_data/grab_for_comparision.rb
107
109
  - spec/sample_data/regression/sentences.yml