line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::JA::Expand; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
76378
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
77
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
59
|
|
5
|
2
|
|
|
2
|
|
11
|
use Carp; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
323
|
|
6
|
2
|
|
|
2
|
|
12
|
use base qw(Lingua::JA::Expand::Base); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
1578
|
|
7
|
2
|
|
|
2
|
|
7240
|
use UNIVERSAL::require; |
|
2
|
|
|
|
|
11265
|
|
|
2
|
|
|
|
|
31
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.01002'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors qw(_tokenizer _datasource); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
|
|
|
|
|
|
my $class = shift; |
15
|
|
|
|
|
|
|
my %args = @_; |
16
|
|
|
|
|
|
|
my $self = $class->SUPER::new( \%args ); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub expand { |
20
|
|
|
|
|
|
|
my $self = shift; |
21
|
|
|
|
|
|
|
my $word = shift; |
22
|
|
|
|
|
|
|
my $threshold = shift || 30; |
23
|
|
|
|
|
|
|
if ( $word !~ /./ ) { |
24
|
|
|
|
|
|
|
carp("put any word") and return; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
my $text_ref = $self->datasource->extract_text( \$word ); |
27
|
|
|
|
|
|
|
return undef if !$text_ref; |
28
|
|
|
|
|
|
|
my $word_set = $self->tokenizer->tokenize( $text_ref, $threshold ); |
29
|
|
|
|
|
|
|
return $word_set; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub tokenize { |
33
|
|
|
|
|
|
|
my $self = shift; |
34
|
|
|
|
|
|
|
my $text = shift; |
35
|
|
|
|
|
|
|
my $threshold = shift || 30; |
36
|
|
|
|
|
|
|
my $word_set = $self->tokenizer->tokenize( \$text, $threshold ); |
37
|
|
|
|
|
|
|
return $word_set; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub tokenizer { |
41
|
|
|
|
|
|
|
my $self = shift; |
42
|
|
|
|
|
|
|
$self->_class_loader( tokenizer => 'Tokenizer::MeCab' ); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub datasource { |
46
|
|
|
|
|
|
|
my $self = shift; |
47
|
|
|
|
|
|
|
$self->_class_loader( datasource => 'DataSource::YahooSearch' ); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _class_loader { |
51
|
|
|
|
|
|
|
my $self = shift; |
52
|
|
|
|
|
|
|
my $class_type = shift; |
53
|
|
|
|
|
|
|
my $default_class = shift; |
54
|
|
|
|
|
|
|
my $accessor = '_' . $class_type; |
55
|
|
|
|
|
|
|
$self->$accessor or $self->$accessor( |
56
|
|
|
|
|
|
|
sub { |
57
|
|
|
|
|
|
|
my $class; |
58
|
|
|
|
|
|
|
my $config = $self->config || {}; |
59
|
|
|
|
|
|
|
if ( $config->{$class_type} ) { |
60
|
|
|
|
|
|
|
$class = $config->{$class_type}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
else { |
63
|
|
|
|
|
|
|
$class = __PACKAGE__ . '::' . $default_class; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
$class->require or croak $@; |
66
|
|
|
|
|
|
|
$class->new($config); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
->() |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
__END__ |