class LooseMatch

Attributes

basic_equivalence_dict[R]
node_target_phoneme[RW]
prev_switch[R]
previously_searched_phonemes[RW]

Public Class Methods

new() click to toggle source
Calls superclass method DataBase::new
# File lib/promper/matching.rb, line 80
  def initialize
    super
    @basic_equivalence_dict = {
  "i" => %w[ɪ ə],
  "z" => %w[s],
  "ə" => %w[i ɪ ʌ æ u],
  "u" => %w[ə],
  "ɪ" => %w[i],
  "d" => %w[t],
  "æ" => %w[ə ʌ ɛ],
  "s" => %w[z],
  "ɝ" => %w[r],
  "r" => %w[ɝ],
  "a" => %w[ʌ ə],
  "p" => %w[b],
  "t" => %w[d],
  "g" => %w[k],
  "ʌ" => %w[ə æ i a],
  "ɛ" => %w[æ],
  "b" => %w[p],
  "f" => %w[v],
  "v" => %w[f],
  "k" => %w[g],  
  "j" => %w[ʃ],
  "ʃ" => %w[j]
}
  @previously_searched_phonemes = {}
  end

Public Instance Methods

add_to_prev_phones(node_target_phoneme, matches) click to toggle source
# File lib/promper/matching.rb, line 109
def add_to_prev_phones(node_target_phoneme, matches)
  previously_searched_phonemes[node_target_phoneme] = matches
end
bail() click to toggle source
# File lib/promper/matching.rb, line 121
def bail
  [node_target_phoneme, ""]
end
combine_matches_and_phoneme_chunks(final_matches,phoneme_chunks) click to toggle source
# File lib/promper/matching.rb, line 229
def combine_matches_and_phoneme_chunks(final_matches,phoneme_chunks)
  final_matches.zip(phoneme_chunks)
end
determine_first_letter(node_target_phoneme) click to toggle source
# File lib/promper/matching.rb, line 170
def determine_first_letter(node_target_phoneme)
  node_target_phoneme[0]
end
determine_remaining_phoneme_chunks(phoneme_representation, node_target_phoneme) click to toggle source
# File lib/promper/matching.rb, line 219
def determine_remaining_phoneme_chunks(phoneme_representation, node_target_phoneme)
  phoneme_length = phoneme_representation.length
  node_target_phoneme[phoneme_length..-1]
end
get_relevant_matches(relevant_values, node_target_phoneme) click to toggle source
# File lib/promper/matching.rb, line 187
def get_relevant_matches(relevant_values, node_target_phoneme)
  rel = relevant_values.map {
      |word, phoneme_representation| [word, phoneme_representation] if passes_tests?(phoneme_representation, node_target_phoneme)}
  rel.compact
end
length_okay?(word, node_target_phoneme) click to toggle source
# File lib/promper/matching.rb, line 205
def length_okay?(word, node_target_phoneme)
  word.length <= node_target_phoneme.length
end
letter_match?(word, node_target_phoneme, index=0) click to toggle source
# File lib/promper/matching.rb, line 199
def letter_match?(word, node_target_phoneme, index=0)       
  word[index] == node_target_phoneme[index] ||
  (basic_equivalence_dict.key?(word[index]) &&
  basic_equivalence_dict[word[index]].include?(node_target_phoneme[index]))
end
match(node_target_phoneme) click to toggle source
# File lib/promper/matching.rb, line 138
def match(node_target_phoneme)
  if previously_searched_phonemes.key? node_target_phoneme
    return previously_searched_phonemes[node_target_phoneme]
  end
  if one_phoneme_remaining?(node_target_phoneme)
    bail 
  elsif no_phonemes_remaining?(node_target_phoneme)
    return nil
  else
    first_letter = determine_first_letter(node_target_phoneme)
    begin
      relevant_values = pull_relevant_values_from_dict(first_letter)

      matches = get_relevant_matches(relevant_values, node_target_phoneme)
      if matches.empty?
        add_to_prev_phones(node_target_phoneme, nil)
        return nil
      else
        chunks = matches.map do |word, phoneme_representation|
          determine_remaining_phoneme_chunks(phoneme_representation, node_target_phoneme)
        end
        matches = post_processing(chunks, matches)
      end
    rescue
      puts "Inner rescue"
      puts $!, $@
    end
  end
  add_to_prev_phones(node_target_phoneme, matches)
  matches
end
no_phonemes_remaining?(node_target_phoneme) click to toggle source
# File lib/promper/matching.rb, line 125
def no_phonemes_remaining?(node_target_phoneme)
  node_target_phoneme == nil ||
  node_target_phoneme.length == 0
end
one_phoneme_remaining?(node_target_phoneme) click to toggle source
# File lib/promper/matching.rb, line 113
def one_phoneme_remaining?(node_target_phoneme)
  begin
    node_target_phoneme.length == 1
  rescue
    false
  end
end
passes_tests?(word, node_target_phoneme) click to toggle source
# File lib/promper/matching.rb, line 193
def passes_tests?(word, node_target_phoneme)
  letter_match?(word, node_target_phoneme) &&
  length_okay?(word, node_target_phoneme) &&
  remaining_letter_match?(word, node_target_phoneme)
end
post_processing(chunks, matches) click to toggle source
# File lib/promper/matching.rb, line 224
def post_processing(chunks, matches)
  matches.zip(chunks).each{ |word, chunk| word[1] = chunk }
  matches
end
pull_relevant_values_from_dict(key) click to toggle source
# File lib/promper/matching.rb, line 174
def pull_relevant_values_from_dict(key)
  initial_values      = db[key]
  if basic_equivalence_dict.has_key?(key)
    equilvalent_keys    = basic_equivalence_dict[key]
    equilvalent_keys.map do |key|
      db[key].each do |word|
        initial_values << word
      end
    end
  end
  initial_values
end
remaining_letter_match?(word, node_target_phoneme) click to toggle source
# File lib/promper/matching.rb, line 209
def remaining_letter_match?(word, node_target_phoneme)
  word_length = word.length
  word_length.times do |letter|
    unless letter_match?(word, node_target_phoneme, index=letter)
      return false        
    end
  end
  true
end
target_phoneme_convert(node_target_phoneme) click to toggle source
# File lib/promper/matching.rb, line 130
def target_phoneme_convert(node_target_phoneme)
    list_of_words = node_target_phoneme.split
    ipa_list = list_of_words.map do |word|
      word.to_ipa.tr('ˈˌ', '')
    end
    ipa_list = ipa_list.join
end