Returns the most frequently used letter with the same
frequency
@param string $text1
@param string $text2
@return int
432909
public function similarity($text1, $text2)
    {
        $similarity = 0;
        $hash1 = $this->hashString($text1);
        $hash2 = $this->hashString($text2);        
        
        $keys = array_keys(array_intersect_key($hash1, $hash2));
        foreach($keys as $key)
        {
            if($hash1[$key] === $hash2[$key] && $hash1[$key] >= $this->limit)
            {
                $similarity += $hash1[$key];
            }
        }        
        return $similarity;
    }
402388
private static function getLetter($columnIndex)
    {
        if ($columnIndex < self::LETTER_COUNT) {
            return self::LETTER[$columnIndex];
        } else {
            $letter1 = self::LETTER[(int)($columnIndex / self::LETTER_COUNT) - 1];
            $letter2 = self::LETTER[($columnIndex % self::LETTER_COUNT)];
            return $letter1 . $letter2;
        }
    }
455185
public function similarity($text1, $text2) 
    {
        if($this->useCache && !isset($this->cache[$text2])) {
            $this->cache[$text2] = Text::getAllSubStrings($text2);
        }
        
        $intersection = array_intersect( Text::getAllSubStrings($text1), ($this->useCache) ? $this->cache[$text2] : Text::getAllSubStrings($text2));
        $max = 0;
        $lcs = '';
        foreach($intersection as $substr)
        {
            $strlen = mb_strlen($substr);
            if( $strlen > $max) {
                $max = $strlen;
                $lcs = $substr;
            }
        }
        return $lcs;
    }
1348605
public static function compareBaseStrings($string1, $string2)
    {
    	if ( $string1 == $string2 ) return true;

    	$out2 = "";
    	$out1 = "";
        $chars = 0;
    	$oops = false;
        for($i=0; $i<strlen($string1)&&$i<strlen($string2); $i++) {
    		if ( $oops || $string1[$i] == $string2[$i] ) {
    			$out1 = $out1 . $string1[$i];
    			$out2 = $out2 . $string2[$i];
    		} else {
    			$out1 = $out1 . ' ->' . $string1[$i] .'<- ';
    			$out2 = $out2 . ' ->' . $string2[$i] .'<- ';
    			$oops = true;
    		}
    		$chars = $chars + 1;
    		if ( $chars > 79 ) {
    			$out1 .= "\n";
    			$out2 .= "\n";
    			$chars = 0;
    		}
    	}
    	if ( $i < strlen($string1) ) {
    		$out2 = $out2 . ' -> truncated ';
    		for($i=0; $i<strlen($string1); $i++) {
    			$out1 = $out1 . $string1[$i];
    			$chars = $chars + 1;
    			if ( $chars > 79 ) {
    				$out1 .= "\n";
    				$chars = 0;
    			}
    		}
    	}

    	if ( $i < strlen($string2) ) {
    		$out1 = $out1 . ' -> truncated ';
    		for($i=0; $i<strlen($string2); $i++) {
    			$out2 = $out2 . $string2[$i];
    			$chars = $chars + 2;
    			if ( $chars > 79 ) {
    				$out2 .= "\n";
    				$chars = 0;
    			}
    		}
    	}
    	return $out1 . "\n-------------\n" . $out2 . "\n";
    }
891209
public function getFirstLetter()
    {
        switch ($this->day_of_week_number)
        {
            case self::MON: return 'M';
            case self::TUE: return 'T';
            case self::WED: return 'W';
            case self::THU: return 'T';
            case self::FRI: return 'F';
            case self::SAT: return 'S';
            case self::SUN: return 'S';
        }
    }
746655
public static function compareElements($elem1, $elem2)
    {
        if (is_array($elem1)) {
            if (is_array($elem2)) {
                return strcmp(serialize($elem1), serialize($elem2));
            }

            return 1;
        }

        if (is_array($elem2)) {
            return -1;
        }

        if ((string)$elem1 === (string)$elem2) {
            return 0;
        }

        return ((string)$elem1 > (string)$elem2) ? 1 : -1;
    }
478612
public static double oliverSimilarity(String text1, String text2) {
        preprocessDocument(text1);
        preprocessDocument(text2);

        String smallerDoc=text1;
        String biggerDoc=text2;
        if(text1.length()>text2.length()) {
            smallerDoc=text2;
            biggerDoc=text1;
        }

        double p=PHPSimilarText.similarityPercentage(smallerDoc, biggerDoc);
        p/=100.0;

        return p;
    }
