Skip to content

Instantly share code, notes, and snippets.

@Showtimes
Created November 2, 2012 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Showtimes/4002138 to your computer and use it in GitHub Desktop.
Save Showtimes/4002138 to your computer and use it in GitHub Desktop.
metaphone file
def self.lookup(str, pos, length, last)
case str[pos, 1]
when /^A|E|I|O|U|Y$/
if 0 == pos
return 'A', 'A', 1
else
return nil, nil, 1
end
when 'B'
return 'P', 'P', ('B' == str[pos + 1, 1] ? 2 : 1)
when 'Ç'
return 'S', 'S', 1
end
when 'C'
if pos > 1 &&
!vowel?(str[pos - 2, 1]) &&
'ACH' == str[pos - 1, 3] &&
str[pos + 2, 1] != 'I' && (
str[pos + 2, 1] != 'E' ||
str[pos - 2, 6] =~ /^(B|M)ACHER$/
) then
return 'K', 'K', 2
elsif 0 == pos && 'CAESAR' == str[pos, 6]
return 'S', 'S', 2
elsif 'CHIA' == str[pos, 4]
return 'K', 'K', 2
elsif 'CH' == str[pos, 2]
if 0 == pos && 'CHAE' == str[pos, 4]
return 'K', 'X', 2
elsif 0 == pos && (
['HARAC', 'HARIS'].include?(str[pos + 1, 5]) ||
['HOR', 'HYM', 'HIA', 'HEM'].include?(str[pos + 1, 3])
) && str[0, 5] != 'CHORE' then
return 'K', 'K', 2
elsif ['VAN ','VON '].include?(str[0, 4]) ||
'SCH' == str[0, 3] ||
['ORCHES','ARCHIT','ORCHID'].include?(str[pos - 2, 6]) ||
['T','S'].include?(str[pos + 2, 1]) || (
((0 == pos) || ['A','O','U','E'].include?(str[pos - 1, 1])) &&
['L','R','N','M','B','H','F','V','W',' '].include?(str[pos + 2, 1])
) then
return 'K', 'K', 2
elsif pos > 0
return ('MC' == str[0, 2] ? 'K' : 'X'), 'K', 2
else
return 'X', 'X', 2
end
elsif 'CZ' == str[pos, 2] && 'WICZ' != str[pos - 2, 4]
return 'S', 'X', 2
elsif 'CIA' == str[pos + 1, 3]
return 'X', 'X', 3
elsif 'CC' == str[pos, 2] && !(1 == pos && 'M' == str[0, 1])
if /^I|E|H$/ =~ str[pos + 2, 1] && 'HU' != str[pos + 2, 2]
if (1 == pos && 'A' == str[pos - 1, 1]) ||
/^UCCE(E|S)$/ =~ str[pos - 1, 5] then
return 'KS', 'KS', 3
else
return 'X', 'X', 3
end
else
return 'K', 'K', 2
end
elsif /^C(K|G|Q)$/ =~ str[pos, 2]
return 'K', 'K', 2
elsif /^C(I|E|Y)$/ =~ str[pos, 2]
return 'S', (/^CI(O|E|A)$/ =~ str[pos, 3] ? 'X' : 'S'), 2
else
if /^ (C|Q|G)$/ =~ str[pos + 1, 2]
return 'K', 'K', 3
else
return 'K', 'K', (/^C|K|Q$/ =~ str[pos + 1, 1] && !(['CE','CI'].include?(str[pos + 1, 2])) ? 2 : 1)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment