File Coverage

blib/lib/pullword.pm
Criterion Covered Total %
statement 14 36 38.8
branch 0 4 0.0
condition n/a
subroutine 5 7 71.4
pod 2 2 100.0
total 21 49 42.8


line stmt bran cond sub pod time code
1             package pullword;
2              
3 1     1   13347 use 5.010;
  1         3  
4 1     1   3 use strict;
  1         1  
  1         16  
5 1     1   2 use warnings;
  1         5  
  1         25  
6 1     1   479 use Encode;
  1         7030  
  1         67  
7 1     1   476 use Mojo::UserAgent;
  1         212769  
  1         9  
8              
9             our @ISA = qw(Exporter);
10             our @EXPORT = qw(PWhash PWget);
11              
12             =encoding utf8
13             =head1 NAME
14              
15             pullword - The perl agent for Pullword(a online Chinese segmentation System) api!
16              
17             =head1 VERSION
18              
19             Version 0.02
20              
21             =cut
22              
23             our $VERSION = '0.02';
24              
25              
26             =head1 SYNOPSIS
27              
28             Quick summary of what the module does.
29              
30             Perhaps a little code snippet.
31              
32             use pullword;
33              
34             print PWget("清华大学是好学校",0,1);
35             ...
36              
37             =head1 EXPORT
38              
39             A list of functions that can be exported. You can delete this section
40             if you don't export anything, such as for a purely object-oriented module.
41              
42             =head1 SUBROUTINES/METHODS
43              
44             =head2 PWget($source,$param1,$param2)
45              
46             get pullword api result.
47             source=[a paragraph of chinese words] for example: source=清华大学是好学校
48             param1=[threshold] for example: param1=0 to pull all word, param1=1 to pull word with probability with 100%.
49             param2=[debug] for example: param2=0 debug model is off, param2=1 debug mode in on(show all probabilities of each word)
50              
51             OUT text reslut;
52              
53             =head2 PWhash($source)
54              
55             get pullword word distribution hash.
56             source=[a paragraph of chinese words] for example: source=清华大学是好学校
57              
58             OUT hash: word as kery and It's frequency count;
59              
60              
61             =cut
62              
63              
64             sub PWhash {
65 0     0 1   my $res=shift;
66 0           my $result=PWget($res,0,0);
67 0           my @fc=split /\n/ms,$result;
68 0           my %fc;
69 0           for(@fc) {
70 0           chmod;
71 0 0         next if /^$/;
72 0           $fc{$_}++;
73             }
74 0           return \%fc;
75             }
76              
77             sub PWget {
78 0     0 1   my ($source,$threshold,$debug)=@_;
79 0           $source=decode("utf8",$source);
80 0           my $myurl="http://api.pullword.com/post.php?source=".$source."¶m1=".$threshold."¶m2=".$debug;
81             #$myurl="http://43.241.223.121/post.php?source=".$source."¶m1=".$threshold."¶m2=".$debug;
82             #$myurl="http://120.26.6.172/post.php?source=".$source."¶m1=".$threshold."¶m2=".$debug;
83 0           my $ua = Mojo::UserAgent->new;
84 0           $ua->transactor->name("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36");
85 0           my $tx=$ua->get($myurl);
86 0           my $replys=$tx->res->body;
87 0           my $out;
88 0           my @tmsg=split /\r\n/sm,$replys;
89 0           for(@tmsg){
90 0 0         next if /^$/;
91 0           $out.=$_."\n";
92             }
93              
94 0           return $out;
95             }
96              
97             =head1 AUTHOR
98              
99             ORANGE, C<< >>
100              
101             =head1 BUGS
102              
103             Please report any bugs or feature requests to C, or through
104             the web interface at L. I will be notified, and then you'll
105             automatically be notified of progress on your bug as I make changes.
106              
107              
108              
109              
110             =head1 SUPPORT
111              
112             You can find documentation for this module with the perldoc command.
113              
114             perldoc pullword
115              
116              
117             You can also look for information at:
118              
119             =over 4
120              
121             =item * RT: CPAN's request tracker (report bugs here)
122              
123             L
124              
125             =item * AnnoCPAN: Annotated CPAN documentation
126              
127             L
128              
129             =item * CPAN Ratings
130              
131             L
132              
133             =item * Search CPAN
134              
135             L
136              
137             =back
138              
139              
140             =head1 ACKNOWLEDGEMENTS
141              
142              
143             =head1 LICENSE AND COPYRIGHT
144              
145             Copyright 2016 ORANGE.
146              
147             This program is released under the following license: Perl
148              
149              
150             =cut
151              
152             1; # End of pullword