Acme-Nyaa
view release on metacpan or search on metacpan
lib/Acme/Nyaa/Ja.pm view on Meta::CPAN
package Acme::Nyaa::Ja;
use parent 'Acme::Nyaa';
use strict;
use warnings;
use utf8;
my $RxComma = qr/[ã(?:, )]/;
my $RxPeriod = qr/[ãï¼]/;
my $RxEndOfList = qr#[ï¼)-=+|}ï¼>/:;"'`\]]#;
my $RxConversation = qr/[ãã].+[ãã]/;
my $RxEndOfSentence = qr/(?:[!ï¼?ï¼â¦]+|[.]{2,}|[ã]{2,}|[ã]{2,}|[,]{2,})/;
my $Cats = [ 'ç«', 'ãã³', 'ãã' ];
my $Separator = qq(\x1f\x1f\x1f);
my $HiraganaNya = 'ã«ã';
my $KatakanaNya = 'ãã£';
my $FightingCats = [
'ããã¼ãªã',
'ããã¼ãª!ã',
'ããã¼ã¼ãªã',
'ããã¼ã¼ãª!ã',
'ããã¼ã¼ã¼ãª!!ã',
'ããã¼ã¼ã¼ã¼ãª!!!ã',
];
my $Copulae = [ 'ã ', 'ã§ã', 'ã§ãã', 'ã©ã', 'ãããããªã', 'ããã', 'ããã§ã' ];
my $HiraganaTails = [
'ã«ã', 'ã«ãã¼', 'ã«ãã', 'ã«ãã¼ã¼ã¼ã¼!', 'ã«ãã', 'ã«ãã¼ã', 'ã«ããã',
'ã«ãã¼!', 'ã«ãã¼ã¼ã¼!!', 'ã«ãã¼ã¼!',
];
my $KatakanaTails = [
'ãã£', 'ãã£ã¼', 'ãã£ã', 'ãã£ã¼ã¼ã¼ã¼!', 'ãã£ã', 'ãã£ã¼ã', 'ãã£ãã',
'ãã£ã¼!', 'ãã£ã¼ã¼ã¼!!', 'ãã£ã¼ã¼!',
];
my $DoNotBecomeCat = [
# See http://ja.wikipedia.org/wiki/ã¢ã¼ãã³ã°å¨ã
'ã¢ã¼ãã³ã°å¨ã',
'ã«ã³ããªã¼å¨ã',
'ã³ã³ãããå¨ã',
'ããã¢ãã',
'ã¨ã³ã¢ãã',
'ããã¼!ã¢ã¼ãã³ã°ã',
'ã¨ã¢ã¢ãã',
'ã¢ã¼ãã³ã°åäºã',
'ã¢ã¼å¨ã',
];
sub new {
# Constructor
my $class = shift;
my $argvs = { @_ };
return $class if ref $class eq __PACKAGE__;
$argvs->{'language'} = 'ja';
return bless $argvs, __PACKAGE__;
}
sub language {
# Set language to use
my $self = shift;
$self->{'language'} ||= 'ja';
return $self->{'language'};
}
sub object {
# Wrapper method for new()
my $self = shift;
return __PACKAGE__->new unless ref $self;
return $self;
}
*objects = *object;
*findobject = *object;
sub cat {
my $self = shift;
my $argv = shift;
my $flag = shift // 0;
my $ref1 = ref $argv;
my $text = undef;
my $neko = undef;
my $nyaa = undef;
return q() if( $ref1 ne '' && $ref1 ne 'SCALAR' );
$text = $ref1 eq 'SCALAR' ? $$argv: $argv;
return q() unless length $text;
eval {
$self->reckon( \$text );
$neko = $self->toutf8( $text );
};
return $text if $@;
$neko =~ s{($RxPeriod)}{$1$Separator}g;
$neko .= $Separator unless $neko =~ m{$Separator};
my $hiralength = scalar @$HiraganaTails;
my $katalength = scalar @$KatakanaTails;
my $writingset = [ split( $Separator, $neko ) ];
my $haschomped = 0;
my ( $r1,$r2 ) = 0;
for my $e ( @$writingset ) {
next if $e =~ m/\A$RxPeriod\s*\z/;
next if $e =~ m/$RxEndOfList\s*\z/;
next if grep { $e =~ m/\A$_\s*/ } @$DoNotBecomeCat;
next if grep { $e =~ m/$_$RxPeriod?\z/ } @$HiraganaTails;
next if grep { $e =~ m/$_$RxPeriod?\z/ } @$KatakanaTails;
next if grep { $e =~ m/$_$RxEndOfSentence?\s*\z/ } @$HiraganaTails;
next if grep { $e =~ m/$_$RxEndOfSentence?\s*\z/ } @$KatakanaTails;
next if grep { $e =~ m/$_\s*\z/ } @$FightingCats;
# Do not convert if the string contain only ASCII characters.
( run in 1.779 second using v1.01-cache-2.11-cpan-5735350b133 )