line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::JA::Categorize::Tokenizer; |
2
|
3
|
|
|
3
|
|
561
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
83
|
|
3
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
60
|
|
4
|
3
|
|
|
3
|
|
3615
|
use Lingua::JA::TFIDF; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use base qw( Lingua::JA::Categorize::Base ); |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors($_) for qw( calc user_extention); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
|
|
|
|
|
|
my $class = shift; |
11
|
|
|
|
|
|
|
my $self = $class->SUPER::new(@_); |
12
|
|
|
|
|
|
|
$self->calc( Lingua::JA::TFIDF->new( %{ $self->config } ) ); |
13
|
|
|
|
|
|
|
return $self; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub tokenize { |
17
|
|
|
|
|
|
|
my $self = shift; |
18
|
|
|
|
|
|
|
my $text_ref = shift; |
19
|
|
|
|
|
|
|
my $threshold = shift; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $text = $$text_ref; |
22
|
|
|
|
|
|
|
my $http_URL_regex |
23
|
|
|
|
|
|
|
= q{\b(?:https?|shttp)://(?:(?:[-_.!~*'()a-zA-Z0-9;:&=+$,]|%[0-9A-Fa-f} |
24
|
|
|
|
|
|
|
. q{][0-9A-Fa-f])*@)?(?:(?:[a-zA-Z0-9](?:[-a-zA-Z0-9]*[a-zA-Z0-9])?\.)} |
25
|
|
|
|
|
|
|
. q{*[a-zA-Z](?:[-a-zA-Z0-9]*[a-zA-Z0-9])?\.?|[0-9]+\.[0-9]+\.[0-9]+\.} |
26
|
|
|
|
|
|
|
. q{[0-9]+)(?::[0-9]*)?(?:/(?:[-_.!~*'()a-zA-Z0-9:@&=+$,]|%[0-9A-Fa-f]} |
27
|
|
|
|
|
|
|
. q{[0-9A-Fa-f])*(?:;(?:[-_.!~*'()a-zA-Z0-9:@&=+$,]|%[0-9A-Fa-f][0-9A-} |
28
|
|
|
|
|
|
|
. q{Fa-f])*)*(?:/(?:[-_.!~*'()a-zA-Z0-9:@&=+$,]|%[0-9A-Fa-f][0-9A-Fa-f} |
29
|
|
|
|
|
|
|
. q{])*(?:;(?:[-_.!~*'()a-zA-Z0-9:@&=+$,]|%[0-9A-Fa-f][0-9A-Fa-f])*)*)} |
30
|
|
|
|
|
|
|
. q{*)?(?:\?(?:[-_.!~*'()a-zA-Z0-9;/?:@&=+$,]|%[0-9A-Fa-f][0-9A-Fa-f])} |
31
|
|
|
|
|
|
|
. q{*)?(?:#(?:[-_.!~*'()a-zA-Z0-9;/?:@&=+$,]|%[0-9A-Fa-f][0-9A-Fa-f])*} |
32
|
|
|
|
|
|
|
. q{)?}; |
33
|
|
|
|
|
|
|
$text =~ s/$http_URL_regex//g; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $tfidf_result = $self->calc->tfidf($text); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my %user_extention; |
38
|
|
|
|
|
|
|
while ( my ( $keyword, $ref ) = each %{ $tfidf_result->{data} } ) { |
39
|
|
|
|
|
|
|
my @f = split( ",", $ref->{info} ); |
40
|
|
|
|
|
|
|
if ( $f[6] eq 'ユーザ設定' ) { |
41
|
|
|
|
|
|
|
$user_extention{$keyword} = $f[9]; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
$self->user_extention( \%user_extention ); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $list = $tfidf_result->list($threshold); |
47
|
|
|
|
|
|
|
my %hash; |
48
|
|
|
|
|
|
|
for (@$list) { |
49
|
|
|
|
|
|
|
my ( $word, $score ) = each(%$_); |
50
|
|
|
|
|
|
|
$hash{$word} = $score; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
return \%hash; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
__END__ |