Forumindlæg af Joseph Rézeau

Billede af Core developers Billede af Plugin developers Billede af Testers Billede af Translators

Hi fellow developers! I am currently trying to  help an automatic gap deletion to my own version of the multianswer/cloze question type. It's working more or less as expected but in my script which sets a SHORTANSWER "gap" (in fact a SHORTANSWER sub-question) every nth word (at n intervals) I would like my script to skip capitalised words (as is the norm in such cloze tests). The following script does skip capitalised words, but... it also skips the next n words. I know this is due to the "continue" instruction in my script line 17. Any idea how I could modify my script to achieve the result I want?

Interval for gaps set at every 5th word. Original text example:

Once upon a time, many hundreds of years ago, there lived a boy named Dick. He was an orphan and had little in the way of comfort,...

With my script I'm getting this result:

Once upon a time, {1:SA:=many} hundreds of years ago, {1:SA:=there} lived a boy named Dick. He was an orphan {1:SA:=and} had little in the {1:SA:=way} of comfort,...

But I would like to get this result:

Once upon a time, {1:SA:=many} hundreds of years ago, {1:SA:=there} lived a boy named Dick. {1:SA:=He} was an orphan and {1:SA:=had} little in the way {1:SA:=of} comfort,...

and here's the script: (interval == 0)

 1        for (let i = 0; i < paragraphs.length; i++) {
 2          let paraText = $(paragraphs[i]).text();
 3          let words = paraText.split(' ');
 4          // Loop through the words and enclose every 5th or 9th word in SHORTANSWER marker.
 5          for (let index = 0; index < words.length; index++) {
 6            if ((index + 1) % interval === 0) {
 7              // Separate the word from any trailing punctuation
 8              let word = words[index];
 9              let punctuation = '';
10              if (/[.,!?;:]+$/.test(word)) {
11                  punctuation = word.slice(-1); // Get the punctuation mark
12                  word = word.slice(0, -1); // Remove the punctuation from the word
13              }
14              // Check if the word starts with a capital letter
15              if (word && word[0] === word[0].toUpperCase() && /[A-Za-z]/.test(word[0])) {
16                // If the word starts with a capital letter, skip the gapping transformation
17                continue;
18              }
19              // Enclose the word in SHORTANSWER (SA) brackets, then add back the punctuation
20              words[index] = `{1:SA:=${word}}${punctuation}`;
21            }
22          }
23          // Join the words back into a single string
24          let gappedText = words.join(' ');
25          if (gappedText !== '') {
26            $(paragraphs[i]).text(gappedText);
27          }
28        }

N.B. I did try ChatGPT for help but it keeps suggesting alternative scripts which do not work. 😡

Gennemsnitsbedømmelse: -
Billede af Développeurs Billede af Développeurs de plugins Billede af Testeurs Billede af Traducteurs

Tu as écrit "Et j'ai...retenté direct le h5p (bouton noir). Alors que s'est 'il passé sur les 2 activités concernées: Sur les flash card:

image%20%281%29.png  image%20%282%29.png
 
A priori cela s'affiche bien cette fois-ci en hauteur (ouf) donc il ne s'agit pas d'un problème d'ecran mais si je comprend bien d'un paramètre d'affichage. Car comme je le constate sur la seconde capture d'écran, le texte est remis sur lui même ."
 
Tout ça manque encore d'explications! Peux-tu préciser sur quelle plateforme (Windows, Linux, Mac), quel navigateur et quel écran (ordi, tablette, phone) tu affiches ton activité H5P FlashCard? Et merci de faire une copie d'écran de la totalité de ton écran et une autre séparément pour la page "Résultats".
Billede af Développeurs Billede af Développeurs de plugins Billede af Testeurs Billede af Traducteurs

Hello Séverin,

Merci pour ce petit rappel. Je suis en train de peaufiner un "fork" du type de question "multianswer" pour y intégrer mon type de question "regexp". Provisoirement j'ai créé un fichier "fr" contenant les traductions, pour tester les chaînes, mais il faudra que je pense à le supprimer quand mon nouveau plugin sera dans la base officielle des plugins Moodle (et que je ferai la traduction dans AMOS).

Joyeuse rentrée à toi !😊

Gennemsnitsbedømmelse:Utile (2)