Class: WordAligner::Aligner

Inherits:
Object
  • Object
show all
Defined in:
lib/word_aligner/aligner.rb

Constant Summary collapse

INSERTION =
1
DELETION =
2
MATCHING =
3
SUBSTITUTE =
4

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transcription, hypothesis) ⇒ Aligner

Returns a new instance of Aligner.



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/word_aligner/aligner.rb', line 19

def initialize(transcription, hypothesis)
  @transcription = transcription
  @hypothesis    = hypothesis

@insertions    = 0
@substitutions = 0
@deletions     = 0
@matching      = 0

  @reference_tokens = tokenize(transcription)
  @hypothese_tokens = tokenize(hypothesis)
end

Instance Attribute Details

#align_costObject

Returns the value of attribute align_cost.



11
12
13
# File 'lib/word_aligner/aligner.rb', line 11

def align_cost
  @align_cost
end

#align_matrixObject (readonly)

Returns the value of attribute align_matrix.



17
18
19
# File 'lib/word_aligner/aligner.rb', line 17

def align_matrix
  @align_matrix
end

#aligned_hypothesisObject

Returns the value of attribute aligned_hypothesis.



12
13
14
# File 'lib/word_aligner/aligner.rb', line 12

def aligned_hypothesis
  @aligned_hypothesis
end

#aligned_transcriptionObject

Returns the value of attribute aligned_transcription.



12
13
14
# File 'lib/word_aligner/aligner.rb', line 12

def aligned_transcription
  @aligned_transcription
end

#backtrace_matrixObject (readonly)

Returns the value of attribute backtrace_matrix.



17
18
19
# File 'lib/word_aligner/aligner.rb', line 17

def backtrace_matrix
  @backtrace_matrix
end

#deletionsObject

Returns the value of attribute deletions.



11
12
13
# File 'lib/word_aligner/aligner.rb', line 11

def deletions
  @deletions
end

#hypothese_tokensObject (readonly)

Returns the value of attribute hypothese_tokens.



15
16
17
# File 'lib/word_aligner/aligner.rb', line 15

def hypothese_tokens
  @hypothese_tokens
end

#hypothesisObject (readonly)

Returns the value of attribute hypothesis.



14
15
16
# File 'lib/word_aligner/aligner.rb', line 14

def hypothesis
  @hypothesis
end

#insertionsObject

Returns the value of attribute insertions.



11
12
13
# File 'lib/word_aligner/aligner.rb', line 11

def insertions
  @insertions
end

#matchingObject

Returns the value of attribute matching.



11
12
13
# File 'lib/word_aligner/aligner.rb', line 11

def matching
  @matching
end

#reference_tokensObject (readonly)

Returns the value of attribute reference_tokens.



15
16
17
# File 'lib/word_aligner/aligner.rb', line 15

def reference_tokens
  @reference_tokens
end

#substitutionsObject

Returns the value of attribute substitutions.



11
12
13
# File 'lib/word_aligner/aligner.rb', line 11

def substitutions
  @substitutions
end

#transcriptionObject (readonly)

Returns the value of attribute transcription.



14
15
16
# File 'lib/word_aligner/aligner.rb', line 14

def transcription
  @transcription
end

Class Method Details

.align(original, hypothesis) ⇒ Object



38
39
40
# File 'lib/word_aligner/aligner.rb', line 38

def self.align(original, hypothesis)
  new(original, hypothesis).result
end

Instance Method Details

#word_error_rateObject



32
33
34
35
36
# File 'lib/word_aligner/aligner.rb', line 32

def word_error_rate
  align_sentences if align_matrix.nil?

  WordErrorRate.new(result)
end