blib/lib/Lingua/ZH/Jieba.pm

filter: Statementstmt 65.5% 209 / 319 Branchbran 26.5% 17 / 64 Conditioncond 47.6% 10 / 21 MC/DCmcdc 7.6% 1 / 13 Subroutinesub 44.8% 26 / 58 Podpod 50.0% 1 / 2 totaltotal 55.3% 264 / 477 CC 47 SCAR 19.1
CC
47
Cov
58%
DESTROY
20.0
DESTROY
20.0
DESTROY
20.0
CRAP 6.8
↑ Summary
1 # This file was automatically generated by SWIG (http://www.swig.org).
2 # Version 4.0.2
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 2 $Lingua::ZH::Jieba::VERSION = '0.007';
9 2 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use base qw(DynaLoader);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 package Lingua::ZH::Jiebac;
12 2 $Lingua::ZH::Jiebac::VERSION = '0.007';
13 2 bootstrap Lingua::ZH::Jieba;
14 package Lingua::ZH::Jieba;
15 2 @EXPORT = qw();
16  
17 # ---------- BASE METHODS -------------
18  
19 package Lingua::ZH::Jieba;
20  
21 0 ▶sub TIEHASH {
Subroutine TIEHASH: not called CC=1 SCAR=6.9
22 0 my ($classname,$obj) = @_;
23 0 return bless $obj, $classname;
24 }
25  
26 0 ▶sub CLEAR { }
Subroutine CLEAR: not called CC=1 SCAR=0.0
27  
28 0 ▶sub FIRSTKEY { }
Subroutine FIRSTKEY: not called CC=1 SCAR=0.0
29  
30 0 ▶sub NEXTKEY { }
Subroutine NEXTKEY: not called CC=1 SCAR=0.0
31  
32 0 ▶sub FETCH {
Subroutine FETCH: not called CC=1 SCAR=6.9
33 0 my ($self,$field) = @_;
34 0 my $member_func = "swig_${field}_get";
35 0 $self->$member_func();
36 }
37  
38 0 ▶sub STORE {
Subroutine STORE: not called CC=1 SCAR=6.9
39 0 my ($self,$field,$newval) = @_;
40 0 my $member_func = "swig_${field}_set";
41 0 $self->$member_func($newval);
42 }
43  
44 0 ▶sub this {
Subroutine this: not called CC=1 SCAR=6.9
Pod undocumented
45 0 my $ptr = shift;
46 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 2 $Lingua::ZH::Jieba::vector_s::VERSION = '0.007';
59 2 ▶use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
Subroutine BEGIN: called CC=1 SCAR=0.0
60 2 @ISA = qw( Lingua::ZH::Jieba );
61 2 %OWNER = ();
62 2 %ITERATORS = ();
63 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
64 0 my $pkg = shift;
65 0 my $self = Lingua::ZH::Jiebac::new_vector_s(@_);
66 0 ▶ bless $self, $pkg if defined($self);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self 0 0 0
67 }
68  
69 2 *size = *Lingua::ZH::Jiebac::vector_s_size;
70 2 *empty = *Lingua::ZH::Jiebac::vector_s_empty;
71 2 *clear = *Lingua::ZH::Jiebac::vector_s_clear;
72 2 *push = *Lingua::ZH::Jiebac::vector_s_push;
73 2 *pop = *Lingua::ZH::Jiebac::vector_s_pop;
74 2 *get = *Lingua::ZH::Jiebac::vector_s_get;
75 2 *set = *Lingua::ZH::Jiebac::vector_s_set;
76 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=4 SCAR=30.0
77 0 ▶ return unless $_[0]->isa('HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]->isa("HASH") 0 0 0
78 0 my $self = tied(%{$_[0]});
79 0 ▶ return unless defined $self;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self 0 0 0
80 0 delete $ITERATORS{$self};
81 0 ▶ if (exists $OWNER{$self}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $OWNER{$self}) 0 0 0
82 0 Lingua::ZH::Jiebac::delete_vector_s($self);
83 0 delete $OWNER{$self};
84 }
85 }
86  
87 0 ▶sub DISOWN {
Subroutine DISOWN: not called CC=1 SCAR=6.9
88 0 my $self = shift;
89 0 my $ptr = tied(%$self);
90 0 delete $OWNER{$ptr};
91 }
92  
93 0 ▶sub ACQUIRE {
Subroutine ACQUIRE: not called CC=1 SCAR=6.9
94 0 my $self = shift;
95 0 my $ptr = tied(%$self);
96 0 $OWNER{$ptr} = 1;
97 }
98  
99  
100 ############# Class : Lingua::ZH::Jieba::vector_wordpos ##############
101  
102 package Lingua::ZH::Jieba::vector_wordpos;
103 2 $Lingua::ZH::Jieba::vector_wordpos::VERSION = '0.007';
104 2 ▶use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
Subroutine BEGIN: called CC=1 SCAR=0.0
105 2 @ISA = qw( Lingua::ZH::Jieba );
106 2 %OWNER = ();
107 2 %ITERATORS = ();
108 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
109 0 my $pkg = shift;
110 0 my $self = Lingua::ZH::Jiebac::new_vector_wordpos(@_);
111 0 ▶ bless $self, $pkg if defined($self);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self 0 0 0
112 }
113  
114 2 *size = *Lingua::ZH::Jiebac::vector_wordpos_size;
115 2 *empty = *Lingua::ZH::Jiebac::vector_wordpos_empty;
116 2 *clear = *Lingua::ZH::Jiebac::vector_wordpos_clear;
117 2 *push = *Lingua::ZH::Jiebac::vector_wordpos_push;
118 2 *pop = *Lingua::ZH::Jiebac::vector_wordpos_pop;
119 2 *get = *Lingua::ZH::Jiebac::vector_wordpos_get;
120 2 *set = *Lingua::ZH::Jiebac::vector_wordpos_set;
121 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=4 SCAR=30.0
122 0 ▶ return unless $_[0]->isa('HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]->isa("HASH") 0 0 0
123 0 my $self = tied(%{$_[0]});
124 0 ▶ return unless defined $self;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self 0 0 0
125 0 delete $ITERATORS{$self};
126 0 ▶ if (exists $OWNER{$self}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $OWNER{$self}) 0 0 0
127 0 Lingua::ZH::Jiebac::delete_vector_wordpos($self);
128 0 delete $OWNER{$self};
129 }
130 }
131  
132 0 ▶sub DISOWN {
Subroutine DISOWN: not called CC=1 SCAR=6.9
133 0 my $self = shift;
134 0 my $ptr = tied(%$self);
135 0 delete $OWNER{$ptr};
136 }
137  
138 0 ▶sub ACQUIRE {
Subroutine ACQUIRE: not called CC=1 SCAR=6.9
139 0 my $self = shift;
140 0 my $ptr = tied(%$self);
141 0 $OWNER{$ptr} = 1;
142 }
143  
144  
145 ############# Class : Lingua::ZH::Jieba::vector_keyword ##############
146  
147 package Lingua::ZH::Jieba::vector_keyword;
148 2 $Lingua::ZH::Jieba::vector_keyword::VERSION = '0.007';
149 2 ▶use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
Subroutine BEGIN: called CC=1 SCAR=0.0
150 2 @ISA = qw( Lingua::ZH::Jieba );
151 2 %OWNER = ();
152 2 %ITERATORS = ();
153 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
154 0 my $pkg = shift;
155 0 my $self = Lingua::ZH::Jiebac::new_vector_keyword(@_);
156 0 ▶ bless $self, $pkg if defined($self);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self 0 0 0
157 }
158  
159 2 *size = *Lingua::ZH::Jiebac::vector_keyword_size;
160 2 *empty = *Lingua::ZH::Jiebac::vector_keyword_empty;
161 2 *clear = *Lingua::ZH::Jiebac::vector_keyword_clear;
162 2 *push = *Lingua::ZH::Jiebac::vector_keyword_push;
163 2 *pop = *Lingua::ZH::Jiebac::vector_keyword_pop;
164 2 *get = *Lingua::ZH::Jiebac::vector_keyword_get;
165 2 *set = *Lingua::ZH::Jiebac::vector_keyword_set;
166 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=4 SCAR=30.0
167 0 ▶ return unless $_[0]->isa('HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]->isa("HASH") 0 0 0
168 0 my $self = tied(%{$_[0]});
169 0 ▶ return unless defined $self;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self 0 0 0
170 0 delete $ITERATORS{$self};
171 0 ▶ if (exists $OWNER{$self}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $OWNER{$self}) 0 0 0
172 0 Lingua::ZH::Jiebac::delete_vector_keyword($self);
173 0 delete $OWNER{$self};
174 }
175 }
176  
177 0 ▶sub DISOWN {
Subroutine DISOWN: not called CC=1 SCAR=6.9
178 0 my $self = shift;
179 0 my $ptr = tied(%$self);
180 0 delete $OWNER{$ptr};
181 }
182  
183 0 ▶sub ACQUIRE {
Subroutine ACQUIRE: not called CC=1 SCAR=6.9
184 0 my $self = shift;
185 0 my $ptr = tied(%$self);
186 0 $OWNER{$ptr} = 1;
187 }
188  
189  
190 ############# Class : Lingua::ZH::Jieba::vector_word ##############
191  
192 package Lingua::ZH::Jieba::vector_word;
193 2 $Lingua::ZH::Jieba::vector_word::VERSION = '0.007';
194 2 ▶use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
Subroutine BEGIN: called CC=1 SCAR=0.0
195 2 @ISA = qw( Lingua::ZH::Jieba );
196 2 %OWNER = ();
197 2 %ITERATORS = ();
198 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
199 0 my $pkg = shift;
200 0 my $self = Lingua::ZH::Jiebac::new_vector_word(@_);
201 0 ▶ bless $self, $pkg if defined($self);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self 0 0 0
202 }
203  
204 2 *size = *Lingua::ZH::Jiebac::vector_word_size;
205 2 *empty = *Lingua::ZH::Jiebac::vector_word_empty;
206 2 *clear = *Lingua::ZH::Jiebac::vector_word_clear;
207 2 *push = *Lingua::ZH::Jiebac::vector_word_push;
208 2 *pop = *Lingua::ZH::Jiebac::vector_word_pop;
209 2 *get = *Lingua::ZH::Jiebac::vector_word_get;
210 2 *set = *Lingua::ZH::Jiebac::vector_word_set;
211 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=4 SCAR=30.0
212 0 ▶ return unless $_[0]->isa('HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]->isa("HASH") 0 0 0
213 0 my $self = tied(%{$_[0]});
214 0 ▶ return unless defined $self;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self 0 0 0
215 0 delete $ITERATORS{$self};
216 0 ▶ if (exists $OWNER{$self}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $OWNER{$self}) 0 0 0
217 0 Lingua::ZH::Jiebac::delete_vector_word($self);
218 0 delete $OWNER{$self};
219 }
220 }
221  
222 0 ▶sub DISOWN {
Subroutine DISOWN: not called CC=1 SCAR=6.9
223 0 my $self = shift;
224 0 my $ptr = tied(%$self);
225 0 delete $OWNER{$ptr};
226 }
227  
228 0 ▶sub ACQUIRE {
Subroutine ACQUIRE: not called CC=1 SCAR=6.9
229 0 my $self = shift;
230 0 my $ptr = tied(%$self);
231 0 $OWNER{$ptr} = 1;
232 }
233  
234  
235 ############# Class : Lingua::ZH::Jieba::Word ##############
236  
237 package Lingua::ZH::Jieba::Word;
238 2 $Lingua::ZH::Jieba::Word::VERSION = '0.007';
239 2 ▶use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
Subroutine BEGIN: called CC=1 SCAR=0.0
240 2 @ISA = qw( Lingua::ZH::Jieba );
241 2 %OWNER = ();
242 2 %ITERATORS = ();
243 2 *swig_word_get = *Lingua::ZH::Jiebac::Word_word_get;
244 2 *swig_word_set = *Lingua::ZH::Jiebac::Word_word_set;
245 2 *swig_offset_get = *Lingua::ZH::Jiebac::Word_offset_get;
246 2 *swig_offset_set = *Lingua::ZH::Jiebac::Word_offset_set;
247 2 *swig_length_get = *Lingua::ZH::Jiebac::Word_length_get;
248 2 *swig_length_set = *Lingua::ZH::Jiebac::Word_length_set;
249 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
250 0 my $pkg = shift;
251 0 my $self = Lingua::ZH::Jiebac::new_Word(@_);
252 0 ▶ bless $self, $pkg if defined($self);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self 0 0 0
253 }
254  
255 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=4 SCAR=30.0
256 0 ▶ return unless $_[0]->isa('HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]->isa("HASH") 0 0 0
257 0 my $self = tied(%{$_[0]});
258 0 ▶ return unless defined $self;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self 0 0 0
259 0 delete $ITERATORS{$self};
260 0 ▶ if (exists $OWNER{$self}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $OWNER{$self}) 0 0 0
261 0 Lingua::ZH::Jiebac::delete_Word($self);
262 0 delete $OWNER{$self};
263 }
264 }
265  
266 0 ▶sub DISOWN {
Subroutine DISOWN: not called CC=1 SCAR=6.9
267 0 my $self = shift;
268 0 my $ptr = tied(%$self);
269 0 delete $OWNER{$ptr};
270 }
271  
272 0 ▶sub ACQUIRE {
Subroutine ACQUIRE: not called CC=1 SCAR=6.9
273 0 my $self = shift;
274 0 my $ptr = tied(%$self);
275 0 $OWNER{$ptr} = 1;
276 }
277  
278  
279 ############# Class : Lingua::ZH::Jieba::KeywordExtractor ##############
280  
281 package Lingua::ZH::Jieba::KeywordExtractor;
282 2 $Lingua::ZH::Jieba::KeywordExtractor::VERSION = '0.007';
283 2 ▶use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
Subroutine BEGIN: called CC=1 SCAR=0.0
284 2 @ISA = qw( Lingua::ZH::Jieba );
285 2 %OWNER = ();
286 2 %ITERATORS = ();
287 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
288 0 my $pkg = shift;
289 0 my $self = Lingua::ZH::Jiebac::new_KeywordExtractor(@_);
290 0 ▶ bless $self, $pkg if defined($self);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self 0 0 0
291 }
292  
293 2 *_extract = *Lingua::ZH::Jiebac::KeywordExtractor__extract;
294 2 ▶sub DESTROY {
Subroutine DESTROY: called CC=4 SCAR=14.0
295 2 ▶ return unless $_[0]->isa('HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]->isa("HASH") 1 1 2
296 1 my $self = tied(%{$_[0]});
297 1 ▶ return unless defined $self;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self 0 1 1
298 1 delete $ITERATORS{$self};
299 1 ▶ if (exists $OWNER{$self}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $OWNER{$self}) 1 0 1
300 1 Lingua::ZH::Jiebac::delete_KeywordExtractor($self);
301 1 delete $OWNER{$self};
302 }
303 }
304  
305 0 ▶sub DISOWN {
Subroutine DISOWN: not called CC=1 SCAR=6.9
306 0 my $self = shift;
307 0 my $ptr = tied(%$self);
308 0 delete $OWNER{$ptr};
309 }
310  
311 0 ▶sub ACQUIRE {
Subroutine ACQUIRE: not called CC=1 SCAR=6.9
312 0 my $self = shift;
313 0 my $ptr = tied(%$self);
314 0 $OWNER{$ptr} = 1;
315 }
316  
317  
318 ############# Class : Lingua::ZH::Jieba::Jieba ##############
319  
320 package Lingua::ZH::Jieba::Jieba;
321 2 $Lingua::ZH::Jieba::Jieba::VERSION = '0.007';
322 2 ▶use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
Subroutine BEGIN: called CC=1 SCAR=0.0
323 2 @ISA = qw( Lingua::ZH::Jieba );
324 2 %OWNER = ();
325 2 %ITERATORS = ();
326 2 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
327 2 my $pkg = shift;
328 2 my $self = Lingua::ZH::Jiebac::new_Jieba(@_);
329 2 ▶ bless $self, $pkg if defined($self);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self 2 0 2
330 }
331  
332 2 *_cut = *Lingua::ZH::Jiebac::Jieba__cut;
333 2 *_cut_ex = *Lingua::ZH::Jiebac::Jieba__cut_ex;
334 2 *_cut_all = *Lingua::ZH::Jiebac::Jieba__cut_all;
335 2 *_cut_all_ex = *Lingua::ZH::Jiebac::Jieba__cut_all_ex;
336 2 *_cut_for_search = *Lingua::ZH::Jiebac::Jieba__cut_for_search;
337 2 *_cut_for_search_ex = *Lingua::ZH::Jiebac::Jieba__cut_for_search_ex;
338 2 *insert_user_word = *Lingua::ZH::Jiebac::Jieba_insert_user_word;
339 2 *_tag = *Lingua::ZH::Jiebac::Jieba__tag;
340 2 *extractor = *Lingua::ZH::Jiebac::Jieba_extractor;
341 2 ▶sub DESTROY {
Subroutine DESTROY: called CC=4 SCAR=14.0
342 2 ▶ return unless $_[0]->isa('HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]->isa("HASH") 1 1 2
343 1 my $self = tied(%{$_[0]});
344 1 ▶ return unless defined $self;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self 0 1 1
345 1 delete $ITERATORS{$self};
346 1 ▶ if (exists $OWNER{$self}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $OWNER{$self}) 1 0 1
347 1 Lingua::ZH::Jiebac::delete_Jieba($self);
348 1 delete $OWNER{$self};
349 }
350 }
351  
352 0 ▶sub DISOWN {
Subroutine DISOWN: not called CC=1 SCAR=6.9
353 0 my $self = shift;
354 0 my $ptr = tied(%$self);
355 0 delete $OWNER{$ptr};
356 }
357  
358 0 ▶sub ACQUIRE {
Subroutine ACQUIRE: not called CC=1 SCAR=6.9
359 0 my $self = shift;
360 0 my $ptr = tied(%$self);
361 0 $OWNER{$ptr} = 1;
362 }
363  
364  
365 # ------- VARIABLE STUBS --------
366  
367 package Lingua::ZH::Jieba;
368  
369  
370  
371 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
372 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
373 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
374 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
375  
376 package Lingua::ZH::Jieba::KeywordExtractor;
377  
378 1 ▶sub extract {
Subroutine extract: called CC=2 SCAR=6.9
379 1 my ($self, $sentence, $top_n) = @_;
380  
381 1 my $words = $self->_extract($sentence, $top_n);
382  
383 1 for (@$words) {
384 5 utf8::decode($_->[0]);
385 }
386 1 return $words;
387 }
388  
389  
390 package Lingua::ZH::Jieba::Jieba;
391  
392 4 ▶sub _make_cut {
Subroutine _make_cut: called CC=1 SCAR=0.0
393 4 my $want_position = shift;
394  
395 12 ▶ return sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
396 12 my ($self, $sentence, $opts) = @_;
397
398 12 ▶ $opts ||= {};
Condition50%1/2
$opts ||= {}
l!l
120
MC/DC0%0/1
$opts ||= {}
$opts
Truth table50%1/2
A
A= $opts
Aresult
11
00
399 12 my $no_hmm = $opts->{no_hmm};
400 12 my $cut_all = $opts->{cut_all};
401
402 12 my $words;
403
404 12 ▶ if ($want_position) {
Branch: 1 branch
BranchTrueFalseTotal
if ($want_position) { } 6 6 12
405 6 ▶ if ($cut_all) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cut_all) { } 1 5 6
406 1 $words = $self->_cut_all_ex($sentence);
407 } else {
408 5 $words = $self->_cut_ex($sentence, !$no_hmm);
409 }
410 6 for (@$words) {
411 24 utf8::decode($_->[0]);
412 }
413 } else {
414 6 ▶ if ($cut_all) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cut_all) { } 1 5 6
415 1 $words = $self->_cut_all($sentence);
416 } else {
417 5 $words = $self->_cut($sentence, !$no_hmm);
418 }
419 6 for (@$words) {
420 24 utf8::decode($_);
421 }
422 }
423
424 12 return $words;
425 4 };
426 }
427  
428 4 ▶sub _make_cut_for_search {
Subroutine _make_cut_for_search: called CC=1 SCAR=0.0
429 4 my $want_position = shift;
430  
431 2 ▶ return sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
432 2 my ($self, $sentence, $opts) = @_;
433  
434 2 ▶ $opts ||= {};
Condition50%1/2
$opts ||= {}
l!l
20
MC/DC0%0/1
$opts ||= {}
$opts
Truth table50%1/2
A
A= $opts
Aresult
11
00
435 2 my $no_hmm = $opts->{no_hmm};
436
437 2 my $words;
438 2 ▶ if ($want_position) {
Branch: 1 branch
BranchTrueFalseTotal
if ($want_position) { } 1 1 2
439 1 $words = $self->_cut_for_search_ex($sentence, !$no_hmm);
440 1 for (@$words) {
441 19 utf8::decode($_->[0]);
442 }
443 } else {
444 1 $words = $self->_cut_for_search($sentence, !$no_hmm);
445 1 for (@$words) {
446 19 utf8::decode($_);
447 }
448 }
449 2 return $words;
450 4 };
451 }
452  
453 {
454 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
455 2 *cut = _make_cut(0);
456 2 *cut_ex = _make_cut(1);
457 2 *cut_for_search = _make_cut_for_search(0);
458 2 *cut_for_search_ex = _make_cut_for_search(1);
459 }
460  
461 1 ▶sub tag {
Subroutine tag: called CC=2 SCAR=6.9
462 1 my ($self, $sentence) = @_;
463  
464 1 my $words = $self->_tag($sentence);
465 1 for (@$words) {
466 10 utf8::decode($_->[0]);
467 }
468 1 return $words;
469 }
470  
471  
472 package Lingua::ZH::Jieba;
473  
474 2 ▶use File::ShareDir qw(dist_file);
Subroutine BEGIN: called CC=1 SCAR=0.0
475  
476 10 ▶sub _shared_file {
Subroutine _shared_file: called CC=1 SCAR=0.0
477 10 my $file = shift;
478 10 return dist_file('Lingua-ZH-Jieba', $file);
479 }
480 2 my $default_dict_path = _shared_file('dict/jieba.dict.utf8');
481 2 my $default_user_dict_path = _shared_file('dict/user.dict.utf8');
482 2 my $default_hmm_path = _shared_file('dict/hmm_model.utf8');
483 2 my $default_idf_path = _shared_file('dict/idf.utf8');
484 2 my $default_stop_word_path = _shared_file('dict/stop_words.utf8');
485  
486 2 ▶sub new {
Subroutine new: called CC=7 SCAR=21.0
Pod documented
487 2 my $pkg = shift;
488 2 my $opts = shift;
489  
490 2 ▶ $opts //= {};
Condition100%2/2
$opts //= {}
l!l
11
MC/DC100%1/1
$opts //= {}
$opts
Truth table100%2/2
A
A= $opts
Aresult
11
00
491
492 2 my $dict_path = $opts->{dict_path};
493 2 my $hmm_path = $opts->{hmm_path};
494 2 my $user_dict_path = $opts->{user_dict_path};
495 2 my $idf_path = $opts->{idf_path};
496 2 my $stop_word_path = $opts->{stop_word_path};
497  
498 2 ▶ $dict_path //= $default_dict_path;
Condition33%1/3
$dict_path //= $default_dict_path
l!l&&r!l&&!r
020
MC/DC0%0/2
$dict_path //= $default_dict_path
$dict_path $default_dict_path
Truth table33%1/3
A //= B
A= $dict_pathB= $default_dict_path
ABresult
1X1
011
000
499 2 ▶ $hmm_path //= $default_hmm_path;
Condition33%1/3
$hmm_path //= $default_hmm_path
l!l&&r!l&&!r
020
MC/DC0%0/2
$hmm_path //= $default_hmm_path
$hmm_path $default_hmm_path
Truth table33%1/3
A //= B
A= $hmm_pathB= $default_hmm_path
ABresult
1X1
011
000
500 2 ▶ $user_dict_path //= $default_user_dict_path;
Condition66%2/3
$user_dict_path //= $default_user_dict_path
l!l&&r!l&&!r
110
MC/DC0%0/2
$user_dict_path //= $default_user_dict_path
$user_dict_path $default_user_dict_path
Truth table66%2/3
A //= B
A= $user_dict_pathB= $default_user_dict_path
ABresult
1X1
011
000
501 2 ▶ $idf_path //= $default_idf_path;
Condition33%1/3
$idf_path //= $default_idf_path
l!l&&r!l&&!r
020
MC/DC0%0/2
$idf_path //= $default_idf_path
$idf_path $default_idf_path
Truth table33%1/3
A //= B
A= $idf_pathB= $default_idf_path
ABresult
1X1
011
000
502 2 ▶ $stop_word_path //= $default_stop_word_path;
Condition33%1/3
$stop_word_path //= $default_stop_word_path
l!l&&r!l&&!r
020
MC/DC0%0/2
$stop_word_path //= $default_stop_word_path
$stop_word_path $default_stop_word_path
Truth table33%1/3
A //= B
A= $stop_word_pathB= $default_stop_word_path
ABresult
1X1
011
000
503
504 2 return Lingua::ZH::Jieba::Jieba->new(
505 $dict_path . "",
506 $hmm_path . "",
507 $user_dict_path . "",
508 $idf_path . "",
509 $stop_word_path . ""
510 );
511 }
512  
513 2 1;
↑ Summary