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";
}
}