fukuball / jieba-php
Showing 1 of 1 files from the diff.

@@ -53,10 +53,10 @@
Loading
53 53
        self::$prob_emit = self::loadModel(dirname(dirname(__FILE__)).'/model/pos/prob_emit.json');
54 54
        self::$char_state = self::loadModel(dirname(dirname(__FILE__)).'/model/pos/char_state.json');
55 55
56 -
        if (Jieba::$dictname!="") {
57 -
            $content = fopen(dirname(dirname(__FILE__))."/dict/".Jieba::$dictname, "r");
56 +
        if (Jieba::$dictname!='') {
57 +
            $content = fopen(dirname(dirname(__FILE__)).'/dict/'.Jieba::$dictname, 'r');
58 58
            while (($line = fgets($content)) !== false) {
59 -
                $explode_line = explode(" ", trim($line));
59 +
                $explode_line = explode(' ', trim($line));
60 60
                $word = $explode_line[0];
61 61
                $freq = $explode_line[1];
62 62
                $tag = $explode_line[2];
@@ -68,9 +68,9 @@
Loading
68 68
69 69
        if (sizeof(Jieba::$user_dictname)!=0) {
70 70
            for ($i = 0; $i<sizeof(Jieba::$user_dictname); $i++) {
71 -
                $content = fopen(Jieba::$user_dictname[$i], "r");
71 +
                $content = fopen(Jieba::$user_dictname[$i], 'r');
72 72
                while (($line = fgets($content)) !== false) {
73 -
                    $explode_line = explode(" ", trim($line));
73 +
                    $explode_line = explode(' ', trim($line));
74 74
                    $word = $explode_line[0];
75 75
                    $freq = $explode_line[1];
76 76
                    $tag = $explode_line[2];
@@ -80,10 +80,10 @@
Loading
80 80
            }
81 81
        }
82 82
83 -
        $content = fopen(dirname(dirname(__FILE__))."/dict/pos_tag_readable.txt", "r");
83 +
        $content = fopen(dirname(dirname(__FILE__)).'/dict/pos_tag_readable.txt', 'r');
84 84
85 85
        while (($line = fgets($content)) !== false) {
86 -
            $explode_line = explode(" ", trim($line));
86 +
            $explode_line = explode(' ', trim($line));
87 87
            $tag = $explode_line[0];
88 88
            $meaning = $explode_line[1];
89 89
            self::$pos_tag_readable[$tag] = $meaning;
@@ -186,7 +186,7 @@
Loading
186 186
187 187
            foreach ($prev_mem_path as $mem_path_state) {
188 188
                if (count(self::$prob_trans[$mem_path_state])>0) {
189 -
                    array_push($prev_states, $mem_path_state);
189 +
                    $prev_states[] = $mem_path_state;
190 190
                }
191 191
            }
192 192
@@ -258,7 +258,7 @@
Loading
258 258
259 259
        $route = array();
260 260
        for ($t=0; $t<$obs_length; $t++) {
261 -
            array_push($route, 'None');
261 +
            $route[] = 'None';
262 262
        }
263 263
264 264
        $i = $obs_length-1;
@@ -269,7 +269,7 @@
Loading
269 269
            $i-=1;
270 270
        }
271 271
272 -
        return array("prob"=>$return_prob, "pos_list"=>$route);
272 +
        return array('prob'=>$return_prob, 'pos_list'=>$route);
273 273
    }// end function viterbi
274 274
275 275
    /**
@@ -280,7 +280,7 @@
Loading
280 280
     *
281 281
     * @return array $words
282 282
     */
283 -
    public static function __cut($sentence, $options = array("HMM" => true))
283 +
    public static function __cut($sentence, $options = array('HMM' => true))
284 284
    {
285 285
        $defaults = array(
286 286
            'mode'=>'default'
@@ -310,19 +310,19 @@
Loading
310 310
                eval('$this_pos_array = array'.$pos_list[$i].';');
311 311
                $this_pos = $this_pos_array[1];
312 312
                $this_word_pair = array(
313 -
                    "word"=>mb_substr($sentence, $begin, (($i+1)-$begin), 'UTF-8'),
314 -
                    "tag"=>$this_pos
313 +
                    'word'=>mb_substr($sentence, $begin, (($i+1)-$begin), 'UTF-8'),
314 +
                    'tag'=>$this_pos
315 315
                );
316 -
                array_push($words, $this_word_pair);
316 +
                $words[] = $this_word_pair;
317 317
                $next = $i+1;
318 318
            } elseif ($pos=='S') {
319 319
                eval('$this_pos_array = array'.$pos_list[$i].';');
320 320
                $this_pos = $this_pos_array[1];
321 321
                $this_word_pair = array(
322 -
                    "word"=>$char,
323 -
                    "tag"=>$this_pos
322 +
                    'word'=>$char,
323 +
                    'tag'=>$this_pos
324 324
                );
325 -
                array_push($words, $this_word_pair);
325 +
                $words[] = $this_word_pair;
326 326
                $next = $i+1;
327 327
            }
328 328
        }
@@ -331,10 +331,10 @@
Loading
331 331
            eval('$this_pos_array = array'.$pos_list[$next].';');
332 332
            $this_pos = $this_pos_array[1];
333 333
            $this_word_pair = array(
334 -
                "word"=>mb_substr($sentence, $next, null, 'UTF-8'),
335 -
                "tag"=>$this_pos
334 +
                'word'=>mb_substr($sentence, $next, null, 'UTF-8'),
335 +
                'tag'=>$this_pos
336 336
            );
337 -
            array_push($words, $this_word_pair);
337 +
            $words[] = $this_word_pair;
338 338
        }
339 339
340 340
        return $words;
@@ -378,16 +378,16 @@
Loading
378 378
            if (preg_match('/'.$re_han_pattern.'/u', $blk)) {
379 379
                $blk_words = self::__cut($blk);
380 380
                foreach ($blk_words as $blk_word) {
381 -
                    array_push($words, $blk_word);
381 +
                    $words[] = $blk_word;
382 382
                }
383 383
            } elseif (preg_match('/'.$re_skip_pattern.'/u', $blk)) {
384 384
                if (preg_match('/'.$re_num_pattern.'/u', $blk)) {
385 -
                    array_push($words, array("word"=>$blk, "tag"=>"m"));
385 +
                    $words[] = array('word' => $blk, 'tag' => 'm');
386 386
                } elseif (preg_match('/'.$re_eng_pattern.'/u', $blk)) {
387 -
                    array_push($words, array("word"=>$blk, "tag"=>"eng"));
387 +
                    $words[] = array('word' => $blk, 'tag' => 'eng');
388 388
                }
389 389
            } elseif (preg_match('/'.$re_punctuation_pattern.'/u', $blk)) {
390 -
                array_push($words, array("word"=>$blk, "tag"=>"w"));
390 +
                $words[] = array('word' => $blk, 'tag' => 'w');
391 391
            }
392 392
        }
393 393
@@ -433,18 +433,15 @@
Loading
433 433
                        if (isset(self::$word_tag[$buf])) {
434 434
                            $buf_tag = self::$word_tag[$buf];
435 435
                        } else {
436 -
                            $buf_tag = "x";
436 +
                            $buf_tag = 'x';
437 437
                        }
438 -
                        array_push(
439 -
                            $words,
440 -
                            array("word"=>$buf, "tag"=>$buf_tag)
441 -
                        );
438 +
                        $words[] = array('word' => $buf, 'tag' => $buf_tag);
442 439
                        $buf = '';
443 440
                    } else {
444 441
                        if (! isset(Jieba::$FREQ[$buf])) {
445 442
                            $regognized = self::__cutDetail($buf);
446 443
                            foreach ($regognized as $key => $word) {
447 -
                                array_push($words, $word);
444 +
                                $words[] = $word;
448 445
                            }
449 446
                        } else {
450 447
                            $elem_array = preg_split('//u', $buf, -1, PREG_SPLIT_NO_EMPTY);
@@ -452,12 +449,9 @@
Loading
452 449
                                if (isset(self::$word_tag[$word])) {
453 450
                                    $buf_tag = self::$word_tag[$word];
454 451
                                } else {
455 -
                                    $buf_tag = "x";
452 +
                                    $buf_tag = 'x';
456 453
                                }
457 -
                                array_push(
458 -
                                    $words,
459 -
                                    array("word"=>$word, "tag"=>$buf_tag)
460 -
                                );
454 +
                                $words[] = array('word' => $word, 'tag' => $buf_tag);
461 455
                            }
462 456
                        }
