line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Mining::Algorithm::AllTokens; |
2
|
1
|
|
|
1
|
|
7386
|
use base qw(Text::Mining::Base); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
89
|
|
3
|
|
|
|
|
|
|
use Class::Std; |
4
|
|
|
|
|
|
|
use Class::Std::Utils; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use warnings; |
7
|
|
|
|
|
|
|
use strict; |
8
|
|
|
|
|
|
|
use Carp; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use version; our $VERSION = qv('0.0.8'); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
{ |
13
|
|
|
|
|
|
|
my %attribute_of : ATTR( get => 'attribute', set => 'attribute' ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub harvest_tokens { |
16
|
|
|
|
|
|
|
my ( $self, $arg_ref ) = @_; |
17
|
|
|
|
|
|
|
my ( @values, @inserts ); |
18
|
|
|
|
|
|
|
if ( defined $arg_ref->{text} ) { |
19
|
|
|
|
|
|
|
my $document_id = $arg_ref->{document_id}; |
20
|
|
|
|
|
|
|
my $text = $arg_ref->{text}; |
21
|
|
|
|
|
|
|
my @sentences = split(/\./, $text); |
22
|
|
|
|
|
|
|
my @list = split(/\s+/, $text); |
23
|
|
|
|
|
|
|
my $seen = {}; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Build insert statements for distinct tokens |
26
|
|
|
|
|
|
|
foreach my $word ( @list ) { |
27
|
|
|
|
|
|
|
if (undef $seen->{$word}) { |
28
|
|
|
|
|
|
|
$seen->{$word}++; |
29
|
|
|
|
|
|
|
push @values, $word; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
if (@values % 100 == 0) { |
32
|
|
|
|
|
|
|
# Build statement |
33
|
|
|
|
|
|
|
#push @inserts, "insert into tokens_temp (document_id, token) values ('" . join("'), ('", @values) . "');"; |
34
|
|
|
|
|
|
|
my $sql = "insert into tokens_temp (document_id, token) values ('$document_id', '" . join("'), ('$document_id', '", @values) . "');"; |
35
|
|
|
|
|
|
|
$self->library()->sqlexec( $sql ); |
36
|
|
|
|
|
|
|
@values = (); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
my $sql = "insert into tokens_temp (document_id, token) values ('" . join("'), ('", @values) . "');"; |
41
|
|
|
|
|
|
|
$self->library()->sqlexec( $sql ); |
42
|
|
|
|
|
|
|
} else { |
43
|
|
|
|
|
|
|
return; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
51
|
|
|
|
|
|
|
__END__ |