Module: Music::Text::Normalization

Defined in:
lib/music/text/normalization.rb,
lib/music/text/normalization/version.rb

Constant Summary collapse

VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

.normalize_artist_name(text) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/music/text/normalization.rb', line 7

def normalize_artist_name(text)
  lowercase_name = text.
                   tr("0-9A-Za-z", "0-9A-Za-z").
                   downcase

  case lowercase_name
  when 'bruce springsteen and the e street band'
    'bruce_springsteen'
  when 'tom petty and the hearbreakers'
    'tom_petty'
  when 'bob marley and the wailers'
    'bob_marley'
  when 'the beatles'
    'the_beatles'
  when 'the verve'
    'the_verve'
  else
    lowercase_name.
      gsub(/['\.]/, '').
      sub(/^(a|an|the)\ +/, '').
      gsub(/[^a-z0-9\p{Hiragana}\p{Katakana}ー-一-龠々]+/, '_').
      sub(/^_/, '').sub(/_$/, '')
  end
end