YASA.pm

filter: Statementstmt 72.1% 44 / 61 Branchbran 43.7% 7 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 66.6% 62 / 93 CC 11 SCAR 21.3
CC
11
Cov
64%
extract
21.2
AUTOLOAD
4.3
new
3.3
CRAP 8.4
« YASA/ConfigData.pm ↑ Summary
1 package Net::YASA;
2  
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use Encode qw/encode decode/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 4 our $VERSION = '0.03';
21 4 our $AUTOLOAD;
22 4 our %ok_field;
23  
24 4 for my $attr ( qw(content minfreq minlength ) ) { $ok_field{$attr}++; }
25  
26 3 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=4 SCAR=14.6
27 3 my $self = shift;
28 3 my $attr = $AUTOLOAD;
29 3 $attr =~ s/.*:://;
30 3 ▶ return if $attr eq 'DESTROY';
Branch: 1 branch
BranchTrueFalseTotal
if $attr eq "DESTROY" 1 2 3
31  
32 2 ▶ if ($ok_field{$attr}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::YASA::ok_field{$attr}) { } 2 0 2
33 2 ▶ $self->{lc $attr} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
34 2 return $self->{lc $attr};
35 } else {
36 0 my $superior = "SUPER::$attr";
37 0 $self->$superior(@_);
38 }
39 }
40  
41 4 ▶use constant YASA_WEB_URL => 'http://yasa.newzilla.org/run/';
Subroutine BEGIN: called CC=1 SCAR=0.0
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(<some_of_utf8_words>);
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 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.8
Pod documented
67 1 my $class = shift;
68 1 my $self = {
69 _ua => undef,
70 minlength => 1,
71 minfreq => 2,
72 output => 'xml',
73 _content => undef
74 };
75 1 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1 1
76 0 my %arg = @_;
77  
78 0 foreach (keys %arg) {
79 0 $self->{lc($_)} = $arg{$_};
80 }
81 }
82 1 $self->{_ua} = LWP::UserAgent->new;
83 1 $self->{_ua}->timeout(30);
84 1 $self->{_ua}->agent('CPAN::Net::YASA');
85 1 bless($self, $class);
86 1 return($self);
87 }
88  
89 =head2 extract
90  
91 =cut
92  
93 1 ▶sub extract {
Subroutine extract: called CC=6 SCAR=30.5
Pod documented
94 1 my ($self, $content) = @_;
95 1 ▶ die 'No content specified' unless $content ne "";
Branch: 1 branch
BranchTrueFalseTotal
unless $content ne "" 0 1 1
96 1 my $ua = $self->{_ua};
97 my $response = $ua->post(
98 1 YASA_WEB_URL.$self->{output}."/",
99 {
100 'min' => $self->minlength,
101 'freq' => $self->minfreq,
102 'content' => encode("utf8",$content),
103 }
104 );
105 1 ▶ die "Error in extracting data from YASA!\n" unless $response->is_success();
Branch: 1 branch
BranchTrueFalseTotal
unless $response->is_success 1 0 1
106 0 ▶ if ($self->{output} eq "json" and eval {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'output'} eq 'json' and eval { do { require JSON::Any; 1 } }) { } 0 0 0
Condition0%0/3
$self->{"output"} eq "json" and eval { do { require JSON::Any; 1 } }
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"output"} eq "json" and eval { do { require JSON::Any; 1 } }
$self->{"output"} eq "json" eval { do { require JSON::Any; 1 } }
Truth table0%0/3
A and B
A= $self->{"output"} eq "json"B= eval { do { require JSON::Any; 1 } }
ABresult
0X0
100
111
107 0 require JSON::Any;
108 0 1;
109 }) {
110 0 my $result = $response->content();
111 0 my $j = JSON::Any->new;
112  
113 0 my $data = $j->decode($result);
114 0 return $data;
115 }
116 else {
117 0 my $xml = decode("utf8",$response->content());
118 0 my @results = ();
119 0 ▶ while ($xml =~ m#<Term>([^<]*)</Term><Freq>(\d+)</Freq>#g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml =~ m[<Term>([^<]*)</Term><Freq>(\d+)</Freq>]g) 0 0 0
120 0 push @results, $1."\t".$2;
121 }
122 0 return \@results;
123 }
124 }
125  
126 =head1 AUTHOR
127  
128 Cheng-Lung Sung, C<< <clsung at FreeBSD.org> >>
129  
130 =head1 BUGS
131  
132 Please report any bugs or feature requests to
133 C<bug-net-yasa at rt.cpan.org>, or through the web interface at
134 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-YASA>.
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<http://yasa.newzilla.org>
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<http://annocpan.org/dist/Net-YASA>
155  
156 =item * CPAN Ratings
157  
158 L<http://cpanratings.perl.org/d/Net-YASA>
159  
160 =item * RT: CPAN's request tracker
161  
162 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-YASA>
163  
164 =item * Search CPAN
165  
166 L<http://search.cpan.org/dist/Net-YASA>
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 4 1; # End of Net::YASA
« YASA/ConfigData.pm ↑ Summary