Files
html/api/ambre-regex-test.php
2026-04-21 16:50:02 +02:00

25 lines
1.2 KiB
PHP

<?php
header("Content-Type: application/json");
// Run node -e to test the regex with real JS semantics
$regex = '/g[eéèê]n[eéèê]re?\\s+(?:un|une|des|le|la)?\\s*(pdf|pptx?|powerpoint|docx?|word|excel|xlsx?|pr[eéèê]sentation|document|tableau|sch[eéèê]ma|mermaid|diagramme|image)|ecri[srt]?\\s+(?:le|du|un)?\\s*code|traduis?\\s+(?:ce\\s+texte|en)?\\s*(anglais|francais|espagnol|allemand|italien|portugais|arabe|chinois|japonais|english|spanish|french|german|italian|portuguese|arabic|chinese|japanese)/i';
$tests = [
"Genere un PDF sur: demo",
"Genere un document Word sur: strategie",
"Genere une presentation sur: pitch",
"Genere un schema mermaid pour: flow",
"Genere une image: logo",
"Ecris le code python pour: fibonacci",
"Traduis en anglais: bonjour",
"ping",
];
$results = [];
foreach ($tests as $t) {
// Escape the test string for shell
$js = "console.log(JSON.stringify({q: \"" . addcslashes($t, "\"\\") . "\", match: $regex.test(\"" . addcslashes($t, "\"\\") . "\")}));";
$out = @shell_exec("node -e \"$js\" 2>&1");
$results[] = ["query"=>$t, "node_out"=>trim($out)];
}
echo json_encode($results, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE);