line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package pullword; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
13311
|
use 5.010; |
|
1
|
|
|
|
|
2
|
|
4
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
5
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
28
|
|
6
|
1
|
|
|
1
|
|
496
|
use Encode; |
|
1
|
|
|
|
|
7135
|
|
|
1
|
|
|
|
|
61
|
|
7
|
1
|
|
|
1
|
|
470
|
use Mojo::UserAgent; |
|
1
|
|
|
|
|
170890
|
|
|
1
|
|
|
|
|
7
|
|
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.01 |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
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 /\r\s/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
|
|
|
|
|
|
return $tx->res->body; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 AUTHOR |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
ORANGE, C<< >> |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 BUGS |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
96
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
97
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 SUPPORT |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
perldoc pullword |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
You can also look for information at: |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=over 4 |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
L |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
L |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item * CPAN Ratings |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
L |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item * Search CPAN |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
L |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=back |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Copyright 2016 ORANGE. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
This program is released under the following license: Perl |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=cut |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
1; # End of pullword |