line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::JA::Categorize; |
2
|
2
|
|
|
2
|
|
471
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
60
|
|
3
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
47
|
|
4
|
2
|
|
|
2
|
|
1137
|
use Lingua::JA::Categorize::Tokenizer; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use Lingua::JA::Categorize::Categorizer; |
6
|
|
|
|
|
|
|
use Lingua::JA::Categorize::Generator; |
7
|
|
|
|
|
|
|
use base qw( Lingua::JA::Categorize::Base ); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors($_) for qw( tokenizer categorizer generator ); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.02002'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
|
|
|
|
|
|
my $class = shift; |
15
|
|
|
|
|
|
|
my $self = $class->SUPER::new(@_); |
16
|
|
|
|
|
|
|
$self->tokenizer( |
17
|
|
|
|
|
|
|
Lingua::JA::Categorize::Tokenizer->new( context => $self ) ); |
18
|
|
|
|
|
|
|
$self->categorizer( |
19
|
|
|
|
|
|
|
Lingua::JA::Categorize::Categorizer->new( context => $self ) ); |
20
|
|
|
|
|
|
|
$self->generator( |
21
|
|
|
|
|
|
|
Lingua::JA::Categorize::Generator->new( context => $self ) ); |
22
|
|
|
|
|
|
|
return $self; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub categorize { |
26
|
|
|
|
|
|
|
my $self = shift; |
27
|
|
|
|
|
|
|
my $text = shift; |
28
|
|
|
|
|
|
|
my $word_num = shift; |
29
|
|
|
|
|
|
|
my $word_set = $self->tokenizer->tokenize( \$text, $word_num ); |
30
|
|
|
|
|
|
|
my $user_extention = $self->tokenizer->user_extention; |
31
|
|
|
|
|
|
|
my $result = $self->categorizer->categorize( $word_set, $user_extention ); |
32
|
|
|
|
|
|
|
return $result; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub generate { |
36
|
|
|
|
|
|
|
my $self = shift; |
37
|
|
|
|
|
|
|
my $categories = shift; |
38
|
|
|
|
|
|
|
my $brain = $self->categorizer->brain; |
39
|
|
|
|
|
|
|
$self->generator->generate( $categories, $brain ); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub load { |
43
|
|
|
|
|
|
|
my $self = shift; |
44
|
|
|
|
|
|
|
my $save_file = shift; |
45
|
|
|
|
|
|
|
$self->categorizer->load($save_file); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub save { |
49
|
|
|
|
|
|
|
my $self = shift; |
50
|
|
|
|
|
|
|
my $save_file = shift; |
51
|
|
|
|
|
|
|
$self->categorizer->save($save_file); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub train { |
55
|
|
|
|
|
|
|
my $self = shift; |
56
|
|
|
|
|
|
|
$self->categorizer->train(@_); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
__END__ |