Esempio n. 1
0
 /**
  * Split string
  *
  * @param string $query
  * @param string $prefix
  * @param string $base
  * @return bool
  */
 protected function split($query, $prefix = '', $base = '')
 {
     $len = $this->text->strlen($query);
     if ($len > 20) {
         return false;
     }
     for ($i = $this->text->getGram(); $i <= $len - $this->text->getGram() + 1; $i++) {
         $a = $this->text->substr($query, 0, $i);
         $b = $this->text->substr($query, $i);
         $aa = $this->getBestMatch($a);
         $bb = $this->getBestMatch($b);
         $key = $a . '|' . $b;
         if ($prefix) {
             $key = $prefix . '|' . $key;
         }
         $this->keys[$key] = '';
         if ($prefix) {
             $this->keys[$key] = $prefix . ' ';
         }
         $this->keys[$key] .= $aa['keyword'] . ' ' . $bb['keyword'];
         $this->diffs[$key] = ($this->damerau->similarity($base, $this->keys[$key]) + $aa['diff'] + $bb['diff']) / 3;
         if ($prefix) {
             $kwd = $prefix . '|' . $aa['keyword'];
         } else {
             $kwd = $aa['keyword'];
         }
         if ($aa['diff'] > 50) {
             $this->split($b, $kwd, $query);
         }
     }
     return null;
 }
Esempio n. 2
0
 /**
  * Split string to words
  *
  * @param string $string
  * @param array  &$results
  * @param int    $increment
  * @return void
  */
 protected function split($string, &$results, $increment = 1)
 {
     $string = $this->text->cleanString($string);
     $words = $this->text->splitWords($string);
     foreach ($words as $word) {
         if ($this->text->strlen($word) >= $this->text->getGram() && !is_numeric($word) && $this->text->strlen($word) <= 10) {
             $word = $this->text->strtolower($word);
             if (!isset($results[$word])) {
                 $results[$word] = $increment;
             } else {
                 $results[$word] += $increment;
             }
         }
     }
 }