463 457
                        $buf = '';
@@ -467,12 +461,9 @@
Loading
467 461
                if (isset(self::$word_tag[$l_word])) {
468 462
                    $buf_tag = self::$word_tag[$l_word];
469 463
                } else {
470 -
                    $buf_tag = "x";
464 +
                    $buf_tag = 'x';
471 465
                }
472 -
                array_push(
473 -
                    $words,
474 -
                    array("word"=>$l_word, "tag"=>$buf_tag)
475 -
                );
466 +
                $words[] = array('word' => $l_word, 'tag' => $buf_tag);
476 467
            }
477 468
            $x = $y;
478 469
        }
@@ -482,17 +473,14 @@
Loading
482 473
                if (isset(self::$word_tag[$buf])) {
483 474
                    $buf_tag = self::$word_tag[$buf];
484 475
                } else {
485 -
                    $buf_tag = "x";
476 +
                    $buf_tag = 'x';
486 477
                }
487 -
                array_push(
488 -
                    $words,
489 -
                    array("word"=>$buf, "tag"=>$buf_tag)
490 -
                );
478 +
                $words[] = array('word'=>$buf, 'tag'=>$buf_tag);
491 479
            } else {
492 480
                if (! isset(Jieba::$FREQ[$buf])) {
493 481
                    $regognized = self::__cutDetail($buf);
494 482
                    foreach ($regognized as $key => $word) {
495 -
                        array_push($words, $word);
483 +
                        $words[] = $word;
496 484
                    }
497 485
                } else {
498 486
                    $elem_array = preg_split('//u', $buf, -1, PREG_SPLIT_NO_EMPTY);
@@ -500,12 +488,9 @@
Loading
500 488
                        if (isset(self::$word_tag[$word])) {
501 489
                            $buf_tag = self::$word_tag[$word];
502 490
                        } else {
503 -
                            $buf_tag = "x";
491 +
                            $buf_tag = 'x';
504 492
                        }
505 -
                        array_push(
506 -
                            $words,
507 -
                            array("word"=>$word, "tag"=>$buf_tag)
508 -
                        );
493 +
                        $words[] = array('word'=>$word, 'tag'=>$buf_tag);
509 494
                    }
510 495
                }
