Exemple #1
0
 /**
  * Gets the specified text from the list of defined words in the file.
  *
  * @param  string $string
  * @return string
  */
 public function getText($string = '')
 {
     $multiArray = new MultiArray($this->vocabulary);
     $result = $multiArray->get($string);
     return is_string($result) ? $result : $string;
 }
Exemple #2
0
 *
 * PHP version 5
 *
 * @category PHP
 * @package  /src/cmd/
 * @author   Fukuball Lin <*****@*****.**>
 * @license  MIT Licence
 * @version  GIT: <fukuball/jieba-php>
 * @link     https://github.com/fukuball/jieba-php
 */
ini_set('memory_limit', '1024M');
require_once dirname(dirname(__FILE__)) . "/vendor/multi-array/MultiArray.php";
require_once dirname(dirname(__FILE__)) . "/vendor/multi-array/Factory/MultiArrayFactory.php";
use Tebru\MultiArray;
$content = fopen(dirname(dirname(__FILE__)) . "/dict/dict.txt", "r");
$trie = new MultiArray(array());
while (($line = fgets($content)) !== false) {
    echo $line;
    $explode_line = explode(" ", trim($line));
    $word = $explode_line[0];
    $l = mb_strlen($word, 'UTF-8');
    $word_c = array();
    for ($i = 0; $i < $l; $i++) {
        $c = mb_substr($word, $i, 1, 'UTF-8');
        array_push($word_c, $c);
    }
    $word_c_key = implode('.', $word_c);
    $trie->set($word_c_key, array("end" => ""));
}
file_put_contents(dirname(dirname(__FILE__)) . "/dict/dict.txt.json", json_encode($trie->storage));
file_put_contents(dirname(dirname(__FILE__)) . "/dict/dict.txt.cache.json", json_encode($trie->cache));
Exemple #3
0
 /**
  * @expectedException OutOfBoundsException
  */
 public function testUnsetWillThrowException()
 {
     $array = $this->getMultiArray();
     $jsonObject = new MultiArray($array);
     $jsonObject->remove('key4');
 }