| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::YASA; |
|
2
|
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
74424
|
use warnings; |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
84
|
|
|
4
|
3
|
|
|
3
|
|
16
|
use strict; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
93
|
|
|
5
|
3
|
|
|
3
|
|
1765
|
use utf8; |
|
|
3
|
|
|
|
|
22
|
|
|
|
3
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
2584
|
use Encode qw/encode decode/; |
|
|
3
|
|
|
|
|
33475
|
|
|
|
3
|
|
|
|
|
268
|
|
|
8
|
3
|
|
|
3
|
|
2995
|
use LWP::UserAgent; |
|
|
3
|
|
|
|
|
145048
|
|
|
|
3
|
|
|
|
|
608
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Net::YASA - Interface to YASA (Yet Another Suffix Array) |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 VERSION |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Version 0.03 |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
|
21
|
|
|
|
|
|
|
our $AUTOLOAD; |
|
22
|
|
|
|
|
|
|
our %ok_field; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
for my $attr ( qw(content minfreq minlength ) ) { $ok_field{$attr}++; } |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub AUTOLOAD { |
|
27
|
2
|
|
|
2
|
|
3
|
my $self = shift; |
|
28
|
2
|
|
|
|
|
4
|
my $attr = $AUTOLOAD; |
|
29
|
2
|
|
|
|
|
11
|
$attr =~ s/.*:://; |
|
30
|
2
|
50
|
|
|
|
8
|
return if $attr eq 'DESTROY'; |
|
31
|
|
|
|
|
|
|
|
|
32
|
2
|
50
|
|
|
|
7
|
if ($ok_field{$attr}) { |
|
33
|
2
|
50
|
|
|
|
5
|
$self->{lc $attr} = shift if @_; |
|
34
|
2
|
|
|
|
|
14
|
return $self->{lc $attr}; |
|
35
|
|
|
|
|
|
|
} else { |
|
36
|
0
|
|
|
|
|
0
|
my $superior = "SUPER::$attr"; |
|
37
|
0
|
|
|
|
|
0
|
$self->$superior(@_); |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
3
|
|
|
3
|
|
31
|
use constant YASA_WEB_URL => 'http://yasa.newzilla.org/run/'; |
|
|
3
|
|
|
|
|
11
|
|
|
|
3
|
|
|
|
|
1509
|
|
|
42
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
This module will submit content to the YASA WebService to return |
|
45
|
|
|
|
|
|
|
a list of terms and corresponding frequencies. |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
use Net::YASA; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $foo = Net::YASA->new(); |
|
50
|
|
|
|
|
|
|
my $termset = $foo->extract(); |
|
51
|
|
|
|
|
|
|
print 'TermSet 1: ', $$termset[0], "\n"; |
|
52
|
|
|
|
|
|
|
print 'TermSet 2: ', $$termset[1], "\n"; |
|
53
|
|
|
|
|
|
|
... |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 EXPORT |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
A list of functions that can be exported. You can delete this section |
|
58
|
|
|
|
|
|
|
if you don't export anything, such as for a purely object-oriented module. |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 METHODS |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 new |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub new { |
|
67
|
1
|
|
|
1
|
1
|
410
|
my $class = shift; |
|
68
|
1
|
|
|
|
|
6
|
my $self = { |
|
69
|
|
|
|
|
|
|
_ua => undef, |
|
70
|
|
|
|
|
|
|
minlength => 1, |
|
71
|
|
|
|
|
|
|
minfreq => 2, |
|
72
|
|
|
|
|
|
|
output => 'xml', |
|
73
|
|
|
|
|
|
|
_content => undef |
|
74
|
|
|
|
|
|
|
}; |
|
75
|
1
|
50
|
|
|
|
4
|
if(@_) { |
|
76
|
0
|
|
|
|
|
0
|
my %arg = @_; |
|
77
|
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
0
|
foreach (keys %arg) { |
|
79
|
0
|
|
|
|
|
0
|
$self->{lc($_)} = $arg{$_}; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
} |
|
82
|
1
|
|
|
|
|
15
|
$self->{_ua} = LWP::UserAgent->new; |
|
83
|
1
|
|
|
|
|
2992
|
$self->{_ua}->timeout(30); |
|
84
|
1
|
|
|
|
|
29
|
$self->{_ua}->agent('CPAN::Net::YASA'); |
|
85
|
1
|
|
|
|
|
66
|
bless($self, $class); |
|
86
|
1
|
|
|
|
|
4
|
return($self); |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 extract |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub extract { |
|
94
|
1
|
|
|
1
|
1
|
5
|
my ($self, $content) = @_; |
|
95
|
1
|
50
|
|
|
|
6
|
die 'No content specified' unless $content ne ""; |
|
96
|
1
|
|
|
|
|
5
|
my $ua = $self->{_ua}; |
|
97
|
1
|
|
|
|
|
42
|
my $response = $ua->post( |
|
98
|
|
|
|
|
|
|
YASA_WEB_URL.$self->{output}."/", |
|
99
|
|
|
|
|
|
|
{ |
|
100
|
|
|
|
|
|
|
'min' => $self->minlength, |
|
101
|
|
|
|
|
|
|
'freq' => $self->minfreq, |
|
102
|
|
|
|
|
|
|
'content' => encode("utf8",$content), |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
); |
|
105
|
1
|
50
|
|
|
|
758137
|
die "Error in extracting data from YASA!\n" unless $response->is_success(); |
|
106
|
1
|
50
|
33
|
|
|
23
|
if ($self->{output} eq "json" and eval { |
|
107
|
0
|
|
|
|
|
0
|
require JSON::Any; |
|
108
|
0
|
|
|
|
|
0
|
1; |
|
109
|
|
|
|
|
|
|
}) { |
|
110
|
0
|
|
|
|
|
0
|
my $result = $response->content(); |
|
111
|
0
|
|
|
|
|
0
|
my $j = JSON::Any->new; |
|
112
|
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
0
|
my $data = $j->decode($result); |
|
114
|
0
|
|
|
|
|
0
|
return $data; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
else { |
|
117
|
1
|
|
|
|
|
12
|
my $xml = decode("utf8",$response->content()); |
|
118
|
1
|
|
|
|
|
90
|
my @results = (); |
|
119
|
1
|
|
|
|
|
16
|
while ($xml =~ m#([^<]*)(\d+)#g) { |
|
120
|
2
|
|
|
|
|
22
|
push @results, $1."\t".$2; |
|
121
|
|
|
|
|
|
|
} |
|
122
|
1
|
|
|
|
|
28
|
return \@results; |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 AUTHOR |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Cheng-Lung Sung, C<< >> |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 BUGS |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
|
133
|
|
|
|
|
|
|
C, or through the web interface at |
|
134
|
|
|
|
|
|
|
L. |
|
135
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
|
136
|
|
|
|
|
|
|
your bug as I make changes. |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
YASA (Yet Another Suffix Array) web site: L |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 SUPPORT |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
perldoc Net::YASA |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
You can also look for information at: |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=over 4 |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
L |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
L |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
L |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item * Search CPAN |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
L |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=back |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Copyright 2007-2009 Cheng-Lung Sung, all rights reserved. |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
177
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=cut |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
1; # End of Net::YASA |