NYSIIS: Difference between revisions
Content deleted Content added
Thundergnat (talk | contribs) →{{header|Perl 6}}: Added a Perl 6 entry |
→{{header|Perl 6}}: style |
||
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) { |
||
⚫ | |||
sub no_suffix ($name is copy) { |
|||
$name .= uc; |
|||
⚫ | |||
} |
} |
||
sub nysiis ($name is copy) { |
sub nysiis ($name is copy) { |
||
$name .= uc |
given $name .= uc { |
||
s:g/<-[A..Z]>//; |
|||
s/^MAC/MCC/; |
|||
s/^P<[FH]>/FF/; |
|||
s/^SCH/SSS/; |
|||
s/^KN/N/; |
|||
s/<[IE]>E$ /Y/; |
|||
s/<[DRN]>T$ /D/; |
|||
s/<[RN]>D$ /D/; |
|||
s:c(1):g/EV/AF/; |
|||
s:c(1):g/<[AEIOU]>+/A/; |
|||
$name.=subst( /EV/, 'AF', :g )\ |
|||
s:c(1):g/Q/G/; |
|||
s:c(1):g/Z/S/; |
|||
s:c(1):g/M/N/; |
|||
s:c(1):g/KN/N/; |
|||
s:c(1):g/K/C/; |
|||
s:c(1):g/SCH/S/; |
|||
s:c(1):g/PF/F/; |
|||
s:c(1):g/K/C/; |
|||
s:c(1):g/H(<-[AEIOU]>)/$0/; |
|||
s:g/(<-[AEIOU]>)H/$0/; |
|||
s:g/(<-[AEIOU]>)W/$0/; |
|||
s:g/ AY$ /Y/; |
|||
$name.subst( /(<-[AEIOU]>)H/, -> $/ {$0}, :g )\ |
|||
s:g/ S$ //; |
|||
s:g/ A$ //; |
|||
s:g/ (.)+ /$0.join()/; |
|||
} |
|||
.subst( /A$/ , '' )\ |
|||
⚫ | |||
} |
} |
||
my $nysiis; |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
?? $nysiis.subst( / (.**6) /, -> $/ { $0 ~ '[' } ) ~ ']' |
|||
Silva McDonald Lawson Jacobs Greene |
|||
!! $nysiis |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
Carlson Wheeler "Louis XVI" |
|||
» { |
|||
⚫ | |||
⚫ | |||
⚫ | |||
if $nysiis.chars > 6 { |
|||
⚫ | |||
⚫ | |||
"Carlson", "Wheeler" , "Louis XVI" |
|||
} |
|||
⚫ | |||
</lang> |
}</lang> |
||
Output: |
Output: |