Example #1
0
 /**
  * Convert $str to same register with $base
  *
  * @param string $str
  * @param string $base
  * @return string
  */
 protected function toSameRegister($str, $base)
 {
     $minLen = min($this->text->strlen($base), $this->text->strlen($str));
     for ($i = 0; $i < $minLen; $i++) {
         $chr = $this->text->substr($base, $i, 1);
         if ($chr != $this->text->strtolower($chr)) {
             $chrN = $this->text->substr($str, $i, 1);
             $chrN = strtoupper($chrN);
             $str = substr_replace($str, $chrN, $i, 1);
         }
     }
     return $str;
 }
Example #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;
             }
         }
     }
 }
Example #3
0
 /**
  * Fallback
  *
  * @param string $text
  * @return string
  */
 public function fallback($text)
 {
     $arQuery = $this->text->splitWords($text);
     for ($i = 1; $i < count($arQuery); $i++) {
         $combinations = $this->fallbackCombinations($arQuery, $i);
         foreach ($combinations as $combination) {
             $newQuery = $text;
             foreach ($combination as $word) {
                 $newQuery = str_replace($word, '', $newQuery);
                 $cntResults = $this->getNumResults($newQuery);
                 if ($cntResults > 0) {
                     $newQuery = preg_replace('/\\s{2,}/', ' ', $newQuery);
                     return trim($newQuery);
                 }
             }
         }
     }
     return false;
 }
Example #4
0
 /**
  * Highlight string
  *
  * @param string $new
  * @param string $old
  * @param string $tag
  * @return string
  */
 public function highlight($new, $old, $tag = 'em')
 {
     return $this->text->htmlDiff($new, $old, $tag);
 }
Example #5
0
 /**
  * Case insensitive version of similarity()
  *
  * @param string $strA
  * @param string $strB
  *
  * @return int distance from 0 to 100
  */
 public function similarity($strA, $strB)
 {
     return $this->_similarity($this->text->strtolower($strA), $this->text->strtolower($strB));
 }
Example #6
0
 /**
  * @param null|string $expected
  * @param string      $data
  * @dataProvider prepareGetTrigramProvider
  */
 public function testGetTrigram($expected, $data)
 {
     $this->assertEquals($expected, $this->model->getTrigram($data));
 }