1061454
public static function compare($str1, $str2, $ignoreCase = true)
    {
        if ($ignoreCase) {
            if (strcasecmp($str1, $str2) == 0) {
                return true;
            }
        } else {
            if (strcmp($str1, $str2) == 0) {
                return true;
            }
        }

        return false;
    }
645547
public static int commonSuffix(String text1, String text2) {
        // Performance analysis: http://neil.fraser.name/news/2007/10/09/
        int text1_length = text1.length();
        int text2_length = text2.length();
        int n = Math.min(text1_length, text2_length);
        for (int i = 1; i <= n; i++) {
            if (text1.charAt(text1_length - i) != text2.charAt(text2_length - i)) {
                return i - 1;
            }
        }
        return n;
    }
799648
function &shuffleText( $text )
    {
        $num = mt_rand( 0, $this->MaxChars );
        for ( $i = 0; $i < $num; ++$i )
        {
            $len = strlen( $text );
            $offs = mt_rand( 0, $len - 1 );
            if ( $offs == 0 )
            {
                $tmp = $text[$offs];
                $text[$offs] = $text[$len - 1];
                $text[$len] = $tmp;
            }
            else
            {
                $delta = -1;
                if ( $text[$offs+$delta] == " " and
                     $offs + 1 < $len )
                    $delta = 1;
                $tmp = $text[$offs];
                $text[$offs] = $text[$offs+$delta];
                $text[$offs+$delta] = $tmp;
            }
        }
        return $text;
    }
279099
public static function intersectLeft($string1, $string2, $encoding = null)
    {
        $encoding = $encoding === null ? mb_internal_encoding() : $encoding;
        $maxLength = min(Mbstring::strlen($string1, $encoding), Mbstring::strlen($string2, $encoding));
        $intersect = '';

        for ($i = 0; $i <= $maxLength; $i++) {
            $char = Mbstring::substr($string1, $i, 1, $encoding);

            if ($char === Mbstring::substr($string2, $i, 1, $encoding)) {
                $intersect .= $char;
            } else {
                break;
            }
        }

        return $intersect;
    }
1269693
private function compareBcStrings(string $a, string $b) : int
    {
        $a_len = strlen($a);
        $b_len = strlen($b);

        if ($a_len > $b_len) {
            return -1;
        }

        if ($a_len < $b_len) {
            return 1;
        }

        $a_len = strlen(str_replace(['*', '?'], '', $a));
        $b_len = strlen(str_replace(['*', '?'], '', $b));

        if ($a_len > $b_len) {
            return -1;
        }

        if ($a_len < $b_len) {
            return 1;
        }

        return 0;
    }
928367
public static int similarityChars(String txt1, String txt2) {
        int sim = similar_char(txt1, txt1.length(), txt2, txt2.length());
        return sim;
    }
422983
public static boolean nullSafeEquals(String text1, String text2) {
        if (text1 == null || text2 == null) {
            return false;
        } else {
            return text1.equals(text2);
        }
    }
582600
@Override
    public double similarScore(String text1, String text2) {
        if(LOGGER.isDebugEnabled()) {
            LOGGER.debug("文本1：");
            LOGGER.debug("\t" + text1);
            LOGGER.debug("文本2：");
            LOGGER.debug("\t" + text2);
        }
        if(text1 == null || text2 == null){
            //只要有一个文本为null，规定相似度分值为0，表示完全不相等
            return 0.0;
        }
        //分词
        List<Word> words1 = seg(text1);
        List<Word> words2 = seg(text2);
        //计算相似度分值
        return similarScore(words1, words2);
    }
67988
public static function getDistanceBetweenXPaths($xpath1, $xpath2)
    {
        if (strlen($xpath1) > strlen($xpath2))
        {
            $diff = substr($xpath1, strlen($xpath2));
        }
        else
        {
            $diff = substr($xpath2, strlen($xpath1));
        }

        return count(explode('/', $diff));
    }
895579
function (letter1, letter2) {
  var index1 = scale.indexOf(letter1);
  var index2 = scale.indexOf(letter2);
  var distance = mod(index2 - index1, scale.length) + 1;

  assert(index1 > -1);
  assert(index2 > -1);
  assert(distance > 0 && distance <= scale.length);

  return distance;
}