Acme-AjiFry
view release on metacpan or search on metacpan
lib/Acme/AjiFry.pm view on Meta::CPAN
package Acme::AjiFry;
use warnings;
use strict;
use utf8;
use Encode;
use List::Util;
our $VERSION = '0.09';
use constant COLS => {
a => [
'ã', 'ã', 'ã', 'ã', 'ãª', 'ã¯', 'ã¾', 'ã', 'ã', 'ã',
'ã', 'ã', 'ã ', 'ã°', 'ã±', 'ã', 'ã', 'ã'
],
i => [
'ã', 'ã', 'ã', 'ã¡', 'ã«', 'ã²', 'ã¿', 'ã',
'ã', 'ã', 'ã¢', 'ã³', 'ã´', 'ã'
],
u => [
'ã', 'ã', 'ã', 'ã¤', 'ã¬', 'ãµ', 'ã', 'ã', 'ã', 'ã',
'ã', 'ã¥', 'ã¶', 'ã·', 'ã
', 'ã£', 'ã
'
],
e => [
'ã', 'ã', 'ã', 'ã¦', 'ã', 'ã¸', 'ã', 'ã',
'ã', 'ã', 'ã§', 'ã¹', 'ãº', 'ã',
],
o => [
'ã', 'ã', 'ã', 'ã¨', 'ã®', 'ã»', 'ã', 'ã', 'ã', 'ã',
'ã', 'ã', 'ã©', 'ã¼', 'ã½', 'ã', 'ã'
],
n => ['ã'],
};
use constant ROWS => {
a =>
[ 'ã', 'ã', 'ã', 'ã', 'ã', 'ã', 'ã', 'ã
', 'ã', 'ã' ],
k =>
[ 'ã', 'ã', 'ã', 'ã', 'ã', 'ã', 'ã', 'ã', 'ã', 'ã' ],
s =>
[ 'ã', 'ã', 'ã', 'ã', 'ã', 'ã', 'ã', 'ã', 'ã', 'ã' ],
t => [
'ã', 'ã¡', 'ã¤', 'ã¦', 'ã¨', 'ã ',
'ã¢', 'ã¥', 'ã§', 'ã©', 'ã£'
],
n => [ 'ãª', 'ã«', 'ã¬', 'ã', 'ã®' ],
h => [
'ã¯', 'ã²', 'ãµ', 'ã¸', 'ã»', 'ã°', 'ã³', 'ã¶',
'ã¹', 'ã¼', 'ã±', 'ã´', 'ã·', 'ãº', 'ã½'
],
m => [ 'ã¾', 'ã¿', 'ã', 'ã', 'ã' ],
y => [ 'ã', 'ã', 'ã', 'ã', 'ã
', 'ã' ],
r => [ 'ã', 'ã', 'ã', 'ã', 'ã' ],
w => [ 'ã', 'ã', 'ã' ],
};
use constant DULLNESS => [
'ã', 'ã', 'ã', 'ã', 'ã', 'ã', 'ã', 'ã', 'ã', 'ã',
'ã ', 'ã¢', 'ã¥', 'ã§', 'ã©', 'ã°', 'ã³', 'ã¶', 'ã¹', 'ã¼'
];
use constant P_SOUND => [ 'ã±', 'ã´', 'ã·', 'ãº', 'ã½' ];
use constant DOUBLE_CONSONANT =>
[ 'ã', 'ã', 'ã
', 'ã', 'ã', 'ã£', 'ã', 'ã
', 'ã', 'ã' ];
sub new {
my $class = shift;
return $class;
}
sub to_AjiFry {
my ( $self, $raw_string ) = @_;
my $chomped = chomp($raw_string);
unless ($raw_string) {
return "\n" if $chomped;
return '';
}
$raw_string = decode_utf8($raw_string);
my $ajifry_word = $self->_to_ajifry($raw_string);
$ajifry_word .= "\n" if $chomped;
return encode_utf8($ajifry_word);
}
sub translate_to_ajifry {
my ( $self, $raw_string ) = @_;
return $self->to_AjiFry($raw_string);
}
sub to_Japanese {
my ( $self, $ajifry_word ) = @_;
my $chomped = chomp($ajifry_word);
unless ($ajifry_word) {
return "\n" if $chomped;
return '';
}
$ajifry_word = decode_utf8($ajifry_word);
my $japanese_word = $self->_to_Japanese($ajifry_word);
$japanese_word .= "\n" if $chomped;
return encode_utf8($japanese_word);
}
sub translate_from_ajifry {
my ( $self, $ajifry_word ) = @_;
return $self->to_Japanese($ajifry_word);
}
sub _search_key_of_element {
my ( $self, $element, $hash ) = @_;
foreach my $key ( sort keys %$hash ) {
if ( List::Util::first { $_ eq $element } @{ $hash->{$key} } ) {
return $key;
}
}
}
sub _find_first {
my ( $self, $key, $list ) = @_;
return ( List::Util::first { $_ eq $key } @$list ) ? 1 : 0;
}
sub _find_duplicate_element_in_both_lists {
my $self = shift;
my ( $list_A, $list_B ) = @_;
my @duplicate_elements;
foreach my $element_A ( @{$list_A} ) {
foreach my $element_B ( @{$list_B} ) {
if ( $element_A eq $element_B ) {
push( @duplicate_elements, $element_A );
}
}
}
return @duplicate_elements;
}
sub _get_ajifry_word_by_consonant {
my $self = shift;
my $consonant = shift;
if ( $consonant eq 'a' ) {
return "é£ã";
}
elsif ( $consonant eq 'k' ) {
return "ãã©ã¤";
}
elsif ( $consonant eq 's' ) {
return "ãåºèº«";
}
elsif ( $consonant eq 't' ) {
return "ã¢ã¸";
}
elsif ( $consonant eq 'n' ) {
return "ãã";
}
elsif ( $consonant eq 'h' ) {
return "山岡";
}
lib/Acme/AjiFry.pm view on Meta::CPAN
my $consonant;
if ( $ajifry_word =~ s/^(é£ã|ãã©ã¤|ãåºèº«|ã¢ã¸|ãã|山岡|岡æ|ã´ã¯ã»ã»ã»|ã´ã¯ï½¥ï½¥ï½¥|ã´ã¯â¦|ãã|éå±±)//
)
{
$consonant = $1;
}
unless ($consonant) {
$ajifry_word =~ s/^(.)//;
$translated_word .= $1;
next;
}
my $vowel;
if ( $ajifry_word =~ s/^(é£ãé£ã|ãããã|ãåºèº«|ããã»ã»ã»|ãã・・・|ããâ¦|ã¢ã¸ãã©ã¤)//
)
{
$vowel = $1;
}
unless ($vowel) {
$translated_word .= $consonant;
$ajifry_word =~ s/^(.)//;
$translated_word .= $1;
next;
}
my $is_dullness;
$is_dullness = $1 if $ajifry_word =~ s/^(é¶äºº)//;
my $is_p_sound;
$is_p_sound = $1 if $ajifry_word =~ s/^(社主)//;
$consonant = $self->_get_consonant_by_ajifry_word($consonant);
$vowel = $self->_get_vowel_by_ajifry_word($vowel);
my @match_characters =
$self->_find_duplicate_element_in_both_lists( ROWS->{$consonant},
COLS->{$vowel} );
if ($is_p_sound) {
$translated_word .= $match_characters[2];
}
elsif ($is_dullness) {
$translated_word .= $match_characters[1];
}
elsif ( $is_double_consonant && $consonant eq 't' ) {
$translated_word .= $match_characters[2];
}
elsif ($is_double_consonant) {
$translated_word .= $match_characters[1];
}
else {
$translated_word .= $match_characters[0];
}
}
return $translated_word;
}
1;
__END__
=encoding utf8
=head1 NAME
Acme::AjiFry - AjiFry Language (ã¢ã¸ãã©ã¤èª) Translator
=head1 VERSION
This document describes Acme::AjiFry version 0.09
=head1 SYNOPSIS
use Acme::AjiFry;
my $ajifry = Acme::AjiFry->new();
print $ajifry->to_AjiFry('ãããã¿')."\n"; # outputs => "é£ãã¢ã¸ãã©ã¤ãåºèº«é£ãé£ããåºèº«ãããã岡æãããã"
print $ajifry->to_Japanese('é£ãã¢ã¸ãã©ã¤ãåºèº«é£ãé£ããåºèº«ãããã岡æãããã')."\n"; # outputs => "ãããã¿"
=head1 DESCRIPTION
Acme::AjiFry is the AjiFry-Language translator.
This module can translate Japanese into AjiFry-Language, and vice versa.
If you would like to know about AjiFry-Language, please refer to the following web site (Japanese Web Site).
L<http://ja.uncyclopedia.info/wiki/%E3%82%A2%E3%82%B8%E3%83%95%E3%83%A9%E3%82%A4%E8%AA%9E>
=head1 METHODS
=over
=item new
new is the constructor of this module.
=item to_Japanese
This function needs a AjiFry-Language string as parameter.
It returns Japanese which was translated from AjiFry-Language.
=item to_AjiFry
This function needs a string as parameter.
It returns AjiFry-Language which was translated from Japanese.
=back
=head1 DEPENDENCIES
=over 4
=item * Encode (version 2.39 or later)
=back
=head1 BUGS AND LIMITATIONS
=for author to fill in:
( run in 1.708 second using v1.01-cache-2.11-cpan-5b529ec07f3 )