Fukuball\Jieba\Posseg::cut PHP Метод

cut() публичный статический Метод

Static method cut
public static cut ( string $sentence, array $options = [] ) : array
$sentence string # input sentence
$options array # other options
Результат array $seg_list
    public static function cut($sentence, $options = array())
    {
        $defaults = array('mode' => 'default');
        @($options = array_merge($defaults, $options));
        $seg_list = array();
        $re_han_pattern = '([\\x{4E00}-\\x{9FA5}]+)';
        $re_skip_pattern = '([a-zA-Z0-9+#\\r\\n]+)';
        $re_punctuation_pattern = '([\\x{ff5e}\\x{ff01}\\x{ff08}\\x{ff09}\\x{300e}' . '\\x{300c}\\x{300d}\\x{300f}\\x{3001}\\x{ff1a}\\x{ff1b}' . '\\x{ff0c}\\x{ff1f}\\x{3002}]+)';
        $re_eng_pattern = '[a-zA-Z+#]+';
        $re_num_pattern = '[0-9]+';
        preg_match_all('/(' . $re_han_pattern . '|' . $re_skip_pattern . '|' . $re_punctuation_pattern . ')/u', $sentence, $matches, PREG_PATTERN_ORDER);
        $blocks = $matches[0];
        foreach ($blocks as $blk) {
            if (preg_match('/' . $re_han_pattern . '/u', $blk)) {
                $words = Posseg::__cutDAG($blk);
                foreach ($words as $word) {
                    array_push($seg_list, $word);
                }
            } elseif (preg_match('/' . $re_skip_pattern . '/u', $blk)) {
                if (preg_match('/' . $re_num_pattern . '/u', $blk)) {
                    array_push($seg_list, array("word" => $blk, "tag" => "m"));
                } elseif (preg_match('/' . $re_eng_pattern . '/u', $blk)) {
                    array_push($seg_list, array("word" => $blk, "tag" => "eng"));
                }
            } elseif (preg_match('/' . $re_punctuation_pattern . '/u', $blk)) {
                array_push($seg_list, array("word" => $blk, "tag" => "w"));
            }
        }
        return $seg_list;
    }

Usage Example

Пример #1
0
 public function getPartofspeech($string)
 {
     Jieba::init();
     Finalseg::init();
     Posseg::init();
     $seg_list = Posseg::cut($string);
     $this->cixing = $seg_list;
     return $seg_list;
 }
All Usage Examples Of Fukuball\Jieba\Posseg::cut