[], 'bad' => [], 'ignored' => []]; public function __construct(array $strings) { $this->io = new SymfonyStyle(new ArgvInput(), new ConsoleOutput()); $this->loadExistingData(); $cleaned = array_unique(array_map(function (string $value): string { return preg_replace('/\s+/', ' ', trim(mb_strtolower($value))); }, $strings)); $alreadyDone = array_merge( $this->results['good'], $this->results['bad'], $this->results['ignored'] ); $this->strings = array_diff($cleaned, $alreadyDone); if (!is_dir(self::OUTPUT_DIR)) { mkdir(self::OUTPUT_DIR, 0777, true); } } private function loadExistingData(): void { $files = [ 'good' => self::GOOD_FILE, 'bad' => self::BAD_FILE, 'ignored' => self::IGNORE_FILE ]; foreach ($files as $key => $path) { if (file_exists($path)) { $this->results[$key] = include $path; } } } public function runQuestions(): void { $count = count($this->strings); if ($count === 0) { $this->io->success("Tous les messages fournis sont déjà labellisés ou ignorés !"); return; } $this->io->title('Labellisation des données (Mode Résilient)'); $this->io->note([ "Appuyez sur 'i' pour écarter un message définitivement.", "Appuyez sur 'q' pour sauvegarder et quitter." ]); $this->io->progressStart($count); foreach ($this->strings as $string) { $this->io->newLine(2); $this->io->text("Message : $string"); $answer = $this->io->choice( 'Action pour ce message ?', [ 'y' => 'Oui (Alerte)', 'n' => 'Non (Autre)', 'i' => 'Ignorer (Passer)', 'q' => 'Quitter et Sauvegarder' ], 'n' ); if ($answer === 'q') { $this->io->note("Interruption demandée..."); break; } if ($answer === 'y') { $this->results['good'][] = $string; } elseif ($answer === 'i') { $this->results['ignored'][] = $string; } else { $this->results['bad'][] = $string; } $this->io->progressAdvance(); } $this->io->progressFinish(); $this->saveResults(); $this->io->success("Sauvegarde effectuée. Ignorés : " . count($this->results['ignored'])); } private function saveResults(): void { $this->exportToFile(self::GOOD_FILE, $this->results['good']); $this->exportToFile(self::BAD_FILE, $this->results['bad']); $this->exportToFile(self::IGNORE_FILE, $this->results['ignored']); } private function exportToFile(string $path, array $data): void { sort($data); $content = "