Class: Phonetic::Caverphone

Inherits:
Algorithm show all
Defined in:
lib/phonetic/caverphone.rb

Overview

Caverphone created by the Caversham Project at the University of Otago. This class implements this algorithm.

Examples:

Phonetic::Caverphone.encode('Charmain') # => 'KMN111'
Phonetic::Caverphone.encode('Ellett')   # => 'ALT111'
Phonetic::Caverphone.encode('Siegmund') # => 'SKMNT1'

See Also:

Constant Summary collapse

MAP =
{
  /^(cou|rou|tou|enou)gh/ => '\12f',
  /^gn/ => '2n',
  /mb$/ => 'mb',
  'cq' => '2q',
  /c([iey])/ => 's\1',
  'tch' => '2ch',
  /[cqx]/ => 'k',
  'v' => 'f',
  'dg' => '2g',
  /ti([oa])/ => 'si\1',
  'd' => 't',
  'ph' => 'fh',
  'b' => 'p',
  'sh' => 's2',
  'z' => 's',
  /^[aeiou]/ => 'A',
  /[aeiou]/ => '3',
  '3gh3' => '3kh3',
  'gh' => '22',
  'g' => 'k',
  /s+/ => 'S',
  /t+/ => 'T',
  /p+/ => 'P',
  /k+/ => 'K',
  /f+/ => 'F',
  /m+/ => 'M',
  /n+/ => 'N',
  'w3' => 'W3',
  /wy/ => 'Wy',
  'wh3' => 'Wh3',
  'why' => 'Why',
  'w' => '2',
  /^h/ => 'A',
  'h' => '2',
  'r3' => 'R3',
  'ry' => 'Ry',
  'r' => '2',
  'l3' => 'L3',
  'ly' => 'Ly',
  'l' => '2',
  'j' => 'y',
  'y3' => 'Y3',
  'y' => '2',
  '2' => '',
  '3' => ''
}

Class Method Summary collapse

Methods inherited from Algorithm

encode

Class Method Details

.encode_word(word, options = {}) ⇒ Object

Encode word to its Caverphone code



61
62
63
64
65
66
# File 'lib/phonetic/caverphone.rb', line 61

def self.encode_word(word, options = {})
  w = word.strip.downcase.gsub(/[^a-z]/, '')
  MAP.each { |r, v| w.gsub!(r, v) }
  w = w + '1' * 6
  w[0..5]
end