Acme-Lou
view release on metacpan or search on metacpan
lib/Acme/Lou.pm view on Meta::CPAN
package Acme::Lou;
use 5.010001;
use strict;
use warnings;
use utf8;
our $VERSION = '0.04';
use Exporter 'import';
use Encode;
use File::ShareDir qw/dist_file/;
use Text::Mecabist;
our @EXPORT_OK = qw/lou/;
sub lou {
my $text = shift || "";
return Acme::Lou->new->translate($text);
}
sub new {
my $class = shift;
my $self = bless {
mecab_option => {
userdic => dist_file('Acme-Lou', Text::Mecabist->encoding->name .'.dic'),
},
lou_rate => 100,
@_,
}, $class;
}
sub translate {
my ($self, $text, $opt) = @_;
my $rate = $opt->{lou_rate} // $self->{lou_rate};
my $parser = Text::Mecabist->new($self->{mecab_option});
return $parser->parse($text, sub {
my $node = shift;
return if not $node->readable;
my $word = $node->extra1 or return; # ã«ã¼åèª found
my $okuri = $node->extra2 // "";
return if int(rand 100) > $rate;
if ($node->prev and
$node->prev->is('æ¥é è©') and
$node->prev->lemma =~ /^[ãã御]$/) {
$node->prev->skip(1);
}
if ($node->is('形容è©') and
$node->is('åºæ¬å½¢') and
$node->next and $node->next->pos =~ /å©è©|è¨å·/) {
$okuri = "";
}
$node->text($word . $okuri);
})->stringify();
}
1;
__END__
=encoding utf-8
=head1 NAME
Acme::Lou - Let's together with Lou Ohshiba
=head1 SYNOPSIS
use utf8;
use Acme::Lou qw/lou/;
print lou("人çã«ã¯ã大åãªä¸ã¤ã®è¢ãããã¾ãã");
# => ã©ã¤ãã«ã¯ãã¤ã³ãã¼ã¿ã³ããªä¸ã¤ã®ããã°ãããã¾ãã
=head1 DESCRIPTION
Translate Japanese text into Lou Ohshiba (Japanese comedian) style.
=head1 METHODS
=head2 $lou = Acme::Lou->new()
Creates an Acme::Lou object.
=head2 $lou->translate($text [, \%options ])
$lou = Acme->Lou->new();
$out = $lou->translate($text, { lou_rate => 50 });
Return translated unicode string.
I<%options>:
=over 4
=item * lou_rate
Percentage of translating. 100(default) means full, 0 means do nothing.
=back
=head1 EXPORTS
No exports by default.
=head2 lou
use Acme::Lou qw/lou/;
my $text = <<'...';
ç¥åç²¾èã®éã®å£°ã諸è¡ç¡å¸¸ã®é¿ãããã
æ²ç¾
忍¹ã®è±ã®è²ãçè
å¿
è¡°ã®çãç¾ãã
奢ãã人ãä¹
ããããã坿¥ã®å¤ã®å¤¢ã®ãã¨ãã
- ã平家ç©èªããã
...
print lou($text);
# ç¥åãã³ãã«ã®ãã«ã®ãã¤ã¹ã諸è¡ç¡å¸¸ã®ã¨ã³ã¼ããã
# æ²ç¾
忍¹ã®ãã©ã¯ã¼ã®ã«ã©ã¼ãçè
å¿
è¡°ã®ãªã¼ãºã³ãã·ã§ã¼ããã
# ãã©ã¦ãããããã¥ã¼ãã³ãä¹
ããããããªã³ãªã¼ã¹ããªã³ã°ã®ã¤ã¼ããã³ã°ã®ããªã¼ã ã®ãã¨ãã
# - ã平家ã¹ãã¼ãªã¼ããã
Shortcut to C<< Acme::Lou->new->translate() >>.
=head1 OBSOLETED FUNCTION
To keep this module working, following functions are obsoleted. sorry.
( run in 0.548 second using v1.01-cache-2.11-cpan-5a3173703d6 )