Fukuball\Jieba\Posseg::__cut PHP Method

__cut() public static method

Static method __cut
public static __cut ( string $sentence, array $options = [] ) : array
$sentence string # input sentence
$options array # other options
return array $words
    public static function __cut($sentence, $options = array())
    {
        $defaults = array('mode' => 'default');
        $options = array_merge($defaults, $options);
        $words = array();
        $viterbi_array = self::viterbi($sentence);
        $prob = $viterbi_array['prob'];
        $pos_list = $viterbi_array['pos_list'];
        $begin = 0;
        $next = 0;
        $len = mb_strlen($sentence, 'UTF-8');
        for ($i = 0; $i < $len; $i++) {
            $char = mb_substr($sentence, $i, 1, 'UTF-8');
            eval('$pos_array = array' . $pos_list[$i] . ';');
            $pos = $pos_array[0];
            if ($pos == 'B') {
                $begin = $i;
            } elseif ($pos == 'E') {
                eval('$this_pos_array = array' . $pos_list[$i] . ';');
                $this_pos = $this_pos_array[1];
                $this_word_pair = array("word" => mb_substr($sentence, $begin, $i + 1 - $begin, 'UTF-8'), "tag" => $this_pos);
                array_push($words, $this_word_pair);
                $next = $i + 1;
            } elseif ($pos == 'S') {
                eval('$this_pos_array = array' . $pos_list[$i] . ';');
                $this_pos = $this_pos_array[1];
                $this_word_pair = array("word" => $char, "tag" => $this_pos);
                array_push($words, $this_word_pair);
                $next = $i + 1;
            }
        }
        if ($next < $len) {
            eval('$this_pos_array = array' . $pos_list[$next] . ';');
            $this_pos = $this_pos_array[1];
            $this_word_pair = array("word" => mb_substr($sentence, $next, null, 'UTF-8'), "tag" => $this_pos);
            array_push($words, $this_word_pair);
        }
        return $words;
    }