-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadability_scores_calculator.html
More file actions
559 lines (506 loc) · 21 KB
/
readability_scores_calculator.html
File metadata and controls
559 lines (506 loc) · 21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Calculateur d'indices de lisibilité</title>
<style>
body {
margin: 0;
padding: 0;
height: auto;
width: auto;
background: #1d1f21;
color: #cdcdcd;
font-family: monospace;
overflow-x: hidden;
}
.main {
margin-left: 15%;
margin-right: 15%;
margin-top: 65px;
margin-bottom: 0px;
font-size: 15px;
font-family: "Menlo", "Meslo LG", monospace;
font-weight: 400;
line-height: 1.725;
text-rendering: geometricPrecision;
color: #c9cacc;
}
.icon {
width: 30px;
}
a {
text-decoration: underline;
color: #c9cacc;
}
h1 {
color: #2bbc8a;
text-align: center;
}
h2 {
color: #2bbc8a;
text-align: center;
}
h3 {
color: #2bbc8a;
text-align: left;
}
li {
padding-bottom: 20px;
}
* {
box-sizing: border-box;
}
.column {
float: left;
width: 50%;
padding: 10px;
}
.row:after {
content: "";
display: table;
clear: both;
}
@media screen and (max-width: 600px) {
.column {
width: 100%;
}
}
table {
border-collapse: collapse;
width: 100%;
padding-left: 10px;
padding-right: 10px;
}
th {
text-align: center;
color: #1d1f21;
background-color: #2bbc8a;
padding-top: 10px;
border: solid;
border-color: #cdcdcd;
border-width: thin;
}
td {
text-align: center;
padding-bottom: 10px;
padding-top: 10px;
border: solid;
border-color: #cdcdcd;
border-width: thin;
}
</style>
</head>
<body>
<div class="main">
<header>
<h1>📚 Indices de lisibilité pour textes français 🇫🇷</h1>
</header>
<br>
<p>
L'objectif de ce programme est d'abord de permettre, grâce à l'usage d'expressions régulières, l'analyse
d'un texte brut fourni
par l'utilisateur pour en extraire plusieurs variables : nombre de caractères, de voyelles, de digrammes, de
trigrammes,
de syllabes graphiques, de mots, de mots de plus de six caractères, de mots de plus de trois syllabes
graphiques, de phrases.
</p>
<p>
En se fondant sur cette analyse du texte, le programme permet ensuite le calcul et l'inteprétation de six
indices de lisibilité :
LIX, RIX, Automated Readability Index (ARI), Gunning Fog index, Coleman-Liau index, Flesch-Kincaid Grade
Level (FKGL),
Simple Measure of Gobbledygook index (SMOG).
</p>
<p>
Ces indices ont pour la plupart été inventés pour mesurer la lisibilité de textes anglais, à l'exception de
l'indice suédois LIX. Ce dernier
est sans doute le plus efficace pour donner une mesure juste de la difficulté d'un texte français.
</p>
<p>Dans tous les cas, un texte sera considéré comme étant aisément lisible par un lecteur moyen s'il relève d'un
niveau de difficulté "🟡 Intermédiaire" (cela correspond
au niveau d'un élève de 3<sup>e</sup>) ou inférieur ("🟢 Facile", "⚪️ Très facile").
</p>
<br>
<div class="row">
<div class="column">
<p style="align-items: center;text-align: center">
<textarea name="textarea" id="content" cols="30" rows="10"
placeholder="Copiez-collez votre texte à analyser ici..."></textarea><br>
<input type="button" id="submitbutton" onclick="scoreTextArea()" value="Analyser">
</p>
</div>
<div class="column">
<p style="align-items: center;text-align: center">...ou ajoutez un fichier en texte brut (.txt).<br><br>
<input type="file" accept=".txt" onchange="scoreTextFile()" /><br />
</p>
</div>
</div>
<br>
<div class="row">
<div class="column">
<table>
<tr>
<th>Élément</th>
<th>Nombre</th>
</tr>
<tr>
<td>Caractères</td>
<td class="caracteres">0</td>
</tr>
<tr>
<td>Voyelles</td>
<td class="voyelles">0</td>
</tr>
<tr>
<td>Digrammes</td>
<td class="digrammes">0</td>
</tr>
<tr>
<td>Trigrammes</td>
<td class="trigrammes">0</td>
</tr>
<tr>
<td>Syllabes graphiques</td>
<td class="syllabes">0</td>
</tr>
<tr>
<td>Mots</td>
<td class="mots">0</td>
</tr>
<tr>
<td>Mots >6 caractères</td>
<td class="motslongs">0</td>
</tr>
<tr>
<td>Mots >2 syllabes graphiques</td>
<td class="motspolysyllabiques">0</td>
</tr>
<tr>
<td>Phrases</td>
<td class="phrases">0</td>
</tr>
</table>
</div>
<div class="column">
<table>
<tr>
<th>Indices</th>
<th>Scores</th>
<th>Niveau de difficulté</th>
</tr>
<tr>
<td>LIX</td>
<td class="lixscore">0</td>
<td class="lixdiff">-</td>
</tr>
<tr>
<td>RIX</td>
<td class="rixscore">0</td>
<td class="rixdiff">-</td>
</tr>
<tr>
<td>Flesch-Kincaid</td>
<td class="fkglscore">0</td>
<td class="fkglscorediff">-</td>
</tr>
<tr>
<td>Gunning Fog</td>
<td class="gunningscore">0</td>
<td class="gunningscorediff">-</td>
</tr>
<tr>
<td>SMOG</td>
<td class="smogscore">0</td>
<td class="smogscorediff">-</td>
</tr>
<tr>
<td>Coleman-Liau</td>
<td class="coleman_liauscore">0</td>
<td class="coleman_liauscorediff">-</td>
</tr>
<tr>
<td>ARI</td>
<td class="ariscore">0</td>
<td class="ariscorediff">-</td>
</tr>
</table>
</div>
</div>
<br>
<h3>Bibliographie indicative</h3>
<ul>
<li>Benoît J.-P. (1986). "<a href="https://doi.org/10.3406/prati.1986.1409">Revue critique des formules de
lisibilité (60 ans de formules de lisibilité : qu'en reste-t-il ?)</a>".</li>
<li>Conquet A., Richaudeau F. (1973). "<a href="https://doi.org/10.3406/colan.1973.3978">Cinq méthodes de
mesure de la lisibilité</a>".</li>
<li>De Landsheere, G. (1963). "<a href="http://www.jstor.org/stable/40659295">Pour une application des tests
de lisibilité de Flesch à la langue française</a>"</li>
<li>Henry G. (1980). "<a href="https://doi.org/10.3406/colan.1980.1364">Lisibilité et compréhension</a>".
</li>
<li>Labasse B. (1999). "<a href="https://doi.org/10.3406/colan.1999.2951">La lisibilité rédactionnelle :
fondements et perspectives</a>".</li>
<li>Le Maux, J. (2015). "<a href="https://doi.org/10.3917/rfla.202.0099">La lisibilité de l’information
financière</a>".</li>
<li>Mesnager J. (1989). "<a href="https://doi.org/10.3406/colan.1989.1081"> Lisibilité des textes pour
enfants : un nouvel outil ?</a></li>
<li>Richaudeau F. (1976). "<a href="https://doi.org/10.3406/colan.1976.4293">Faut-il brûler les formules de
lisibilité ?</a>".</li>
</ul>
<p style="color:#2bbc8a;text-align: center;"> Voir le projet sur
<a href="https://github.com/filkat34/readability-scores" target="_blank"> <img
src="https://skillicons.dev/icons?i=github" alt="Github" width="32" height="32" /></a>
</p>
</div>
</body>
<Script>
// Text analysis functions with Regex :
function nbCaracteres(str) {
str = str.normalize("NFD").replace(/[\u0300-\u036f]/gi, "");
let regex = /(\w)/gi;
return str.match(regex).length;
}
function nbVoyelles(str) {
str = str.normalize("NFD").replace(/[\u0300-\u036f]/gi, "");
let regex = /[aeiouœ]/gi;
let voyelles = str.match(regex);
if (voyelles === null) {
voyelles = 0;
} else {
voyelles = str.match(regex).length;
}
return voyelles;
}
function nbDigrammes(str) {
str = str.normalize("NFD").replace(/[\u0300-\u036f]/gi, "");
let regex = /(au)|(eu)|(ou)|(oi)|(œu)|(ei)|(ai)|(ee)|(ue)|(ui)|(ua)/gi;
let digrammes = str.match(regex);
if (digrammes === null) {
digrammes = 0;
} else {
digrammes = str.match(regex).length;
}
return digrammes;
}
function nbTrigrammes(str) {
str = str.normalize("NFD").replace(/[\u0300-\u036f]/gi, "");
let regex = /(eau)|(oue)|(aie)/gi;
let trigrammes = str.match(regex)
if (trigrammes === null) {
trigrammes = 0;
} else {
trigrammes = str.match(regex).length;
}
return trigrammes;
}
function nbSyllabesGraphiques(str) {
return nbVoyelles(str) - (nbDigrammes(str) + nbTrigrammes(str));
}
function nbMots(str) {
str = str.normalize("NFD").replace(/[\u0300-\u036f]/gi, "");
let regex = /(\w+)/gi;
let mots = str.match(regex)
if (mots === null) {
mots = 0;
} else {
mots = str.match(regex).length;
}
return mots;
}
function nbMotsPolysyllabiques(str) {
let punctuation = /[.,?!;:]/g;
str = str.normalize("NFD").replace(/[\u0300-\u036f]/gi, "").replace(punctuation, "").replace(" ", " ");
let mots = str.split(' ');
let motsPolysyllabiques = 0;
for (const mot in mots) {
if (nbSyllabesGraphiques(mots[mot]) >= 3) {
motsPolysyllabiques++;
}
}
return motsPolysyllabiques;
}
function nbMotsLongs(str) {
str = str.normalize("NFD").replace(/[\u0300-\u036f]/gi, "");
let regex = /(\w{7,})/g;
let motsLongs = str.match(regex);
if (motsLongs === null) {
motsLongs = 0;
} else {
motsLongs = str.match(regex).length;
}
return motsLongs;
}
function nbPhrases(str) {
let regex = /..\.|!|\?/gi;
let phrases = str.match(regex);
if (phrases === 0) {
phrases = 1;
} else {
phrases = str.match(regex).length;
}
return phrases;
}
// Readability formulas functions :
function scoreLix(str) {
return nbMots(str) / nbPhrases(str) + 100 * (nbMotsLongs(str) / nbMots(str));
}
function scoreRix(str) {
return nbMotsLongs(str) / nbPhrases(str);
}
function scoreFkgl(str) {
return 0.39 * (nbMots(str) / nbPhrases(str)) + 11.8 * (nbSyllabesGraphiques(str) / nbMots(str)) - 15.59;
}
function scoreGunningFog(str) {
return 0.4 * (nbMots(str) / nbPhrases(str) + 100 * (nbMotsPolysyllabiques(str) / nbMots(str)));
}
function scoreSMOG(str) {
return 1.043 * Math.sqrt((nbMotsPolysyllabiques(str) * (30 / nbPhrases(str)))) + 3.1291;
}
function scoreColemanLiau(str) {
return 0.0588 * ((nbCaracteres(str) / nbMots(str)) * 100) - 0.296 * ((nbPhrases(str) / nbMots(str)) * 100) - 15.8;
}
function scoreAri(str) {
return 4.71 * (nbCaracteres(str) / nbMots(str)) + 0.5 * (nbMots(str) / nbPhrases(str)) - 21.43;
}
// Readability scores analysis function
function scoreAnalysis(formula, score) {
let formula_scales = [['lix', 59, 50, 40, 30],
['rix', 7.1, 5.3, 2.9, 1.8],
['fkgl', 15, 12, 5, 1],
['gunning', 17, 13, 7, 1],
['smog', 14, 12, 7, 1],
['ari', 15, 9, 5, 1],
['coleman_liau', 15, 9, 5, 1]
]
for (let column in formula_scales) {
for (let row in formula_scales) {
if (formula_scales[column][row] === formula) {
if (score > formula_scales[column][1]) {
return "🔴 Très difficile";
}
if (score > formula_scales[column][2]) {
return "🟠 Difficile";
}
if (score > formula_scales[column][3]) {
return "🟡 Intermédiaire";
}
if (score > formula_scales[column][4]) {
return "🟢 Facile";
}
return "⚪️ Très facile";
}
}
}
}
// Events functions
function scoreTextFile() {
const caracteres = document.querySelector(".caracteres");
const voyelles = document.querySelector(".voyelles");
const digrammes = document.querySelector(".digrammes");
const trigrammes = document.querySelector(".trigrammes");
const syllabes = document.querySelector(".syllabes");
const mots = document.querySelector(".mots");
const motslongs = document.querySelector(".motslongs");
const motspolysyllabiques = document.querySelector(".motspolysyllabiques");
const phrases = document.querySelector(".phrases");
const lix = document.querySelector(".lixscore");
const rix = document.querySelector(".rixscore");
const fkgl = document.querySelector(".fkglscore");
const gunningFog = document.querySelector(".gunningscore");
const smog = document.querySelector(".smogscore");
const colemanliau = document.querySelector(".coleman_liauscore");
const ari = document.querySelector(".ariscore");
const lixdiff = document.querySelector(".lixdiff");
const rixdiff = document.querySelector(".rixdiff");
const fkgldiff = document.querySelector(".fkglscorediff");
const gunningFogdiff = document.querySelector(".gunningscorediff");
const smogdiff = document.querySelector(".smogscorediff");
const colemanliaudiff = document.querySelector(".coleman_liauscorediff");
const aridiff = document.querySelector(".ariscorediff");
const [file] = document.querySelector("input[type=file]").files;
const reader = new FileReader();
reader.addEventListener(
"load",
() => {
caracteres.innerText = nbCaracteres(reader.result);
voyelles.innerText = nbVoyelles(reader.result);
digrammes.innerText = nbDigrammes(reader.result);
trigrammes.innerText = nbTrigrammes(reader.result);
syllabes.innerText = nbSyllabesGraphiques(reader.result);
mots.innerText = nbMots(reader.result);
motslongs.innerText = nbMotsLongs(reader.result);
motspolysyllabiques.innerText = nbMotsPolysyllabiques(reader.result);
phrases.innerText = nbPhrases(reader.result);
lix.innerText = scoreLix(reader.result).toFixed(2);
rix.innerText = scoreRix(reader.result).toFixed(2);
fkgl.innerText = scoreFkgl(reader.result).toFixed(2);
gunningFog.innerText = scoreGunningFog(reader.result).toFixed(2);
smog.innerText = scoreSMOG(reader.result).toFixed(2);
colemanliau.innerText = scoreColemanLiau(reader.result).toFixed(2);
ari.innerText = scoreAri(reader.result).toFixed(2);
lixdiff.innerText = scoreAnalysis('lix', scoreLix(reader.result));
rixdiff.innerText = scoreAnalysis('rix', scoreRix(reader.result));
fkgldiff.innerText = scoreAnalysis('fkgl', scoreFkgl(reader.result));
gunningFogdiff.innerText = scoreAnalysis('gunning', scoreGunningFog(reader.result));
smogdiff.innerText = scoreAnalysis('smog', scoreSMOG(reader.result));
colemanliaudiff.innerText = scoreAnalysis('coleman_liau', scoreColemanLiau(reader.result));
aridiff.innerText = scoreAnalysis('ari', scoreAri(reader.result));
},
false,
);
if (file) {
reader.readAsText(file);
}
}
function scoreTextArea() {
const caracteres = document.querySelector(".caracteres");
const voyelles = document.querySelector(".voyelles");
const digrammes = document.querySelector(".digrammes");
const trigrammes = document.querySelector(".trigrammes");
const syllabes = document.querySelector(".syllabes");
const mots = document.querySelector(".mots");
const motslongs = document.querySelector(".motslongs");
const motspolysyllabiques = document.querySelector(".motspolysyllabiques");
const phrases = document.querySelector(".phrases");
const lix = document.querySelector(".lixscore");
const rix = document.querySelector(".rixscore");
const fkgl = document.querySelector(".fkglscore");
const gunningFog = document.querySelector(".gunningscore");
const smog = document.querySelector(".smogscore");
const colemanliau = document.querySelector(".coleman_liauscore");
const ari = document.querySelector(".ariscore");
const inputText = document.getElementById("content").value;
const lixdiff = document.querySelector(".lixdiff");
const rixdiff = document.querySelector(".rixdiff");
const fkgldiff = document.querySelector(".fkglscorediff");
const gunningFogdiff = document.querySelector(".gunningscorediff");
const smogdiff = document.querySelector(".smogscorediff");
const colemanliaudiff = document.querySelector(".coleman_liauscorediff");
const aridiff = document.querySelector(".ariscorediff");
caracteres.innerText = nbCaracteres(inputText);
voyelles.innerText = nbVoyelles(inputText);
digrammes.innerText = nbDigrammes(inputText);
trigrammes.innerText = nbTrigrammes(inputText);
syllabes.innerText = nbSyllabesGraphiques(inputText);
mots.innerText = nbMots(inputText);
motslongs.innerText = nbMotsLongs(inputText);
motspolysyllabiques.innerText = nbMotsPolysyllabiques(inputText);
phrases.innerText = nbPhrases(inputText);
lix.innerText = scoreLix(inputText).toFixed(2);
rix.innerText = scoreRix(inputText).toFixed(2);
fkgl.innerText = scoreFkgl(inputText).toFixed(2);
gunningFog.innerText = scoreGunningFog(inputText).toFixed(2);
smog.innerText = scoreSMOG(inputText).toFixed(2);
colemanliau.innerText = scoreColemanLiau(inputText).toFixed(2);
ari.innerText = scoreAri(inputText).toFixed(2);
lixdiff.innerText = scoreAnalysis('lix', scoreLix(inputText));
rixdiff.innerText = scoreAnalysis('rix', scoreRix(inputText));
fkgldiff.innerText = scoreAnalysis('fkgl', scoreFkgl(inputText));
gunningFogdiff.innerText = scoreAnalysis('gunning', scoreGunningFog(inputText));
smogdiff.innerText = scoreAnalysis('smog', scoreSMOG(inputText));
colemanliaudiff.innerText = scoreAnalysis('coleman_liau', scoreColemanLiau(inputText));
aridiff.innerText = scoreAnalysis('ari', scoreAri(inputText));
}
</Script>
</html>