test 4345
This commit is contained in:
parent
6f7616823f
commit
2b0a93c39f
4 changed files with 104 additions and 84 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import Detector from "./Detector.js";
|
||||
import compromise from 'fr-compromise';
|
||||
import conj from 'conjugation-fr';
|
||||
import { toInfinitive } from "../data.js"; // check path ??
|
||||
import { toInfinitive } from "../data/index.js";
|
||||
import { cleanMessageContent } from "../utils/strings.js";
|
||||
|
||||
/*check the pronoun / subject of the question to answer properly by conjugating
|
||||
|
|
@ -12,9 +12,7 @@ const suffixes = [
|
|||
', mon gars',
|
||||
', mec',
|
||||
", je crois",
|
||||
'',
|
||||
'',
|
||||
''
|
||||
'', '', ''
|
||||
];
|
||||
|
||||
export default class withPronounDetector extends Detector {
|
||||
|
|
@ -22,9 +20,11 @@ export default class withPronounDetector extends Detector {
|
|||
const reference = await message.fetchReference().catch(() => null);
|
||||
const isSelfTarget = (reference && reference.author.id === message.client.user?.id) ?? false;
|
||||
|
||||
const compromiseMatch = compromise(cleanMessageContent(message).toLowerCase()).match('(#Pronoun|ça|ca|tu) (#Verb|fait) #Infinitive? quoi [<suffix>!Verb{0,3}]$');
|
||||
const text = cleanMessageContent(message).toLowerCase();
|
||||
const compromiseMatch = compromise(text).match('(#Pronoun|ça|ca|tu) (#Verb|fait) #Infinitive? quoi [<suffix>!Verb{0,3}]$');
|
||||
|
||||
if (compromiseMatch == null || compromiseMatch.length === 0) {
|
||||
// console.log("DEBUG: Pas de structure 'Sujet + Verbe + Quoi' détectée.");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -37,26 +37,41 @@ export default class withPronounDetector extends Detector {
|
|||
|
||||
const replySuffix = compromiseMatch.groups('suffix')?.text().trim() ?? '';
|
||||
|
||||
if (result == null) {
|
||||
if (result == null) return '';
|
||||
|
||||
const verbTerm = result.terms[1];
|
||||
if (!verbTerm) {
|
||||
console.log("DEBUG: Structure détectée mais verbe introuvable.");
|
||||
return '';
|
||||
}
|
||||
|
||||
// warning : result.terms[1] can't exist if the compromise structure change
|
||||
const verbTerm = result.terms[1];
|
||||
if (!verbTerm) return '';
|
||||
|
||||
const verbInfinitive = toInfinitive[verbTerm.text];
|
||||
if (!verbInfinitive) return ''; // safety check if the verb is in the list
|
||||
const verbText = verbTerm.text.toLowerCase();
|
||||
|
||||
// Debug: On vérifie ce qu'il cherche
|
||||
const verbInfinitive = toInfinitive[verbText];
|
||||
|
||||
if (!verbInfinitive) {
|
||||
console.log(`DEBUG: ÉCHEC - Le verbe '${verbText}' n'est pas dans toInfinitive.json`);
|
||||
return ''; //drop et initialise perroquet (suffixDetector ou basicDetector)
|
||||
}
|
||||
|
||||
let conjugated = '';
|
||||
const tenseTag = verbTerm.tags.find(t => t.endsWith('Tense')) ?? 'Present';
|
||||
|
||||
const getConjugation = (pronoun) => {
|
||||
const tenseData = conj.findTense(verbInfinitive, tenseTag);
|
||||
return tenseData.find(c => c.pronoun === pronoun)?.verb;
|
||||
try {
|
||||
const tenseData = conj.findTense(verbInfinitive, tenseTag);
|
||||
return tenseData.find(c => c.pronoun === pronoun)?.verb;
|
||||
} catch (e) {
|
||||
console.error(`DEBUG: Erreur conjugation-fr pour ${verbInfinitive}:`, e);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
switch (result.terms[0].text.toLowerCase()) {
|
||||
// Logique d'inversion des pronoms
|
||||
const subjectText = result.terms[0].text.toLowerCase();
|
||||
|
||||
switch (subjectText) {
|
||||
case 'je':
|
||||
case "j'":
|
||||
conjugated = `tu ${getConjugation('tu')}`;
|
||||
|
|
@ -70,16 +85,13 @@ export default class withPronounDetector extends Detector {
|
|||
}
|
||||
break;
|
||||
case 'il':
|
||||
conjugated = `il ${getConjugation('il')}`;
|
||||
case 'on':
|
||||
case 'ça':
|
||||
case 'ca':
|
||||
conjugated = `${subjectText} ${getConjugation('il')}`;
|
||||
break;
|
||||
case 'elle':
|
||||
conjugated = `elle ${getConjugation('il')}`; // 'elle' utilise la conjugaison 'il' dans cette lib souvent
|
||||
break;
|
||||
case 'on':
|
||||
conjugated = `on ${getConjugation('il')}`;
|
||||
break;
|
||||
case 'ça':
|
||||
conjugated = `ça ${getConjugation('il')}`;
|
||||
conjugated = `elle ${getConjugation('il')}`;
|
||||
break;
|
||||
case 'nous':
|
||||
conjugated = `nous ${getConjugation('nous')}`;
|
||||
|
|
@ -94,8 +106,13 @@ export default class withPronounDetector extends Detector {
|
|||
conjugated = `elles ${getConjugation('ils')}`;
|
||||
break;
|
||||
default:
|
||||
conjugated = '';
|
||||
break;
|
||||
console.log(`DEBUG: Pronom '${subjectText}' non géré.`);
|
||||
return '';
|
||||
}
|
||||
|
||||
if (!conjugated || conjugated.includes('undefined')) {
|
||||
console.log(`DEBUG: Échec conjugaison finale.`);
|
||||
return '';
|
||||
}
|
||||
|
||||
const infinitiveVerb = result.terms.find(t => t.tags.includes('Infinitive'))?.text ?? '';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue