Soundex: Difference between revisions
Content deleted Content added
Drkameleon (talk | contribs) Added Arturo implementation |
Add SenseTalk implementation |
||
Line 4,550: | Line 4,550: | ||
> "M232" |
> "M232" |
||
> "M213" |
> "M213" |
||
</pre> |
|||
=={{header|SenseTalk}}== |
|||
<lang sensetalk>set names to ["Aschraft","Ashcroft","DiBenedetto","Euler","Gauss","Ghosh","Gutierrez", |
|||
"Heilbronn","Hilbert","Honeyman","Jackson","Lee","LeGrand","Lissajous","Lloyd", |
|||
"Moses","Pfister","Robert","Rupert","Rubin","Tymczak","VanDeusen","Van de Graaff","Wheaton"] |
|||
repeat with each name in names |
|||
put !"[[name]] --> [[name's soundex]]" |
|||
end repeat |
|||
to handle soundex of aName |
|||
delete space from aName -- remove spaces |
|||
put the first character of aName into soundex |
|||
replace every occurrence of <{letter:char},{:letter}> with "{:letter}" in aName -- collapse double letters |
|||
delete "H" from aName |
|||
delete "W" from aName |
|||
set prevCode to 0 |
|||
repeat with each character ch in aName |
|||
if ch is in ... |
|||
... "BFPV" then set code to 1 |
|||
... "CGJKQSXZ" then set code to 2 |
|||
... "DT" then set code to 3 |
|||
... "L" then set code to 4 |
|||
... "MN" then set code to 5 |
|||
... "R" then set code to 6 |
|||
... else set code to 0 |
|||
end if |
|||
if code isn't 0 and the counter > 1 and code isn't prevCode then put code after soundex |
|||
put code into prevCode |
|||
end repeat |
|||
set soundex to the first 4 chars of (soundex & "000") -- fill in with 0's as needed |
|||
set prefix to <("Van" or "Con" or "De" or "Di" or "La" or "Le") followed by a capital letter> |
|||
if aName begins with prefix then |
|||
put aName into nameWithoutPrefix |
|||
delete the first occurrence of prefix in nameWithoutPrefix |
|||
return [soundex, soundex of nameWithoutPrefix] |
|||
end if |
|||
return soundex |
|||
end soundex |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
Aschraft --> A261 |
|||
Ashcroft --> A261 |
|||
DiBenedetto --> ["D153","B533"] |
|||
Euler --> E460 |
|||
Gauss --> G200 |
|||
Ghosh --> G200 |
|||
Gutierrez --> G362 |
|||
Heilbronn --> H416 |
|||
Hilbert --> H416 |
|||
Honeyman --> H555 |
|||
Jackson --> J250 |
|||
Lee --> L000 |
|||
LeGrand --> ["L265","G653"] |
|||
Lissajous --> L222 |
|||
Lloyd --> L300 |
|||
Moses --> M220 |
|||
Pfister --> P236 |
|||
Robert --> R163 |
|||
Rupert --> R163 |
|||
Rubin --> R150 |
|||
Tymczak --> T522 |
|||
VanDeusen --> ["V532","D250"] |
|||
Van de Graaff --> V532 |
|||
Wheaton --> W350 |
|||
</pre> |
</pre> |
||