| 1 | package Acme::Ikamusume; | ||
| 2 | 3 | ▶ | use 5.008001; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 3 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 3 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | our $VERSION = '0.07'; | ||
| 6 | 3 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 3 | ▶ | use Class::Trigger; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 3 | ▶ | use File::ShareDir; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 3 | ▶ | use Acme::Ikamusume::MAParser; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 11 | use Acme::Ikamusume::Rule; | ||
| 12 | |||
| 13 | sub new { | ||
| 14 | my $self = bless {}, shift; | ||
| 15 | Acme::Ikamusume::Rule->set_rules($self); | ||
| 16 | $self; | ||
| 17 | } | ||
| 18 | |||
| 19 | sub geso { | ||
| 20 | my ($self, $input) = @_; | ||
| 21 | return "" unless defined $input; | ||
| 22 | $self = $self->new unless ref $self; | ||
| 23 | |||
| 24 | my $parser = Acme::Ikamusume::MAParser->new({ | ||
| 25 | userdic => File::ShareDir::dist_file('Acme-Ikamusume', 'ika.dic'), | ||
| 26 | }); | ||
| 27 | |||
| 28 | my @result; | ||
| 29 | for my $text (split /(\s+)/, $input) { | ||
| 30 | if ($text =~ /\s/) { | ||
| 31 | push @result, $text; | ||
| 32 | next; | ||
| 33 | } | ||
| 34 | |||
| 35 | my @words; | ||
| 36 | foreach ( | ||
| 37 | my $node = $parser->parse($text); | ||
| 38 | $node; | ||
| 39 | $node = $node->next | ||
| 40 | ) { | ||
| 41 | next if $node->stat =~ /[23]/; # skip MECAB_(BOS|EOS)_NODE | ||
| 42 | push @words, $node->surface; | ||
| 43 | |||
| 44 | $self->call_trigger('node' => ($node, \@words)); | ||
| 45 | $self->call_trigger('node.has_extra' => ($node, \@words)) if $node->features->{extra}; | ||
| 46 | $self->call_trigger('node.readable' => ($node, \@words)) if $node->features->{yomi}; | ||
| 47 | } | ||
| 48 | |||
| 49 | push @result, @words; | ||
| 50 | } | ||
| 51 | |||
| 52 | join "", @result; | ||
| 53 | } | ||
| 54 | |||
| 55 | 1; | ||
| 56 | __END__ | ||