Пример #1
0
function compareComplex($v1, $v2)
{
    global $weightLevenshtein, $weightMetaphone, $weightSoundex;
    if (!strlen($v1)) {
        echo "<br>" . $v1 . " - " . $v2;
    }
    $l = 100 - levenshtein($v1, $v2) / strlen($v1) * 100;
    $m = compareMetaphone($v1, $v2);
    $s = compareSoundex($v1, $v2);
    #echo $v1." - ".$v2. " - $l - $m - $s - " . ($m*2/3 + $l*2/3*1/3 + $s*1/3*1/3) . "<br>";
    return $m * $weightMetaphone + $l * $weightLevenshtein + $s * $weightSoundex;
}
Пример #2
0
<?php

require 'libs/misc.php';
$weightMetaphone = 2 / 3;
$weightLevenshtein = 2 / 3 * 1 / 3;
$weightSoundex = 1 / 3 * 1 / 3;
$matrix = array();
if ($_GET['w1'] && $_GET['w2']) {
    $matrix[] = array($_GET['w2'], $_GET['w2']);
} else {
    $matrix[] = array('Maria Kirilenko', 'Masha Kirilenko');
    $matrix[] = array('Andrei Neculau', 'Andrei N.');
    $matrix[] = array('Neculau', 'N.');
    $matrix[] = array('Andrei Neculau', 'Neculau Andrei');
    $matrix[] = array('Luminita', 'Luminița');
}
function noDiacriticsParse(&$item)
{
    $item = noDiacritics($item);
}
array_walk_recursive($matrix, 'noDiacriticsParse');
$result = array();
foreach ($matrix as $row) {
    list($w1, $w2) = $row;
    $result[] = array('w1' => $w1, 'w2' => $w2, 'levenshtein' => levenshtein($w1, $w2), 'metaphone' => metaphone($w1) . " - " . metaphone($w2), 'metaphone_compare' => compareMetaphone($w1, $w2), 'soundex' => soundex($w1) . " - " . soundex($w2), 'soundex_compare' => compareSoundex($w1, $w2), 'compare' => compareComplexMulti(explode(' ', $w1), explode(' ', $w2)));
}
print_a($result);