| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Acme::Lou; |
|
2
|
4
|
|
|
4
|
|
85870
|
use 5.010001; |
|
|
4
|
|
|
|
|
10
|
|
|
3
|
4
|
|
|
4
|
|
14
|
use strict; |
|
|
4
|
|
|
|
|
3
|
|
|
|
4
|
|
|
|
|
66
|
|
|
4
|
4
|
|
|
4
|
|
12
|
use warnings; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
88
|
|
|
5
|
4
|
|
|
4
|
|
482
|
use utf8; |
|
|
4
|
|
|
|
|
11
|
|
|
|
4
|
|
|
|
|
696
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
|
7
|
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
141
|
use Exporter 'import'; |
|
|
4
|
|
|
|
|
4
|
|
|
|
4
|
|
|
|
|
97
|
|
|
9
|
4
|
|
|
4
|
|
1897
|
use Encode; |
|
|
4
|
|
|
|
|
27654
|
|
|
|
4
|
|
|
|
|
279
|
|
|
10
|
4
|
|
|
4
|
|
1858
|
use File::ShareDir qw/dist_file/; |
|
|
4
|
|
|
|
|
18421
|
|
|
|
4
|
|
|
|
|
225
|
|
|
11
|
4
|
|
|
4
|
|
1495
|
use Text::Mecabist; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @EXPORT_OK = qw/lou/; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub lou { |
|
16
|
|
|
|
|
|
|
my $text = shift || ""; |
|
17
|
|
|
|
|
|
|
return Acme::Lou->new->translate($text); |
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
|
21
|
|
|
|
|
|
|
my $class = shift; |
|
22
|
|
|
|
|
|
|
my $self = bless { |
|
23
|
|
|
|
|
|
|
mecab_option => { |
|
24
|
|
|
|
|
|
|
userdic => dist_file('Acme-Lou', Text::Mecabist->encoding->name .'.dic'), |
|
25
|
|
|
|
|
|
|
}, |
|
26
|
|
|
|
|
|
|
lou_rate => 100, |
|
27
|
|
|
|
|
|
|
@_, |
|
28
|
|
|
|
|
|
|
}, $class; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub translate { |
|
32
|
|
|
|
|
|
|
my ($self, $text, $opt) = @_; |
|
33
|
|
|
|
|
|
|
my $rate = $opt->{lou_rate} // $self->{lou_rate}; |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $parser = Text::Mecabist->new($self->{mecab_option}); |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
return $parser->parse($text, sub { |
|
38
|
|
|
|
|
|
|
my $node = shift; |
|
39
|
|
|
|
|
|
|
return if not $node->readable; |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $word = $node->extra1 or return; # ルー単語 found |
|
42
|
|
|
|
|
|
|
my $okuri = $node->extra2 // ""; |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
return if int(rand 100) > $rate; |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
if ($node->prev and |
|
47
|
|
|
|
|
|
|
$node->prev->is('接頭詞') and |
|
48
|
|
|
|
|
|
|
$node->prev->lemma =~ /^[ごお御]$/) { |
|
49
|
|
|
|
|
|
|
$node->prev->skip(1); |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
if ($node->is('形容詞') and |
|
53
|
|
|
|
|
|
|
$node->is('基本形') and |
|
54
|
|
|
|
|
|
|
$node->next and $node->next->pos =~ /助詞|記号/) { |
|
55
|
|
|
|
|
|
|
$okuri = ""; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$node->text($word . $okuri); |
|
59
|
|
|
|
|
|
|
})->stringify(); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
|
63
|
|
|
|
|
|
|
__END__ |