int(10)
    [1]=>
    int(8)
    [2]=>
    int(-12)
  }
}

*/
function printMatrix($n, $matrix)
{
    $sum1 = 0;
    $sum2 = 0;
    if ($n >= 1 && $n <= 100) {
        for ($i = 0; $i < $n + 1; $i++) {
            for ($j = 0; $j < 1; $j++) {
                $sum1 += $matrix[$i][$i - 1];
            }
            for ($j = 0; $j < 1; $j++) {
                $sum2 += $matrix[$i][$n - $i];
            }
            echo $sum1;
        }
    }
    if ($sum1 >= -100 && $sum1 <= 100 || $sum2 >= -100 && $sum2 <= 100) {
        return abs($sum1 - $sum2);
    }
    return false;
}
echo printMatrix($n, $mat);
echo PHP_EOL;
                if ($direction === 2) {
                    // From left to right
                    for ($column = $left; $column <= $right; $column++) {
                        printValue($matrix, $bottom, $column);
                    }
                    $bottom--;
                } else {
                    if ($direction == 3) {
                        // From bottom to top
                        for ($row = $bottom; $row >= $top; $row--) {
                            printValue($matrix, $row, $right);
                        }
                        $right--;
                    }
                }
            }
        }
        $direction = ++$direction % 4;
        // 0,1,2,3,0,...
    }
}
function printValue($matrix, $row, $column)
{
    echo $matrix[$row][$column] . "\t";
}
echo 'Matrix:<br>';
printMatrix($matrix);
echo "<br> Matrix clockwise:<br>";
printMatrixBySpiralClockwise($matrix);
echo "<br><br> Matrix counterclockwise:<br>";
printMatrixBySpiralCounterClockwise($matrix);
Beispiel #3
0
<?php

$index = getIndex();
// print_r($index);
printf("%33s\n", "----- Raw matrix -----");
printMatrix($index);
normalize($index);
newline(3);
printf("%40s\n", "----- Normalized matrix -----");
printMatrix($index);
printf("%s\n\n", "==========================================");
printf("\t*** %s ***\n", "Similarity Score");
print_calculated_score($argv[1], $argv[2], $index['dictionary']);
printf("%s\n", "==========================================");
printf("\t%s\n", "== DEBUG ==");
print_calculated_score('doc1', 'doc2', $index['dictionary']);
print_calculated_score('doc1', 'doc3', $index['dictionary']);
print_calculated_score('doc2', 'doc1', $index['dictionary']);
newline();
function print_calculated_score($docA, $docB, $dict)
{
    $cosine_score = cosineSim($docA, $docB, $dict);
    printf(" -- cos (%s & %s) = %.2f%% [%f]\n", $docA, $docB, $cosine_score, $cosine_score);
}
function printMatrix($index)
{
    /* print docID */
    printf("%10s", 'vocab/doc');
    foreach ($index['docCount'] as $key => $value) {
        printf('%10s ', $key);
    }