Lingua-RU-NameParse
view release on metacpan or search on metacpan
NameParse.pm view on Meta::CPAN
package Lingua::RU::NameParse;
use 5.008;
use strict;
use warnings;
our $VERSION = '0.02';
sub new { my $class = shift;
bless {}, $class; }
=item normalize NAME
Given a first name and a patronymic, returns the name and patronymic in the nominative
case.
=cut
sub normalize {
my ( $self, $testme ) = @_;
use utf8;
# voodo to set the string's UTF8 flag
$testme = pack 'U*', unpack( 'U*', $testme );
my ( $w1, $w2 ) = split m/\s+/, $testme;
##################
# ACCUSATIVE
##################
if ( $w2 =~ /[Ñк]а$/ ) {
$w2 =~ s/а$//g;
$w1 =~ s/а$//g;
$w1 =~ s/Ñ$/й/g;
}
elsif ( $w2 =~ /овнÑ\b/ ) {
$w2 =~ s/Ñ\b/а/;
$w1 =~ s/ÑÑ\b/ÑÑ/;
$w1 =~ s/иÑ\b/иÑ/;
}
################
# DATIVE
################
elsif ( $w2 =~ /не\b/ ) {
$w2 =~ s/е\b/а/;
$w1 =~ s/Ñе\b/ÑÑ/;
$w1 =~ s/е\b/а/;
$w1 =~ s/ии\b/иÑ/;
}
elsif ( $w2 =~ /Ñе\b/ ) {
$w2 =~ s/е$//;
$w1 =~ s/ее\b/ей/; # aleksei
}
# ÐонÑÑанÑÐ¸Ð½Ñ ÐевинÑ
elsif ( $w2 =~ /[нÑ]Ñ$/ ) {
$w2 =~ s/Ñ$//;
$w1 =~ s/Ñ\b//;
$w1 =~ s/([еи])Ñ\b/$1й/;
}
###################
# INSTRUMENTAL
###################
# ÐеÑой ÐавловноÑ
elsif ( $w2 =~ /но[Ñй]$/ ) {
$w2 =~ s/оÑ$/а/;
$w2 =~ s/ой$/а/;
$w1 =~ s/ой$/а/;
$w1 =~ s/еÑ/Ñ/;
$w1 =~ s/ей/Ñ/;
}
elsif ( $w2 =~ /ем$/ ) {
$w2 =~ s/ем\b//;
$w1 =~ s/ом\b//;
$w1 =~ s/еем\b/ей/;
}
( run in 0.915 second using v1.01-cache-2.11-cpan-71847e10f99 )