Fukuball\Jieba\Jieba::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', 'dict' => 'normal');
        $options = array_merge($defaults, $options);
        if ($options['mode'] == 'test') {
            echo "Building Trie...\n";
        }
        if ($options['dict'] == 'small') {
            $f_name = "dict.small.txt";
            self::$dictname = "dict.small.txt";
        } elseif ($options['dict'] == 'big') {
            $f_name = "dict.big.txt";
            self::$dictname = "dict.big.txt";
        } else {
            $f_name = "dict.txt";
            self::$dictname = "dict.txt";
        }
        $t1 = microtime(true);
        self::$trie = Jieba::genTrie(dirname(dirname(__FILE__)) . "/dict/" . $f_name);
        foreach (self::$FREQ as $key => $value) {
            self::$FREQ[$key] = log($value / self::$total);
        }
        self::$min_freq = min(self::$FREQ);
        if ($options['mode'] == 'test') {
            echo "loading model cost " . (microtime(true) - $t1) . " seconds.\n";
            echo "Trie has been built succesfully.\n";
        }
    }

Usage Example

Exemplo 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\Jieba::init