Fukuball\Jieba\Posseg::init PHP Method

init() public static method

Static method init
public static init ( array $options = [] ) : void
$options array # other options
return void
    public static function init($options = array())
    {
        $defaults = array('mode' => 'default');
        $options = array_merge($defaults, $options);
        self::$prob_start = self::loadModel(dirname(dirname(__FILE__)) . '/model/pos/prob_start.json');
        self::$prob_trans = self::loadModel(dirname(dirname(__FILE__)) . '/model/pos/prob_trans.json');
        self::$prob_emit = self::loadModel(dirname(dirname(__FILE__)) . '/model/pos/prob_emit.json');
        self::$char_state = self::loadModel(dirname(dirname(__FILE__)) . '/model/pos/char_state.json');
        if (Jieba::$dictname != "") {
            $content = fopen(dirname(dirname(__FILE__)) . "/dict/" . Jieba::$dictname, "r");
            while (($line = fgets($content)) !== false) {
                $explode_line = explode(" ", trim($line));
                $word = $explode_line[0];
                $freq = $explode_line[1];
                $tag = $explode_line[2];
                self::$word_tag[$word] = $tag;
            }
            fclose($content);
        }
        if (sizeof(Jieba::$user_dictname) != 0) {
            for ($i = 0; $i < sizeof(Jieba::$user_dictname); $i++) {
                $content = fopen(Jieba::$user_dictname[$i], "r");
                while (($line = fgets($content)) !== false) {
                    $explode_line = explode(" ", trim($line));
                    $word = $explode_line[0];
                    $freq = $explode_line[1];
                    $tag = $explode_line[2];
                    self::$word_tag[$word] = $tag;
                }
                fclose($content);
            }
        }
        $content = fopen(dirname(dirname(__FILE__)) . "/dict/pos_tag_readable.txt", "r");
        while (($line = fgets($content)) !== false) {
            $explode_line = explode(" ", trim($line));
            $tag = $explode_line[0];
            $meaning = $explode_line[1];
            self::$pos_tag_readable[$tag] = $meaning;
        }
        fclose($content);
    }

Usage Example

Ejemplo n.º 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::init