<?php
use Phpml\Classification\SVC;
require 'vendor/autoload.php';
function vetaNaSlova(string $v): array {
    return preg_split('/\s+/', trim($v));
}
function predikuj(string $veta): string {
    $slova = vetaNaSlova($veta);
    $len = count($slova);
    $odpoved = [];
    for ($i = 0; $i < $len; $i++) {
        $path = "models/model_$i.model";

        if (!file_exists($path)) {
            $odpoved[] = "?"; // žiadny model
            continue;
        }
        /** @var SVC $model */
        $model = unserialize(file_get_contents($path));
        $pred = $model->predict([$i]);
        $odpoved[] = $pred;
    }
    return implode(" ", $odpoved);
}
// ====== TEST ======
$otazka = $argv[1] ?? "what is common to think";
echo predikuj($otazka) . "\n";
