Skip to content

Instantly share code, notes, and snippets.

@kwik101
Created August 9, 2011 16:34
Show Gist options
  • Select an option

  • Save kwik101/1134511 to your computer and use it in GitHub Desktop.

Select an option

Save kwik101/1134511 to your computer and use it in GitHub Desktop.
soundex with Russian launguage support
exports.rules = rules = []
exports.addRule = addRule = (from, to) ->
rules.push {
from: from
to: to
}
addRule /[aehiouy]/g, ''
addRule /[йуеёыахоэяиюьъ]/g, ''
addRule /[с]?тч/g, 'щ'
addRule /rl/g, 'r'
addRule /[bfpvw]/g, '1'
addRule /[бфпв]/g, '1'
addRule /[cgjkqsxz]/g, '2'
addRule /[цжкзсг]/g, '2'
addRule /[dt]/g, '3'
addRule /[дтщшч]/g, '3'
addRule /[l]/g, '4'
addRule /[л]/g, '4'
addRule /[mn]/g, '5'
addRule /[мн]/g, '5'
addRule /[r]/g, '6'
addRule /[р]/g, '6'
#remove dublicates
addRule /([0-9])(\1{1,})/g, '$1'
exports.soundex = soundex = (word) ->
w = word.toLowerCase()
for rule in rules
w = w.replace rule.from, rule.to
return w
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment