class SSMD::Annotations::PhonemeAnnotation

Attributes

ipa[R]
x_sampa[R]

Public Class Methods

new(ph, text) click to toggle source
# File lib/ssmd/annotations/phoneme_annotation.rb, line 13
def initialize(ph, text)
  @x_sampa = text if ph == "ph"

  if ph == "ph"
    @ipa = x_sampa_to_ipa x_sampa
  elsif ph == "ipa"
    @ipa = text
  end
end
regex() click to toggle source
# File lib/ssmd/annotations/phoneme_annotation.rb, line 9
def self.regex
  /((?:ph)|(?:ipa)): ?(.+)/
end

Public Instance Methods

combine(annotation) click to toggle source
# File lib/ssmd/annotations/phoneme_annotation.rb, line 27
def combine(annotation)
  self # discard further phoneme annotations
end
wrap(text) click to toggle source
# File lib/ssmd/annotations/phoneme_annotation.rb, line 23
def wrap(text)
  "<phoneme alphabet=\"ipa\" ph=\"#{ipa}\">#{text}</phoneme>"
end
x_sampa_to_ipa(input) click to toggle source
# File lib/ssmd/annotations/phoneme_annotation.rb, line 31
def x_sampa_to_ipa(input)
  x_sampa_to_ipa_table.inject(input) do |text, (x_sampa, ipa)|
    text.gsub x_sampa, ipa
  end
end
x_sampa_to_ipa_table() click to toggle source
# File lib/ssmd/annotations/phoneme_annotation.rb, line 37
def x_sampa_to_ipa_table
  @table ||= begin
    lines = File.read(x_sampa_to_ipa_table_file_path).lines

    lines.map { |line| line.split(" ") }
  end
end
x_sampa_to_ipa_table_file_path() click to toggle source
# File lib/ssmd/annotations/phoneme_annotation.rb, line 45
def x_sampa_to_ipa_table_file_path
  Pathname(SSMD.root_dir).join("lib/ssmd/annotations/xsampa_to_ipa_table.txt")
end