NYSIIS: Difference between revisions

Content deleted Content added
Thundergnat (talk | contribs)
→‎{{header|Perl 6}}: Added a Perl 6 entry
Grondilu (talk | contribs)
Line 199: Line 199:
This implementation removes common name suffixes similar to the reference implementation, even though it is not specified in the task description or on the linked [[wp:New York State Identification and Intelligence System|NYSIIS]] page. This algorithm isn't too friendly to certain French kings. :)
This implementation removes common name suffixes similar to the reference implementation, even though it is not specified in the task description or on the linked [[wp:New York State Identification and Intelligence System|NYSIIS]] page. This algorithm isn't too friendly to certain French kings. :)


<lang perl6>
<lang perl6>sub no_suffix ($name) {
$name.uc.subst: /\h (<[JS]>R) | (<[IVX]>+) $/, '';
sub no_suffix ($name is copy) {
$name .= uc;
$name.subst( /\h (<[JS]>R) | (<[IVX]>+) $/, '' );
}
}


sub nysiis ($name is copy) {
sub nysiis ($name is copy) {
$name .= uc;
given $name .= uc {
$name.=subst( /<-[A..Z]>/, '', :g )\
s:g/<-[A..Z]>//;
.=subst( /^MAC/, 'MCC' )\
s/^MAC/MCC/;
.=subst( /^P<[FH]>/, 'FF' )\
s/^P<[FH]>/FF/;
.=subst( /^SCH/, 'SSS' )\
s/^SCH/SSS/;
.=subst( /^KN/, 'N' )\
s/^KN/N/;
.=subst( /<[IE]>E$/, 'Y' )\
s/<[IE]>E$ /Y/;
.=subst( /<[DRN]>T$/, 'D' )\
s/<[DRN]>T$ /D/;
.=subst( /<[RN]>D$/, 'D' );
s/<[RN]>D$ /D/;
my $first = substr-rw( $name, 0, 1 ) = '';
s:c(1):g/EV/AF/;
s:c(1):g/<[AEIOU]>+/A/;
$name.=subst( /EV/, 'AF', :g )\
.=subst( /<[AEIOU]>+/, 'A', :g )\
s:c(1):g/Q/G/;
.=subst( /Q/, 'G', :g )\
s:c(1):g/Z/S/;
.=subst( /Z/, 'S', :g )\
s:c(1):g/M/N/;
.=subst( /M/, 'N', :g )\
s:c(1):g/KN/N/;
.=subst( /KN/, 'N', :g )\
s:c(1):g/K/C/;
.=subst( /K/, 'C', :g )\
s:c(1):g/SCH/S/;
.=subst( /SCH/, 'S', :g )\
s:c(1):g/PF/F/;
.=subst( /PF/, 'F', :g )\
s:c(1):g/K/C/;
.=subst( /K/ , 'C', :g )\
s:c(1):g/H(<-[AEIOU]>)/$0/;
.=subst( /H(<-[AEIOU]>)/, -> $/ {$0}, :g );
s:g/(<-[AEIOU]>)H/$0/;
$name = $first ~ $name;
s:g/(<-[AEIOU]>)W/$0/;
s:g/ AY$ /Y/;
$name.subst( /(<-[AEIOU]>)H/, -> $/ {$0}, :g )\
.subst( /(<[AEIOU]>)W/, -> $/ {$0}, :g )\
s:g/ S$ //;
.subst( /AY$/, 'Y', :g )\
s:g/ A$ //;
.subst( /S$/ , '' )\
s:g/ (.)+ /$0.join()/;
}
.subst( /A$/ , '' )\
.subst( /(.)$0+/, -> $/ {$0}, :g );
}
}


my $nysiis;


for «
printf "%10s, %s\n", $_,
knight mitchell "o'daniel" "brown sr" "browne III"
( $nysiis = nysiis no_suffix $_ ).chars > 6
"browne IV" "O'Banion" Mclaughlin McCormack Chapman
?? $nysiis.subst( / (.**6) /, -> $/ { $0 ~ '[' } ) ~ ']'
Silva McDonald Lawson Jacobs Greene
!! $nysiis
"O'Brien" Morrison Larson Willis Mackenzie
for (
Carr Lawrence Matthews Richards Bishop
"knight", "mitchell", "o'daniel", "brown sr", "browne III",
Franklin McDaniel Harper Lynch Watkins
"browne IV", "O'Banion", "Mclaughlin", "McCormack", "Chapman",
"Silva", "McDonald", "Lawson", "Jacobs", "Greene",
Carlson Wheeler "Louis XVI"
» {
"O'Brien", "Morrison", "Larson", "Willis", "Mackenzie",
my $nysiis = nysiis no_suffix $_;
"Carr", "Lawrence", "Matthews", "Richards", "Bishop",
if $nysiis.chars > 6 {
"Franklin", "McDaniel", "Harper", "Lynch", "Watkins",
$nysiis .= subst: rx/ <after .**6> .+ /, -> $/ { "[$/]" };
"Carlson", "Wheeler" , "Louis XVI"
);
}
printf "%10s, %s\n", $_, $nysiis;

</lang>
}</lang>


Output:
Output: