src/Comparisons/JaroWinklerComparison.php
/**
     * Return the similarity using the JaroWinkler algorithm
     * @param string $text1
     * @param string $text2
     * @return real
     */
Return the similarity using the JaroWinkler algorithm
@param string $text1
@param string $text2
@return real
Return the similarity using the JaroWinkler algorithm @param string $text1 @param string $text2 @return real
public function similarity($text1, $text2)
    {
        if($text1 === $text2) {
            return 1.0;
        }
        if (strlen($text1) > strlen($text2)) {
            $tmp = $text1;
            $text1 = $text2;
            $text2 = $tmp;
        }
        $strLen1 = strlen($text1);
        $strLen2 = strlen($text2);
        $maxDistance = (int)$strLen2 / 2;
        $commonCounter = 0; 
        $transpositionCounter = 0; 
        $prevPosition = -1;
        for ($index = 0; $index < $strLen1; $index++) 
        {
            $char = $text1[$index];
            $jindex = max(0, $index - $maxDistance);
            while($jindex < min($strLen2, $index + $maxDistance))
            {
                if ($char === $text2[$jindex]) {
                    $commonCounter++; 
                    if ($prevPosition != -1 && $jindex < $prevPosition) {
                        $transpositionCounter++; 
                    }
                  $prevPosition = $jindex;
                  break;
                }
                $jindex++;
            }
        }
        if($commonCounter === 0) {
            return 0.0;
        }
        $score = (
                ($commonCounter / $strLen1) +
                ($commonCounter / $strLen2) +
               (($commonCounter - $transpositionCounter) / $commonCounter)) / 3.0;
        $prefixLength = 0; 
        $last = min($this->minPrefixLength, $strLen1);        
        while($prefixLength < $last && $text1[$prefixLength] == $text2[$prefixLength])
        {
            $prefixLength++;
        }
        return $score + (($prefixLength * (1 - $score)) / 10);     
    }
public function similarity ( $ text1 , $ text2 ) { if ( $ text1 === $ text2 ) { return 1.0 ; } if ( strlen ( $ text1 ) > strlen ( $ text2 ) ) { $ tmp = $ text1 ; $ text1 = $ text2 ; $ text2 = $ tmp ; } $ strLen1 = strlen ( $ text1 ) ; $ strLen2 = strlen ( $ text2 ) ; $ maxDistance = ( int ) $ strLen2 / 2 ; $ commonCounter = 0 ; $ transpositionCounter = 0 ; $ prevPosition = - 1 ; for ( $ index = 0 ; $ index < $ strLen1 ; $ index ++ ) { $ char = $ text1 [ $ index ] ; $ jindex = max ( 0 , $ index - $ maxDistance ) ; while ( $ jindex < min ( $ strLen2 , $ index + $ maxDistance ) ) { if ( $ char === $ text2 [ $ jindex ] ) { $ commonCounter ++ ; if ( $ prevPosition != - 1 && $ jindex < $ prevPosition ) { $ transpositionCounter ++ ; } $ prevPosition = $ jindex ; break ; } $ jindex ++ ; } } if ( $ commonCounter === 0 ) { return 0.0 ; } $ score = ( ( $ commonCounter / $ strLen1 ) + ( $ commonCounter / $ strLen2 ) + ( ( $ commonCounter - $ transpositionCounter ) / $ commonCounter ) ) / 3.0 ; $ prefixLength = 0 ; $ last = min ( $ this -> minPrefixLength , $ strLen1 ) ; while ( $ prefixLength < $ last && $ text1 [ $ prefixLength ] == $ text2 [ $ prefixLength ] ) { $ prefixLength ++ ; } return $ score + ( ( $ prefixLength * ( 1 - $ score ) ) / 10 ) ; }
Return the similarity using the JaroWinkler algorithm
 @param string $text1
 @param string $text2
 @return real
Return the similarity using the JaroWinkler algorithm @param string $text1 @param string $text2 @return real
// ensure that s1 is shorter than or same length as s2 // count of common characters // count of transpositions // init inner loop  // common char found // no common characters between strings // first compute the score //init values // length of prefix