Skip to content

Instantly share code, notes, and snippets.

@njh
Created December 28, 2010 18:38
Show Gist options
  • Select an option

  • Save njh/757525 to your computer and use it in GitHub Desktop.

Select an option

Save njh/757525 to your computer and use it in GitHub Desktop.
def extract_pronunciation(string)
result = string.dup
regexes = {
%r[\(IPA: ["\[/].*?["\]/]\) ] => '',
%r[\(pronounced ["\[/].*?["\]/]\) ] => '',
# for when pronounciation is mixed in with birthdate, e.g. (pronounced /bəˈɹɛlɪs/; born December 7, 1979)
%r[pronounced ["\[/].*?["\]/]\; ] => '',
}
for regex in regexes.keys
if result =~ regex
result.sub!(regex, regexes[regex])
break
end
end
return result
end
def test_extract_pronunciation
examples = {
'U2 (IPA: /ˌjuːˈtuː/) are a rock band from Dublin,' => 'U2 are a rock band from Dublin,',
'Albert Camus (IPA: [albɛʁ kamy]) is ' => 'Albert Camus is ',
'Anton Corbijn (pronounced [kɔrˈbɛin]) (born May 20, 1955) ' => 'Anton Corbijn (born May 20, 1955) ',
'Breed 77 (pronounced "Breed Seven-Seven") is a band whose' => 'Breed 77 is a band whose',
'Sara Beth Bareilles (pronounced /bəˈɹɛlɪs/; born December 7, 1979) is an American' => 'Sara Beth Bareilles (born December 7, 1979) is an American'
}
examples.keys.each do |string|
assert_equal examples[string], @tapp.send(:extract_pronunciation, string)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment