67 lines
2.2 KiB
PHP
67 lines
2.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
use Classifier\Lib\Discriminant\AlertAnalyzer;
|
||
|
|
use Classifier\Lib\Discriminant\BlackList;
|
||
|
|
use Classifier\Lib\Discriminant\WhiteList;
|
||
|
|
use Classifier\Lib\Enum\MessageType;
|
||
|
|
use Classifier\Lib\MessageClassifier;
|
||
|
|
use Classifier\Lib\Model\MessageQualifier;
|
||
|
|
use Classifier\Lib\Utils\StringCleaner;
|
||
|
|
|
||
|
|
require_once __DIR__ . '/vendor/autoload.php';
|
||
|
|
require_once __DIR__ . '/Lib/index.php';
|
||
|
|
|
||
|
|
$message = <<<'EOT'
|
||
|
|
SAN NICOLAO SEISME RESSENTI: ABRITEZ VOUS SOUS UN MEUBLE SOLIDE OU DANS UN ESPACE DEGAGE A L'EXTERIEUR INFO FB/INSTA + PREF2B+SIS2B
|
||
|
|
|
||
|
|
EOT;
|
||
|
|
|
||
|
|
// Seuil pour le dictionnaire
|
||
|
|
$threshold = 100;
|
||
|
|
|
||
|
|
$modelPath = __DIR__ . '/model.rbx';
|
||
|
|
|
||
|
|
// Stop words : Mots à ignorer pour le nettoyage des messages
|
||
|
|
$stopWords = require __DIR__ . '/data/stopwords.php';
|
||
|
|
$strCleaner = new StringCleaner($stopWords);
|
||
|
|
|
||
|
|
// Liste noire : Priorité absolue pour tuer les faux positifs
|
||
|
|
$blackList = new BlackList(require __DIR__ . '/data/blacklist.php', $strCleaner);
|
||
|
|
|
||
|
|
// Liste blanche : Mots clés avec poids pour le dictionnaire fuzzy
|
||
|
|
$whiteList = new WhiteList(require __DIR__ . '/data/whitelist.php', $strCleaner);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* ! TYPE D'ALERTE PAR DEFAUT EN CAS DE DOUTE
|
||
|
|
*/
|
||
|
|
$defaultAlertType = MessageType::ALERTE();
|
||
|
|
|
||
|
|
$analyzer = new AlertAnalyzer($whiteList, $blackList, $strCleaner, $threshold);
|
||
|
|
$qualifier = new MessageQualifier($modelPath);
|
||
|
|
|
||
|
|
// * Combinaison des deux approches Dictionnaire et machine learning
|
||
|
|
$master = new MessageClassifier(
|
||
|
|
$analyzer,
|
||
|
|
$qualifier,
|
||
|
|
$defaultAlertType
|
||
|
|
);
|
||
|
|
|
||
|
|
try {
|
||
|
|
$result = $master->classify($message);
|
||
|
|
|
||
|
|
echo "--- RÉSULTAT DE L'ANALYSE ---\n";
|
||
|
|
echo "Message : " . substr($message, 0, 100) . "...\n";
|
||
|
|
echo "Décision : " . $result->decision->getValue() . "\n";
|
||
|
|
echo "Machine : " . ($result->machineDecision ? $result->machineDecision->getValue() : 'N/A') . "\n";
|
||
|
|
echo "Méthode : " . $result->method->getValue() . "\n";
|
||
|
|
echo "Confiance: " . round($result->confidence * 100, 2) . "%\n";
|
||
|
|
|
||
|
|
echo "Détails : " . implode(', ', array_map(function (object $d) {
|
||
|
|
return $d->word . " (" . round($d->score * 100, 2) . "%)";
|
||
|
|
}, $result->getDetails())) . "\n";
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
echo "Erreur système : " . $e->getMessage();
|
||
|
|
}
|