line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# This file was automatically generated by SWIG (http://www.swig.org). |
2
|
|
|
|
|
|
|
# Version 3.0.12 |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Do not make changes to this file unless you know what you are doing--modify |
5
|
|
|
|
|
|
|
# the SWIG interface file instead. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package Lingua::ZH::Jieba; |
8
|
|
|
|
|
|
|
$Lingua::ZH::Jieba::VERSION = '0.003'; |
9
|
2
|
|
|
2
|
|
26290
|
use base qw(Exporter); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
138
|
|
10
|
2
|
|
|
2
|
|
8
|
use base qw(DynaLoader); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
441
|
|
11
|
|
|
|
|
|
|
package Lingua::ZH::Jiebac; |
12
|
|
|
|
|
|
|
$Lingua::ZH::Jiebac::VERSION = '0.003'; |
13
|
|
|
|
|
|
|
bootstrap Lingua::ZH::Jieba; |
14
|
|
|
|
|
|
|
package Lingua::ZH::Jieba; |
15
|
|
|
|
|
|
|
@EXPORT = qw(); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# ---------- BASE METHODS ------------- |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
package Lingua::ZH::Jieba; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub TIEHASH { |
22
|
0
|
|
|
0
|
|
0
|
my ($classname,$obj) = @_; |
23
|
0
|
|
|
|
|
0
|
return bless $obj, $classname; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
0
|
|
|
sub CLEAR { } |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
0
|
|
|
sub FIRSTKEY { } |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
0
|
|
|
sub NEXTKEY { } |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub FETCH { |
33
|
0
|
|
|
0
|
|
0
|
my ($self,$field) = @_; |
34
|
0
|
|
|
|
|
0
|
my $member_func = "swig_${field}_get"; |
35
|
0
|
|
|
|
|
0
|
$self->$member_func(); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub STORE { |
39
|
0
|
|
|
0
|
|
0
|
my ($self,$field,$newval) = @_; |
40
|
0
|
|
|
|
|
0
|
my $member_func = "swig_${field}_set"; |
41
|
0
|
|
|
|
|
0
|
$self->$member_func($newval); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub this { |
45
|
0
|
|
|
0
|
0
|
0
|
my $ptr = shift; |
46
|
0
|
|
|
|
|
0
|
return tied(%$ptr); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# ------- FUNCTION WRAPPERS -------- |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
package Lingua::ZH::Jieba; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
############# Class : Lingua::ZH::Jieba::vector_s ############## |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
package Lingua::ZH::Jieba::vector_s; |
58
|
|
|
|
|
|
|
$Lingua::ZH::Jieba::vector_s::VERSION = '0.003'; |
59
|
2
|
|
|
2
|
|
11
|
use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
574
|
|
60
|
|
|
|
|
|
|
@ISA = qw( Lingua::ZH::Jieba ); |
61
|
|
|
|
|
|
|
%OWNER = (); |
62
|
|
|
|
|
|
|
%ITERATORS = (); |
63
|
|
|
|
|
|
|
sub new { |
64
|
0
|
|
|
0
|
|
0
|
my $pkg = shift; |
65
|
0
|
|
|
|
|
0
|
my $self = Lingua::ZH::Jiebac::new_vector_s(@_); |
66
|
0
|
0
|
|
|
|
0
|
bless $self, $pkg if defined($self); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
*size = *Lingua::ZH::Jiebac::vector_s_size; |
70
|
|
|
|
|
|
|
*empty = *Lingua::ZH::Jiebac::vector_s_empty; |
71
|
|
|
|
|
|
|
*clear = *Lingua::ZH::Jiebac::vector_s_clear; |
72
|
|
|
|
|
|
|
*push = *Lingua::ZH::Jiebac::vector_s_push; |
73
|
|
|
|
|
|
|
*pop = *Lingua::ZH::Jiebac::vector_s_pop; |
74
|
|
|
|
|
|
|
*get = *Lingua::ZH::Jiebac::vector_s_get; |
75
|
|
|
|
|
|
|
*set = *Lingua::ZH::Jiebac::vector_s_set; |
76
|
|
|
|
|
|
|
sub DESTROY { |
77
|
0
|
0
|
|
0
|
|
0
|
return unless $_[0]->isa('HASH'); |
78
|
0
|
|
|
|
|
0
|
my $self = tied(%{$_[0]}); |
|
0
|
|
|
|
|
0
|
|
79
|
0
|
0
|
|
|
|
0
|
return unless defined $self; |
80
|
0
|
|
|
|
|
0
|
delete $ITERATORS{$self}; |
81
|
0
|
0
|
|
|
|
0
|
if (exists $OWNER{$self}) { |
82
|
0
|
|
|
|
|
0
|
Lingua::ZH::Jiebac::delete_vector_s($self); |
83
|
0
|
|
|
|
|
0
|
delete $OWNER{$self}; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub DISOWN { |
88
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
89
|
0
|
|
|
|
|
0
|
my $ptr = tied(%$self); |
90
|
0
|
|
|
|
|
0
|
delete $OWNER{$ptr}; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub ACQUIRE { |
94
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
95
|
0
|
|
|
|
|
0
|
my $ptr = tied(%$self); |
96
|
0
|
|
|
|
|
0
|
$OWNER{$ptr} = 1; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
############# Class : Lingua::ZH::Jieba::vector_wordpos ############## |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
package Lingua::ZH::Jieba::vector_wordpos; |
103
|
|
|
|
|
|
|
$Lingua::ZH::Jieba::vector_wordpos::VERSION = '0.003'; |
104
|
2
|
|
|
2
|
|
7
|
use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
492
|
|
105
|
|
|
|
|
|
|
@ISA = qw( Lingua::ZH::Jieba ); |
106
|
|
|
|
|
|
|
%OWNER = (); |
107
|
|
|
|
|
|
|
%ITERATORS = (); |
108
|
|
|
|
|
|
|
sub new { |
109
|
0
|
|
|
0
|
|
0
|
my $pkg = shift; |
110
|
0
|
|
|
|
|
0
|
my $self = Lingua::ZH::Jiebac::new_vector_wordpos(@_); |
111
|
0
|
0
|
|
|
|
0
|
bless $self, $pkg if defined($self); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
*size = *Lingua::ZH::Jiebac::vector_wordpos_size; |
115
|
|
|
|
|
|
|
*empty = *Lingua::ZH::Jiebac::vector_wordpos_empty; |
116
|
|
|
|
|
|
|
*clear = *Lingua::ZH::Jiebac::vector_wordpos_clear; |
117
|
|
|
|
|
|
|
*push = *Lingua::ZH::Jiebac::vector_wordpos_push; |
118
|
|
|
|
|
|
|
*pop = *Lingua::ZH::Jiebac::vector_wordpos_pop; |
119
|
|
|
|
|
|
|
*get = *Lingua::ZH::Jiebac::vector_wordpos_get; |
120
|
|
|
|
|
|
|
*set = *Lingua::ZH::Jiebac::vector_wordpos_set; |
121
|
|
|
|
|
|
|
sub DESTROY { |
122
|
0
|
0
|
|
0
|
|
0
|
return unless $_[0]->isa('HASH'); |
123
|
0
|
|
|
|
|
0
|
my $self = tied(%{$_[0]}); |
|
0
|
|
|
|
|
0
|
|
124
|
0
|
0
|
|
|
|
0
|
return unless defined $self; |
125
|
0
|
|
|
|
|
0
|
delete $ITERATORS{$self}; |
126
|
0
|
0
|
|
|
|
0
|
if (exists $OWNER{$self}) { |
127
|
0
|
|
|
|
|
0
|
Lingua::ZH::Jiebac::delete_vector_wordpos($self); |
128
|
0
|
|
|
|
|
0
|
delete $OWNER{$self}; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub DISOWN { |
133
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
134
|
0
|
|
|
|
|
0
|
my $ptr = tied(%$self); |
135
|
0
|
|
|
|
|
0
|
delete $OWNER{$ptr}; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub ACQUIRE { |
139
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
140
|
0
|
|
|
|
|
0
|
my $ptr = tied(%$self); |
141
|
0
|
|
|
|
|
0
|
$OWNER{$ptr} = 1; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
############# Class : Lingua::ZH::Jieba::vector_keyword ############## |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
package Lingua::ZH::Jieba::vector_keyword; |
148
|
|
|
|
|
|
|
$Lingua::ZH::Jieba::vector_keyword::VERSION = '0.003'; |
149
|
2
|
|
|
2
|
|
9
|
use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
547
|
|
150
|
|
|
|
|
|
|
@ISA = qw( Lingua::ZH::Jieba ); |
151
|
|
|
|
|
|
|
%OWNER = (); |
152
|
|
|
|
|
|
|
%ITERATORS = (); |
153
|
|
|
|
|
|
|
sub new { |
154
|
0
|
|
|
0
|
|
0
|
my $pkg = shift; |
155
|
0
|
|
|
|
|
0
|
my $self = Lingua::ZH::Jiebac::new_vector_keyword(@_); |
156
|
0
|
0
|
|
|
|
0
|
bless $self, $pkg if defined($self); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
*size = *Lingua::ZH::Jiebac::vector_keyword_size; |
160
|
|
|
|
|
|
|
*empty = *Lingua::ZH::Jiebac::vector_keyword_empty; |
161
|
|
|
|
|
|
|
*clear = *Lingua::ZH::Jiebac::vector_keyword_clear; |
162
|
|
|
|
|
|
|
*push = *Lingua::ZH::Jiebac::vector_keyword_push; |
163
|
|
|
|
|
|
|
*pop = *Lingua::ZH::Jiebac::vector_keyword_pop; |
164
|
|
|
|
|
|
|
*get = *Lingua::ZH::Jiebac::vector_keyword_get; |
165
|
|
|
|
|
|
|
*set = *Lingua::ZH::Jiebac::vector_keyword_set; |
166
|
|
|
|
|
|
|
sub DESTROY { |
167
|
0
|
0
|
|
0
|
|
0
|
return unless $_[0]->isa('HASH'); |
168
|
0
|
|
|
|
|
0
|
my $self = tied(%{$_[0]}); |
|
0
|
|
|
|
|
0
|
|
169
|
0
|
0
|
|
|
|
0
|
return unless defined $self; |
170
|
0
|
|
|
|
|
0
|
delete $ITERATORS{$self}; |
171
|
0
|
0
|
|
|
|
0
|
if (exists $OWNER{$self}) { |
172
|
0
|
|
|
|
|
0
|
Lingua::ZH::Jiebac::delete_vector_keyword($self); |
173
|
0
|
|
|
|
|
0
|
delete $OWNER{$self}; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub DISOWN { |
178
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
179
|
0
|
|
|
|
|
0
|
my $ptr = tied(%$self); |
180
|
0
|
|
|
|
|
0
|
delete $OWNER{$ptr}; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub ACQUIRE { |
184
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
185
|
0
|
|
|
|
|
0
|
my $ptr = tied(%$self); |
186
|
0
|
|
|
|
|
0
|
$OWNER{$ptr} = 1; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
############# Class : Lingua::ZH::Jieba::KeywordExtractor ############## |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
package Lingua::ZH::Jieba::KeywordExtractor; |
193
|
|
|
|
|
|
|
$Lingua::ZH::Jieba::KeywordExtractor::VERSION = '0.003'; |
194
|
2
|
|
|
2
|
|
8
|
use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS); |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
389
|
|
195
|
|
|
|
|
|
|
@ISA = qw( Lingua::ZH::Jieba ); |
196
|
|
|
|
|
|
|
%OWNER = (); |
197
|
|
|
|
|
|
|
%ITERATORS = (); |
198
|
|
|
|
|
|
|
sub new { |
199
|
0
|
|
|
0
|
|
0
|
my $pkg = shift; |
200
|
0
|
|
|
|
|
0
|
my $self = Lingua::ZH::Jiebac::new_KeywordExtractor(@_); |
201
|
0
|
0
|
|
|
|
0
|
bless $self, $pkg if defined($self); |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
*_extract = *Lingua::ZH::Jiebac::KeywordExtractor__extract; |
205
|
|
|
|
|
|
|
sub DESTROY { |
206
|
2
|
100
|
|
2
|
|
1071
|
return unless $_[0]->isa('HASH'); |
207
|
1
|
|
|
|
|
2
|
my $self = tied(%{$_[0]}); |
|
1
|
|
|
|
|
3
|
|
208
|
1
|
50
|
|
|
|
3
|
return unless defined $self; |
209
|
1
|
|
|
|
|
2
|
delete $ITERATORS{$self}; |
210
|
1
|
50
|
|
|
|
5
|
if (exists $OWNER{$self}) { |
211
|
1
|
|
|
|
|
23829
|
Lingua::ZH::Jiebac::delete_KeywordExtractor($self); |
212
|
1
|
|
|
|
|
22
|
delete $OWNER{$self}; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub DISOWN { |
217
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
218
|
0
|
|
|
|
|
0
|
my $ptr = tied(%$self); |
219
|
0
|
|
|
|
|
0
|
delete $OWNER{$ptr}; |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
sub ACQUIRE { |
223
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
224
|
0
|
|
|
|
|
0
|
my $ptr = tied(%$self); |
225
|
0
|
|
|
|
|
0
|
$OWNER{$ptr} = 1; |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
############# Class : Lingua::ZH::Jieba::Jieba ############## |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
package Lingua::ZH::Jieba::Jieba; |
232
|
|
|
|
|
|
|
$Lingua::ZH::Jieba::Jieba::VERSION = '0.003'; |
233
|
2
|
|
|
2
|
|
7
|
use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS); |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
476
|
|
234
|
|
|
|
|
|
|
@ISA = qw( Lingua::ZH::Jieba ); |
235
|
|
|
|
|
|
|
%OWNER = (); |
236
|
|
|
|
|
|
|
%ITERATORS = (); |
237
|
|
|
|
|
|
|
sub new { |
238
|
2
|
|
|
2
|
|
2
|
my $pkg = shift; |
239
|
2
|
|
|
|
|
4431222
|
my $self = Lingua::ZH::Jiebac::new_Jieba(@_); |
240
|
2
|
50
|
|
|
|
48
|
bless $self, $pkg if defined($self); |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
*_cut = *Lingua::ZH::Jiebac::Jieba__cut; |
244
|
|
|
|
|
|
|
*_cut_all = *Lingua::ZH::Jiebac::Jieba__cut_all; |
245
|
|
|
|
|
|
|
*_cut_for_search = *Lingua::ZH::Jiebac::Jieba__cut_for_search; |
246
|
|
|
|
|
|
|
*insert_user_word = *Lingua::ZH::Jiebac::Jieba_insert_user_word; |
247
|
|
|
|
|
|
|
*_tag = *Lingua::ZH::Jiebac::Jieba__tag; |
248
|
|
|
|
|
|
|
*extractor = *Lingua::ZH::Jiebac::Jieba_extractor; |
249
|
|
|
|
|
|
|
sub DESTROY { |
250
|
4
|
100
|
|
4
|
|
1192
|
return unless $_[0]->isa('HASH'); |
251
|
2
|
|
|
|
|
3
|
my $self = tied(%{$_[0]}); |
|
2
|
|
|
|
|
7
|
|
252
|
2
|
50
|
|
|
|
6
|
return unless defined $self; |
253
|
2
|
|
|
|
|
4
|
delete $ITERATORS{$self}; |
254
|
2
|
50
|
|
|
|
6
|
if (exists $OWNER{$self}) { |
255
|
2
|
|
|
|
|
594779
|
Lingua::ZH::Jiebac::delete_Jieba($self); |
256
|
2
|
|
|
|
|
52
|
delete $OWNER{$self}; |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
sub DISOWN { |
261
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
262
|
0
|
|
|
|
|
0
|
my $ptr = tied(%$self); |
263
|
0
|
|
|
|
|
0
|
delete $OWNER{$ptr}; |
264
|
|
|
|
|
|
|
} |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
sub ACQUIRE { |
267
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
268
|
0
|
|
|
|
|
0
|
my $ptr = tied(%$self); |
269
|
0
|
|
|
|
|
0
|
$OWNER{$ptr} = 1; |
270
|
|
|
|
|
|
|
} |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
# ------- VARIABLE STUBS -------- |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
package Lingua::ZH::Jieba; |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
package Lingua::ZH::Jieba::KeywordExtractor; |
280
|
2
|
|
|
2
|
|
7
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
34
|
|
281
|
2
|
|
|
2
|
|
5
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
38
|
|
282
|
2
|
|
|
2
|
|
9
|
use utf8; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
8
|
|
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
sub extract { |
285
|
1
|
|
|
1
|
|
664768
|
my ($self, $sentence, $top_n) = @_; |
286
|
|
|
|
|
|
|
|
287
|
1
|
|
|
|
|
414
|
my $words = $self->_extract($sentence, $top_n); |
288
|
|
|
|
|
|
|
|
289
|
1
|
|
|
|
|
7
|
for (@$words) { |
290
|
5
|
|
|
|
|
13
|
utf8::decode($_->[0]); |
291
|
|
|
|
|
|
|
} |
292
|
1
|
|
|
|
|
6
|
return $words; |
293
|
|
|
|
|
|
|
} |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
package Lingua::ZH::Jieba::Jieba; |
297
|
2
|
|
|
2
|
|
169
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
26
|
|
298
|
2
|
|
|
2
|
|
4
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
41
|
|
299
|
2
|
|
|
2
|
|
5
|
use utf8; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
4
|
|
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
sub cut { |
302
|
6
|
|
|
6
|
|
797
|
my ($self, $sentence, $opts) = @_; |
303
|
|
|
|
|
|
|
|
304
|
6
|
|
100
|
|
|
20
|
$opts ||= {}; |
305
|
6
|
|
|
|
|
6
|
my $no_hmm = $opts->{no_hmm}; |
306
|
6
|
|
|
|
|
8
|
my $cut_all = $opts->{cut_all}; |
307
|
|
|
|
|
|
|
|
308
|
6
|
|
|
|
|
6
|
my $words; |
309
|
6
|
100
|
|
|
|
9
|
if ($cut_all) { |
310
|
1
|
|
|
|
|
53
|
$words = $self->_cut_all($sentence); |
311
|
|
|
|
|
|
|
} else { |
312
|
5
|
|
|
|
|
356
|
$words = $self->_cut($sentence, !$no_hmm); |
313
|
|
|
|
|
|
|
} |
314
|
|
|
|
|
|
|
|
315
|
6
|
|
|
|
|
15
|
for (@$words) { |
316
|
24
|
|
|
|
|
36
|
utf8::decode($_); |
317
|
|
|
|
|
|
|
} |
318
|
6
|
|
|
|
|
26
|
return $words; |
319
|
|
|
|
|
|
|
} |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
sub cut_for_search { |
322
|
1
|
|
|
1
|
|
1
|
my ($self, $sentence, $opts) = @_; |
323
|
|
|
|
|
|
|
|
324
|
1
|
|
50
|
|
|
6
|
$opts ||= {}; |
325
|
1
|
|
|
|
|
2
|
my $no_hmm = $opts->{no_hmm}; |
326
|
|
|
|
|
|
|
|
327
|
1
|
|
|
|
|
165
|
my $words = $self->_cut_for_search($sentence, !$no_hmm); |
328
|
|
|
|
|
|
|
|
329
|
1
|
|
|
|
|
4
|
for (@$words) { |
330
|
19
|
|
|
|
|
19
|
utf8::decode($_); |
331
|
|
|
|
|
|
|
} |
332
|
1
|
|
|
|
|
5
|
return $words; |
333
|
|
|
|
|
|
|
} |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
sub tag { |
336
|
1
|
|
|
1
|
|
235
|
my ($self, $sentence) = @_; |
337
|
|
|
|
|
|
|
|
338
|
1
|
|
|
|
|
136
|
my $words = $self->_tag($sentence); |
339
|
1
|
|
|
|
|
4
|
for (@$words) { |
340
|
10
|
|
|
|
|
12
|
utf8::decode($_->[0]); |
341
|
|
|
|
|
|
|
} |
342
|
1
|
|
|
|
|
3
|
return $words; |
343
|
|
|
|
|
|
|
} |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
package Lingua::ZH::Jieba; |
347
|
|
|
|
|
|
|
# ABSTRACT: Perl wrapper for CppJieba (Chinese text segmentation) |
348
|
2
|
|
|
2
|
|
454
|
use 5.010; |
|
2
|
|
|
|
|
4
|
|
349
|
2
|
|
|
2
|
|
6
|
use strict; |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
30
|
|
350
|
2
|
|
|
2
|
|
5
|
use warnings; |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
38
|
|
351
|
2
|
|
|
2
|
|
5
|
use utf8; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
5
|
|
352
|
|
|
|
|
|
|
|
353
|
2
|
|
|
2
|
|
485
|
use File::ShareDir qw(dist_file); |
|
2
|
|
|
|
|
3946
|
|
|
2
|
|
|
|
|
405
|
|
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
sub _shared_file { |
356
|
10
|
|
|
10
|
|
11
|
my $file = shift; |
357
|
10
|
|
|
|
|
16
|
return dist_file('Lingua-ZH-Jieba', $file); |
358
|
|
|
|
|
|
|
} |
359
|
|
|
|
|
|
|
my $default_dict_path = _shared_file('dict/jieba.dict.utf8'); |
360
|
|
|
|
|
|
|
my $default_user_dict_path = _shared_file('dict/user.dict.utf8'); |
361
|
|
|
|
|
|
|
my $default_hmm_path = _shared_file('dict/hmm_model.utf8'); |
362
|
|
|
|
|
|
|
my $default_idf_path = _shared_file('dict/idf.utf8'); |
363
|
|
|
|
|
|
|
my $default_stop_word_path = _shared_file('dict/stop_words.utf8'); |
364
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
sub new { |
366
|
2
|
|
|
2
|
1
|
22737
|
my $pkg = shift; |
367
|
2
|
|
|
|
|
4
|
my $opts = shift; |
368
|
|
|
|
|
|
|
|
369
|
2
|
|
100
|
|
|
9
|
$opts //= {}; |
370
|
|
|
|
|
|
|
|
371
|
2
|
|
|
|
|
3
|
my $dict_path = $opts->{dict_path}; |
372
|
2
|
|
|
|
|
2
|
my $hmm_path = $opts->{hmm_path}; |
373
|
2
|
|
|
|
|
4
|
my $user_dict_path = $opts->{user_dict_path}; |
374
|
2
|
|
|
|
|
3
|
my $idf_path = $opts->{idf_path}; |
375
|
2
|
|
|
|
|
3
|
my $stop_word_path = $opts->{stop_word_path}; |
376
|
|
|
|
|
|
|
|
377
|
2
|
|
33
|
|
|
16
|
$dict_path //= $default_dict_path; |
378
|
2
|
|
33
|
|
|
9
|
$hmm_path //= $default_hmm_path; |
379
|
2
|
|
66
|
|
|
6
|
$user_dict_path //= $default_user_dict_path; |
380
|
2
|
|
33
|
|
|
6
|
$idf_path //= $default_idf_path; |
381
|
2
|
|
33
|
|
|
7
|
$stop_word_path //= $default_stop_word_path; |
382
|
|
|
|
|
|
|
|
383
|
2
|
|
|
|
|
16
|
return Lingua::ZH::Jieba::Jieba->new( |
384
|
|
|
|
|
|
|
$dict_path . "", |
385
|
|
|
|
|
|
|
$hmm_path . "", |
386
|
|
|
|
|
|
|
$user_dict_path . "", |
387
|
|
|
|
|
|
|
$idf_path . "", |
388
|
|
|
|
|
|
|
$stop_word_path . "" |
389
|
|
|
|
|
|
|
); |
390
|
|
|
|
|
|
|
} |
391
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
1; |