Soundex: Difference between revisions

add NetRexx
(add NetRexx)
Line 2,652:
USER>W $$SOUNDEX^SOUNDEX("ghoti")
G300</pre></p>
 
=={{header|NetRexx}}==
{{trans|Rexx}}
<lang NetRexx>
class Soundex
 
method get_soundex(in_) static
in = in_.upper()
old_alphabet= 'AEIOUYHWBFPVCGJKQSXZDTLMNR'
new_alphabet= '@@@@@@**111122222222334556'
word=''
loop i=1 for in.length()
tmp_=in.substr(i, 1) /*obtain a character from word*/
if tmp_.datatype('M') then word=word||tmp_
end
 
value=word.strip.left(1) /*1st character is left alone.*/
word=word.translate(new_alphabet, old_alphabet) /*define the current word. */
prev=value.translate(new_alphabet, old_alphabet) /* " " previous " */
 
loop j=2 to word.length() /*process remainder of word. */
q=word.substr(j, 1)
if q\==prev & q.datatype('W') then do
value=value || q; prev=q
end
else if q=='@' then prev=q
end /*j*/
 
return value.left(4,0) /*padded value with zeroes. */
 
method main(args=String[]) static
 
test=''; result_=''
test['1']= "12346" ; result_['1']= '0000'
test['4']= "4-H" ; result_['4']= 'H000'
test['11']= "Ashcraft" ; result_['11']= 'A261'
test['12']= "Ashcroft" ; result_['12']= 'A261'
test['18']= "auerbach" ; result_['18']= 'A612'
test['20']= "Baragwanath" ; result_['20']= 'B625'
test['22']= "bar" ; result_['22']= 'B600'
test['23']= "barre" ; result_['23']= 'B600'
test['20']= "Baragwanath" ; result_['20']= 'B625'
test['28']= "Burroughs" ; result_['28']= 'B620'
test['29']= "Burrows" ; result_['29']= 'B620'
test['30']= "C.I.A." ; result_['30']= 'C000'
test['37']= "coöp" ; result_['37']= 'C100'
test['43']= "D-day" ; result_['43']= 'D000'
test['44']= "d jay" ; result_['44']= 'D200'
test['45']= "de la Rosa" ; result_['45']= 'D462'
test['46']= "Donnell" ; result_['46']= 'D540'
test['47']= "Dracula" ; result_['47']= 'D624'
test['48']= "Drakula" ; result_['48']= 'D624'
test['49']= "Du Pont" ; result_['49']= 'D153'
test['50']= "Ekzampul" ; result_['50']= 'E251'
test['51']= "example" ; result_['51']= 'E251'
test['55']= "Ellery" ; result_['55']= 'E460'
test['59']= "Euler" ; result_['59']= 'E460'
test['60']= "F.B.I." ; result_['60']= 'F000'
test['70']= "Gauss" ; result_['70']= 'G200'
test['71']= "Ghosh" ; result_['71']= 'G200'
test['72']= "Gutierrez" ; result_['72']= 'G362'
test['80']= "he" ; result_['80']= 'H000'
test['81']= "Heilbronn" ; result_['81']= 'H416'
test['84']= "Hilbert" ; result_['84']= 'H416'
test['100']= "Jackson" ; result_['100']= 'J250'
test['104']= "Johnny" ; result_['104']= 'J500'
test['105']= "Jonny" ; result_['105']= 'J500'
test['110']= "Kant" ; result_['110']= 'K530'
test['116']= "Knuth" ; result_['116']= 'K530'
test['120']= "Ladd" ; result_['120']= 'L300'
test['124']= "Llyod" ; result_['124']= 'L300'
test['125']= "Lee" ; result_['125']= 'L000'
test['126']= "Lissajous" ; result_['126']= 'L222'
test['128']= "Lukasiewicz" ; result_['128']= 'L222'
test['130']= "naïve" ; result_['130']= 'N100'
test['141']= "Miller" ; result_['141']= 'M460'
test['143']= "Moses" ; result_['143']= 'M220'
test['146']= "Moskowitz" ; result_['146']= 'M232'
test['147']= "Moskovitz" ; result_['147']= 'M213'
test['150']= "O'Conner" ; result_['150']= 'O256'
test['151']= "O'Connor" ; result_['151']= 'O256'
test['152']= "O'Hara" ; result_['152']= 'O600'
test['153']= "O'Mally" ; result_['153']= 'O540'
test['161']= "Peters" ; result_['161']= 'P362'
test['162']= "Peterson" ; result_['162']= 'P362'
test['165']= "Pfister" ; result_['165']= 'P236'
test['180']= "R2-D2" ; result_['180']= 'R300'
test['182']= "rÄ≈sumÅ∙" ; result_['182']= 'R250'
test['184']= "Robert" ; result_['184']= 'R163'
test['185']= "Rupert" ; result_['185']= 'R163'
test['187']= "Rubin" ; result_['187']= 'R150'
test['191']= "Soundex" ; result_['191']= 'S532'
test['192']= "sownteks" ; result_['192']= 'S532'
test['199']= "Swhgler" ; result_['199']= 'S460'
test['202']= "'til" ; result_['202']= 'T400'
test['208']= "Tymczak" ; result_['208']= 'T522'
test['216']= "Uhrbach" ; result_['216']= 'U612'
test['221']= "Van de Graaff" ; result_['221']= 'V532'
test['222']= "VanDeusen" ; result_['222']= 'V532'
test['230']= "Washington" ; result_['230']= 'W252'
test['233']= "Wheaton" ; result_['233']= 'W350'
test['234']= "Williams" ; result_['234']= 'W452'
test['236']= "Woolcock" ; result_['236']= 'W422'
 
