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.002'; |
9
|
2
|
|
|
2
|
|
38327
|
use base qw(Exporter); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
216
|
|
10
|
2
|
|
|
2
|
|
10
|
use base qw(DynaLoader); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
614
|
|
11
|
|
|
|
|
|
|
package Lingua::ZH::Jiebac; |
12
|
|
|
|
|
|
|
$Lingua::ZH::Jiebac::VERSION = '0.002'; |
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.002'; |
59
|
2
|
|
|
2
|
|
11
|
use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS); |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
820
|
|
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.002'; |
104
|
2
|
|
|
2
|
|
11
|
use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS); |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
647
|
|
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::Jieba ############## |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
package Lingua::ZH::Jieba::Jieba; |
148
|
|
|
|
|
|
|
$Lingua::ZH::Jieba::Jieba::VERSION = '0.002'; |
149
|
2
|
|
|
2
|
|
11
|
use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
616
|
|
150
|
|
|
|
|
|
|
@ISA = qw( Lingua::ZH::Jieba ); |
151
|
|
|
|
|
|
|
%OWNER = (); |
152
|
|
|
|
|
|
|
%ITERATORS = (); |
153
|
|
|
|
|
|
|
sub new { |
154
|
2
|
|
|
2
|
|
4
|
my $pkg = shift; |
155
|
2
|
|
|
|
|
5165846
|
my $self = Lingua::ZH::Jiebac::new_Jieba(@_); |
156
|
2
|
50
|
|
|
|
50
|
bless $self, $pkg if defined($self); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
*_cut = *Lingua::ZH::Jiebac::Jieba__cut; |
160
|
|
|
|
|
|
|
*_cut_all = *Lingua::ZH::Jiebac::Jieba__cut_all; |
161
|
|
|
|
|
|
|
*_cut_for_search = *Lingua::ZH::Jiebac::Jieba__cut_for_search; |
162
|
|
|
|
|
|
|
*insert_user_word = *Lingua::ZH::Jiebac::Jieba_insert_user_word; |
163
|
|
|
|
|
|
|
*_tag = *Lingua::ZH::Jiebac::Jieba__tag; |
164
|
|
|
|
|
|
|
sub DESTROY { |
165
|
4
|
100
|
|
4
|
|
975
|
return unless $_[0]->isa('HASH'); |
166
|
2
|
|
|
|
|
4
|
my $self = tied(%{$_[0]}); |
|
2
|
|
|
|
|
7
|
|
167
|
2
|
50
|
|
|
|
6
|
return unless defined $self; |
168
|
2
|
|
|
|
|
4
|
delete $ITERATORS{$self}; |
169
|
2
|
50
|
|
|
|
6
|
if (exists $OWNER{$self}) { |
170
|
2
|
|
|
|
|
681536
|
Lingua::ZH::Jiebac::delete_Jieba($self); |
171
|
2
|
|
|
|
|
58
|
delete $OWNER{$self}; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub DISOWN { |
176
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
177
|
0
|
|
|
|
|
0
|
my $ptr = tied(%$self); |
178
|
0
|
|
|
|
|
0
|
delete $OWNER{$ptr}; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub ACQUIRE { |
182
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
183
|
0
|
|
|
|
|
0
|
my $ptr = tied(%$self); |
184
|
0
|
|
|
|
|
0
|
$OWNER{$ptr} = 1; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
# ------- VARIABLE STUBS -------- |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
package Lingua::ZH::Jieba; |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
package Lingua::ZH::Jieba::Jieba; |
195
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
46
|
|
196
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
61
|
|
197
|
2
|
|
|
2
|
|
8
|
use utf8; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
12
|
|
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
sub cut { |
200
|
6
|
|
|
6
|
|
762
|
my ($self, $sentence, $opts) = @_; |
201
|
|
|
|
|
|
|
|
202
|
6
|
|
100
|
|
|
26
|
$opts ||= {}; |
203
|
6
|
|
|
|
|
8
|
my $no_hmm = $opts->{no_hmm}; |
204
|
6
|
|
|
|
|
5
|
my $cut_all = $opts->{cut_all}; |
205
|
|
|
|
|
|
|
|
206
|
6
|
|
|
|
|
5
|
my $words; |
207
|
6
|
100
|
|
|
|
11
|
if ($cut_all) { |
208
|
1
|
|
|
|
|
54
|
$words = $self->_cut_all($sentence); |
209
|
|
|
|
|
|
|
} else { |
210
|
5
|
|
|
|
|
345
|
$words = $self->_cut($sentence, !$no_hmm); |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
6
|
|
|
|
|
16
|
for (@$words) { |
214
|
24
|
|
|
|
|
34
|
utf8::decode($_); |
215
|
|
|
|
|
|
|
} |
216
|
6
|
|
|
|
|
27
|
return $words; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
sub cut_for_search { |
220
|
1
|
|
|
1
|
|
2
|
my ($self, $sentence, $opts) = @_; |
221
|
|
|
|
|
|
|
|
222
|
1
|
|
50
|
|
|
5
|
$opts ||= {}; |
223
|
1
|
|
|
|
|
2
|
my $no_hmm = $opts->{no_hmm}; |
224
|
|
|
|
|
|
|
|
225
|
1
|
|
|
|
|
218
|
my $words = $self->_cut_for_search($sentence, !$no_hmm); |
226
|
|
|
|
|
|
|
|
227
|
1
|
|
|
|
|
5
|
for (@$words) { |
228
|
19
|
|
|
|
|
19
|
utf8::decode($_); |
229
|
|
|
|
|
|
|
} |
230
|
1
|
|
|
|
|
7
|
return $words; |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
sub tag { |
234
|
1
|
|
|
1
|
|
237
|
my ($self, $sentence) = @_; |
235
|
|
|
|
|
|
|
|
236
|
1
|
|
|
|
|
130
|
my $words = $self->_tag($sentence); |
237
|
1
|
|
|
|
|
5
|
for (@$words) { |
238
|
10
|
|
|
|
|
12
|
utf8::decode($_->[0]); |
239
|
|
|
|
|
|
|
} |
240
|
1
|
|
|
|
|
2
|
return $words; |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
package Lingua::ZH::Jieba; |
245
|
|
|
|
|
|
|
# ABSTRACT: Perl wrapper for CppJieba (Chinese text segmentation) |
246
|
2
|
|
|
2
|
|
572
|
use 5.010; |
|
2
|
|
|
|
|
7
|
|
247
|
2
|
|
|
2
|
|
13
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
43
|
|
248
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
58
|
|
249
|
2
|
|
|
2
|
|
8
|
use utf8; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
5
|
|
250
|
|
|
|
|
|
|
|
251
|
2
|
|
|
2
|
|
780
|
use File::ShareDir qw(dist_file); |
|
2
|
|
|
|
|
6596
|
|
|
2
|
|
|
|
|
539
|
|
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
sub _shared_file { |
254
|
10
|
|
|
10
|
|
15
|
my $file = shift; |
255
|
10
|
|
|
|
|
23
|
return dist_file('Lingua-ZH-Jieba', $file); |
256
|
|
|
|
|
|
|
} |
257
|
|
|
|
|
|
|
my $default_dict_path = _shared_file('dict/jieba.dict.utf8'); |
258
|
|
|
|
|
|
|
my $default_user_dict_path = _shared_file('dict/user.dict.utf8'); |
259
|
|
|
|
|
|
|
my $default_hmm_path = _shared_file('dict/hmm_model.utf8'); |
260
|
|
|
|
|
|
|
my $default_idf_path = _shared_file('dict/idf.utf8'); |
261
|
|
|
|
|
|
|
my $default_stop_word_path = _shared_file('dict/stop_words.utf8'); |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
sub new { |
264
|
2
|
|
|
2
|
1
|
28351
|
my $pkg = shift; |
265
|
2
|
|
|
|
|
3
|
my $opts = shift; |
266
|
|
|
|
|
|
|
|
267
|
2
|
|
100
|
|
|
12
|
$opts //= {}; |
268
|
|
|
|
|
|
|
|
269
|
2
|
|
|
|
|
5
|
my $dict_path = $opts->{dict_path}; |
270
|
2
|
|
|
|
|
3
|
my $hmm_path = $opts->{hmm_path}; |
271
|
2
|
|
|
|
|
4
|
my $user_dict_path = $opts->{user_dict_path}; |
272
|
2
|
|
|
|
|
4
|
my $idf_path = $opts->{idf_path}; |
273
|
2
|
|
|
|
|
3
|
my $stop_word_path = $opts->{stop_word_path}; |
274
|
|
|
|
|
|
|
|
275
|
2
|
|
33
|
|
|
12
|
$dict_path //= $default_dict_path; |
276
|
2
|
|
33
|
|
|
11
|
$hmm_path //= $default_hmm_path; |
277
|
2
|
|
66
|
|
|
8
|
$user_dict_path //= $default_user_dict_path; |
278
|
2
|
|
33
|
|
|
10
|
$idf_path //= $default_idf_path; |
279
|
2
|
|
33
|
|
|
9
|
$stop_word_path //= $default_stop_word_path; |
280
|
|
|
|
|
|
|
|
281
|
2
|
|
|
|
|
22
|
return Lingua::ZH::Jieba::Jieba->new( |
282
|
|
|
|
|
|
|
$dict_path . "", |
283
|
|
|
|
|
|
|
$hmm_path . "", |
284
|
|
|
|
|
|
|
$user_dict_path . "", |
285
|
|
|
|
|
|
|
$idf_path . "", |
286
|
|
|
|
|
|
|
$stop_word_path . "" |
287
|
|
|
|
|
|
|
); |
288
|
|
|
|
|
|
|
} |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
1; |