Esempio n. 1
0
 /**
  * An attempt to measure word similarity in percent
  *
  * @param string $strA
  * @param string $strB
  *
  * @return int distance from 0 to 100
  */
 protected function _similarity($strA, $strB)
 {
     $lenA = $this->text->strlen($strA);
     $lenB = $this->text->strlen($strB);
     if ($lenA == 0 && $lenB == 0) {
         return 100;
     }
     $distance = $this->_distance($strA, $strB);
     $similarity = 100 - (int) round(200 * $distance / ($lenA + $lenB));
     return $similarity >= 100 ? 100 : $similarity;
 }
Esempio n. 2
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;
 }
Esempio n. 3
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;
             }
         }
     }
 }