Anonymous user
NYSIIS: Difference between revisions
→{{header|REXX}}: added/changed comments and whitespace, changed indentations, aligned statements, simplified logic of the NYSIIS function.
SqrtNegInf (talk | contribs) m (→{{header|Perl 6}}: explicit return of modified variable) |
(→{{header|REXX}}: added/changed comments and whitespace, changed indentations, aligned statements, simplified logic of the NYSIIS function.) |
||
Line 699:
Code was added to the REXX program to allow various titles.
Any post-nominal letters (generational, honorific, professional,or other) ending in a period is ignored as well as
If the rule of only returning (up to) six characters is to be enforced, then the last REXX statement should be
replaced with:
<lang rexx>/*REXX program implements the NYSIIS phonetic algorithm (for various names).*/▼
<lang rexx>return strip( left(key, 6) ) /*return the leftmost six characters.
▲<lang rexx>/*REXX program implements the NYSIIS phonetic algorithm (for various test names). */
names="Bishop brown_sr browne_III browne_IV Carlson Carr Chapman D'Souza de_Sousa Franklin",
"Greene Harper Hoyle-Johnson Jacobs knight Larson Lawrence Lawson Louis_XVI Lynch",
"Mackenzie Marshall,ESQ Matthews McCormack McDaniel McDonald Mclaughlin mitchell Morrison",
"O'Banion O'Brien o'daniel Richards Silva Vaughan_Williams Watkins Wheeler Willis Xavier,MD."
arg z; if z='' then z=names /*
do i=1 for words(z) /*process each name (word) in the list.*/
xx=translate( word(z,i), , '_') /*reconstitute any blanks using TRANS. */
say right(xx,
end /*i*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
nysiis: procedure; arg x; x=space( translate(x, , ',')) /*elide commas, excess blanks*/
w=words(x);
titles= 'ESQ JNR JR SNR SR'
if w\==1 then if pos('IL', lw)==0 then
if left(x,
if left(x,
if left(x, 2)=='PH' | left(x,2)=='PF' then x= 'FF'substr(x, 3) /* " " PH,PF?*/
if left(x, 3)=='SCH' then x= 'SSS'substr(x, 4) /* " " SCH ? */
r2=right(x, 2)
if wordpos(r2, 'EE IE') \==0 then x= left(x,
if wordpos(r2, 'DT RT RD NT ND')\==0 then x= left(x,
key=left(x, 1) /*use first char.*/
do j=2 to length(x); if
if
if $(2)=='KN' then x=left(x, j-1)"N"substr(x, j+1) /*have a KN ? Use N */
else if
if $(3)=='SCH' then x=overlay("SSS", x, j)
if
▲ if c2=='PH' then x=overlay("FF",x,j)
▲ if c=='W' then if vowel(p) then x=overlay("A",x,j)
▲ if c\==right(key,1) then key=key || c
end /*j*/
/* [↓] elide: */
if right(key, 1)=='S' then key=left(key, max(1, length(key) -1)) /*ending S */
if right(key, 2)=='AY' then key=left(key, length(key) -2)"Y" /* " A in AY*/
if right(key, 1)=='A' then key=left(key, max(1, length(key) -1)) /* " A */
return strip(key) /*return the whole key (all of it). */</lang>
▲return strip(key) /*return the whole key. */
▲return strip(left(key, 6)) /*return leftmost six characters. */ /* ◄──── this code isn't executed.*/
▲vowel: return pos(arg(1), 'AEIOUaeiou') \== 0</lang>
'''output''' when using the default input(s):
<pre>
Bishop ──► BASAP
brown sr ──► BRANSR
browne III ──► BRAN
browne IV ──► BRAN
Carlson ──► CARLSAN
Carr ──► CAR
Chapman ──► CAPNAN
D'Souza ──► DSAS
de Sousa ──► DASAS
Franklin ──►
Greene ──► GRAN
Harper ──► HARPAR
Hoyle-Johnson ──► HAYLAJANSAN
Jacobs ──► JACAB
knight ──► NAGT
Larson ──► LARSAN
Lawrence ──► LARANC
Lawson ──► LASAN
Louis XVI ──► L
Lynch ──► LYNC
Mackenzie ──►
Marshall,ESQ ──► MARSALASG
Matthews ──► MAT
McCormack ──►
McDaniel ──► MCDANAL
McDonald ──► MCDANALD
Mclaughlin ──► MCLAGLAN
mitchell ──► MATCAL
Morrison ──► MARASAN
O'Banion ──► OBANAN
O'Brien ──► OBRAN
o'daniel ──► ODANAL
Richards ──► RACARD
Silva ──► SALV
Vaughan Williams ──► VAGANWALAN
Watkins ──►
Wheeler ──► WALAR
Willis ──► WAL
Xavier,MD. ──► XAVAR
</pre>
|