cii-text-analysis/Lib/Model/Prediction.php
Jéremy Munsch f68d2ac333
premier poc
2026-02-11 08:24:04 +01:00

65 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace Classifier\Lib\Model;
use Classifier\Lib\Enum\MessageType;
class Prediction
{
// FIXME : php8.1 readonly props
/**
* Label final (avec gestion du doute)
* @var MessageType
*/
public $decision;
/**
* Label le plus probable selon le modèle entrainé (avant application du seuil de doute)
* @var MessageType
*/
public $machineDecision;
/**
* Méthode qui a conduit à la décision
* @var string
*/
public $method;
/**
* Score (0.0 à 1.0)
* @var float
*/
public $confidence;
/**
* Détail complet
* @var array<string,float>
*/
public $scores;
public function __construct(
MessageType $decision,
MessageType $machineDecision,
string $method,
float $confidence,
array $scores = []
) {
$this->decision = $decision;
$this->machineDecision = $machineDecision;
$this->method = $method;
$this->confidence = $confidence;
$this->scores = $scores;
foreach ($scores as $label => $score) {
if (empty($label) || !is_string($label)) {
throw new \InvalidArgumentException("Label de score invalide : " . var_export($label, true));
}
if ((!is_float($score) && !is_int($score)) || $score < 0.0 || $score > 1.0) {
throw new \InvalidArgumentException("Score de label '$label' invalide : " . var_export($score, true));
}
}
}
}