21 $similarity = $this->simpleStringComparator->getSimilarity( $a, $b );
22 if ( $similarity > 0.9 ) {
26 $similarity = $this->
levenshtein( $a, $b, mb_strlen( $a ), mb_strlen( $b ) );
27 if ( $similarity === -1 ) {
32 $maxLength = max( strlen( $a ), strlen( $b ) );
33 return ( $maxLength - $similarity ) / $maxLength;
40 public function levenshtein(
string $str1,
string $str2,
int $length1,
int $length2 ): int {
41 if ( $length1 === 0 ) {
45 if ( $length2 === 0 ) {
49 if ( $str1 === $str2 ) {
53 $byteLength1 = strlen( $str1 );
54 $byteLength2 = strlen( $str2 );
55 if ( $byteLength1 === $length1 && $byteLength1 <= 255
56 && $byteLength2 === $length2 && $byteLength2 <= 255
61 $prevRow = range( 0, $length2 );
62 for ( $i = 0; $i < $length1; $i++ ) {
64 $currentRow[0] = $i + 1;
65 $c1 = mb_substr( $str1, $i, 1 );
66 for ( $j = 0; $j < $length2; $j++ ) {
67 $c2 = mb_substr( $str2, $j, 1 );
68 $insertions = $prevRow[$j + 1] + 1;
69 $deletions = $currentRow[$j] + 1;
70 $substitutions = $prevRow[$j] + ( ( $c1 !== $c2 ) ? 1 : 0 );
71 $currentRow[] = min( $insertions, $deletions, $substitutions );
73 $prevRow = $currentRow;
76 return $prevRow[$length2];