511 496
            }
@@ -555,23 +540,17 @@
Loading
555 540
                    if (isset(self::$word_tag[$buf])) {
556 541
                        $buf_tag = self::$word_tag[$buf];
557 542
                    } else {
558 -
                        $buf_tag = "x";
543 +
                        $buf_tag = 'x';
559 544
                    }
560 -
                    array_push(
561 -
                        $words,
562 -
                        array("word"=>$buf, "tag"=>$buf_tag)
563 -
                    );
545 +
                    $words[] = array('word' => $buf, 'tag' => $buf_tag);
564 546
                    $buf = '';
565 547
                }
566 548
                if (isset(self::$word_tag[$l_word])) {
567 549
                    $buf_tag = self::$word_tag[$l_word];
568 550
                } else {
569 -
                    $buf_tag = "x";
551 +
                    $buf_tag = 'x';
570 552
                }
571 -
                array_push(
572 -
                    $words,
573 -
                    array("word"=>$l_word, "tag"=>$buf_tag)
574 -
                );
553 +
                $words[] = array('word' => $l_word, 'tag' => $buf_tag);
575 554
                $x = $y;
576 555
            }
577 556
        }
@@ -580,12 +559,9 @@
Loading
580 559
            if (isset(self::$word_tag[$buf])) {
581 560
                $buf_tag = self::$word_tag[$buf];
582 561
            } else {
583 -
                $buf_tag = "x";
562 +
                $buf_tag = 'x';
584 563
            }
585 -
            array_push(
586 -
                $words,
587 -
                array("word"=>$buf, "tag"=>$buf_tag)
588 -
            );
564 +
            $words[] = array('word' => $buf, 'tag' => $buf_tag);
589 565
        }
590 566
591 567
        return $words;
@@ -599,7 +575,7 @@
Loading
599 575
     *
600 576
     * @return array $seg_list
601 577
     */
602 -
    public static function cut($sentence, $options = array("HMM" => true))
578 +
    public static function cut($sentence, $options = array('HMM' => true))
603 579
    {
604 580
        $defaults = array(
605 581
            'mode'=>'default'
@@ -634,16 +610,16 @@
Loading
634 610
                }
635 611
636 612
                foreach ($words as $word) {
637 -
                    array_push($seg_list, $word);
613 +
                    $seg_list[] = $word;
638 614
                }
639 615
            } elseif (preg_match('/'.$re_skip_pattern.'/u', $blk)) {
640 616
                if (preg_match('/'.$re_num_pattern.'/u', $blk)) {
641 -
                    array_push($seg_list, array("word"=>$blk, "tag"=>"m"));
617 +
                    $seg_list[] = array('word' => $blk, 'tag' => 'm');
642 618
                } elseif (preg_match('/'.$re_eng_pattern.'/u', $blk)) {
643 -
                    array_push($seg_list, array("word"=>$blk, "tag"=>"eng"));
619 +
                    $seg_list[] = array('word' => $blk, 'tag' => 'eng');
644 620
                }
645 621
            } elseif (preg_match('/'.$re_punctuation_pattern.'/u', $blk)) {
646 -
                array_push($seg_list, array("word"=>$blk, "tag"=>"w"));
622 +
                $seg_list[] = array('word' => $blk, 'tag' => 'w');
647 623
            }
648 624
        }
649 625
@@ -670,7 +646,7 @@
Loading
670 646
671 647
        foreach ($seg_list as $seg) {
672 648
            $seg['tag_readable'] = self::$pos_tag_readable[$seg['tag']];
673 -
            array_push($new_seg_list, $seg);
649 +
            $new_seg_list[] = $seg;
674 650
        }
675 651
676 652
        return $new_seg_list;
Files Complexity Coverage
src/class 268 55.48%
Project Totals (5 files) 268 55.48%
139.2
TRAVIS_PHP_VERSION=7.2
TRAVIS_OS_NAME=linux
139.1
TRAVIS_PHP_VERSION=7.1
TRAVIS_OS_NAME=linux

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading