public function testPinyin()
 {
     $test = new Pinyin();
     $content = $test->getPinyin('你好拼音');
     $this->comment($content);
     $this->assertTrue(!empty($content));
 }
Example #2
0
 /**
  * ...
  *
  * @param $strings
  * @return array
  */
 public static function generate($strings)
 {
     // TODO 逐个连接字符
     $generates = [];
     foreach ($strings as $string) {
         // 添加
         $name = Pinyin::getPinyin($string) . '@' . Pinyin::getPinyinFirst($string);
         $info = [];
         $account = new Account();
         $account->setName($name);
         $account->addAmount($string, $info);
         $generates[] = $account;
     }
     return $generates;
 }
Example #3
0
 /**
  * 生成搜索key
  *
  * @return string
  */
 public function getSearchKey($keyChain = [Suggest::KEY_RAW, Suggest::KEY_PINYIN])
 {
     $keys = [];
     // check have pinyin word
     if (Suggest::$config['cn_inlcude_pinyin'] != true) {
         $keyChain = [Suggest::KEY_RAW];
     }
     // generate keys for search
     foreach ($keyChain as $key) {
         if ($key == Suggest::KEY_RAW) {
             // raw char
             $word = Analyze::clear($this->word);
             $keys[] = strlen($this->word) > 1 ? RedisStore::PREFIX . $this->getType() . '#' . '*' . '@' . '*' . $word . '*' : RedisStore::PREFIX . $this->getType() . '#' . '*' . '@' . $word . '*';
         }
         if ($key == Suggest::KEY_PINYIN) {
             // pinyin
             $pinyin = Analyze::clear(Pinyin::getPinyin($this->word));
             $keys[] = strlen($this->word) > 1 ? RedisStore::PREFIX . $this->getType() . '#' . '*' . $pinyin . '*' . '@' . '*' : RedisStore::PREFIX . $this->getType() . '#' . $pinyin . '*' . '@' . '*';
         }
     }
     return $keys;
 }
Example #4
0
 /**
  * @param $word
  * @return string
  */
 public static function parse($word)
 {
     $word = Pinyin::getPinyin($word);
     return strtolower($word);
 }