Created
August 9, 2011 16:34
-
-
Save kwik101/1134511 to your computer and use it in GitHub Desktop.
soundex with Russian launguage support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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