Anonymous user
NYSIIS: Difference between revisions
m
→{{header|REXX}}: added/changed whitespace and comments, used a template for the output section.
(Added Wren) |
m (→{{header|REXX}}: added/changed whitespace and comments, used a template for the output section.) |
||
Line 1,564:
<lang rexx>return strip( left(key, 6) ) /*return the leftmost six characters. */</lang>
<lang rexx>/*REXX program implements the NYSIIS phonetic algorithm (for various test names). */
parse upper arg z; if z='' then z=
do i=1 for words(z) /*process each name (word) in the list.*/
xx= translate( word(z, i), , '_')
say right(xx, 35) ' ──► ' nysiis(xx) /*display some stuff to the terminal. */
end /*i*/
exit
/*──────────────────────────────────────────────────────────────────────────────────────*/
$: p= substr(x,j-1,1) /*prev*/;
vowel: return pos(arg(1), 'AEIOUaeiou') \== 0 /*returns 1 if the argument has a vowel*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
nysiis: procedure;
w= words(x);
@titles= 'ESQ JNR JR SNR SR'
if w\==1 then if pos('IL', lw)==0 then /*disallow IL as Roman #.
if pos(., x)\==0 |,
datatype( left(Lw, 1), 'W') |,
verify(Lw, 'IVXL') ==0
wordpos(x, @titles)\==0 then x= subword(x, 1, w-1)
x= space(x, 0)
if left(x, 3)=='MAC' then x=
if left(x, 2)=='KN' then x=
if left(x, 1)=='K' then x=
if left(x, 2)=='PH' | left(x,2)==
if left(x, 3)=='SCH' then x=
r2= right(x, 2)
if wordpos(r2, 'EE IE') \==0 then x= left(x, length(x)-2)"Y"
if wordpos(r2, 'DT RT RD NT ND')\==0 then x= left(x, length(x)-2)"D"
key= left(x, 1)
do j=2 to length(x);
if $(2)=='EV' then x= overlay("F", x, j+1)
else x= overlay( translate( $(1), 'AAAAGSN', "EIOUQZM"), x, j)
if $(2)=='KN' then x= left(x, j-1)"N"substr(x, j+1)
else if $(1)=="K" then x= overlay('C',x,j)
if $(3)=='SCH' then x= overlay("SSS", x, j)
if $(2)=='PH' then x= overlay("FF", x, j)
if $(1)=='H' then if \vowel(p) | \vowel(n) then x= overlay( p , x, j)
if $(1)=='W' then if vowel(p) then x= overlay("A", x, j)
if $(1)\== right(key, 1)
end /*j*/
/* [↓] elide: */
if right(key, 1)=='S' then key= left(key, max(1, length(key) -1))
if right(key, 2)=='AY' then key= left(key, length(key) -2)"Y"
if right(key, 1)=='A' then key= left(key, max(1, length(key) -1))
return strip(key) /*return the whole key (all of it). */</lang>
<pre>
Bishop ──► BASAP
|