loop i over test
say test[i].left(10) get_soundex(test[i]) '=' result_[i]
end
</lang>
{{out}}
<pre>
barre B600 = B600
Wheaton W350 = W350
Knuth K530 = K530
auerbach A612 = A612
Ekzampul E251 = E251
D-day D000 = D000
example E251 = E251
4-H H000 = H000
Burroughs B620 = B620
d jay D200 = D200
F.B.I. F000 = F000
Lissajous L222 = L222
Burrows B620 = B620
coöp C100 = C100
de la Rosa D462 = D462
Gauss G200 = G200
Donnell D540 = D540
Ghosh G200 = G200
Dracula D624 = D624
Ellery E460 = E460
he H000 = H000
Gutierrez G362 = G362
Drakula D624 = D624
Williams W452 = W452
Heilbronn H416 = H416
Du Pont D153 = D153
Robert R163 = R163
Pfister P236 = P236
Moskowitz M232 = M232
Euler E460 = E460
Hilbert H416 = H416
Rupert R163 = R163
Uhrbach U612 = U612
Moskovitz M213 = M213
Lukasiewic L222 = L222
Woolcock W422 = W422
Tymczak T522 = T522
Rubin R150 = R150
Swhgler S460 = S460
Jackson J250 = J250
Kant K530 = K530
Ladd L300 = L300
naïve N100 = N100
O'Conner O256 = O256
Miller M460 = M460
O'Connor O256 = O256
Washington W252 = W252
R2-D2 R300 = R300
Peters P362 = P362
Van de Gra V532 = V532
Johnny J500 = J500
'til T400 = T400
O'Hara O600 = O600
Peterson P362 = P362
Moses M220 = M220
Llyod L300 = L300
Soundex S532 = S532
VanDeusen V532 = V532
Jonny J500 = J500
O'Mally O540 = O540
12346 000 = 0000
Ashcraft A261 = A261
rÄ≈sumÅ∙ R250 = R250
Ashcroft A261 = A261
Baragwanat B625 = B625
Lee L000 = L000
bar B600 = B600
C.I.A. C000 = C000
sownteks S532 = S532
</pre>
 
=={{header|OCaml}}==
41

edits