jclic 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/README.md +5 -7
  2. package/dist-node/jclic-node.js +14157 -0
  3. package/dist-node/jclic-node.umd.cjs +530 -0
  4. package/package.json +38 -26
  5. package/.vscode/launch.json +0 -33
  6. package/.vscode/settings.json +0 -13
  7. package/CHANGELOG.md +0 -664
  8. package/TRANSLATIONS.md +0 -11
  9. package/build-locales.mjs +0 -82
  10. package/dist/jclic-node.js +0 -31678
  11. package/dist/jclic-node.js.map +0 -1
  12. package/dist/jclic.components.LICENSE +0 -2254
  13. package/dist/jclic.min.js +0 -27
  14. package/dist/jclic.min.js.map +0 -1
  15. package/eslint.config.mjs +0 -31
  16. package/jsdoc.config.js +0 -71
  17. package/locales/ar.po +0 -244
  18. package/locales/ast.po +0 -246
  19. package/locales/bs.po +0 -247
  20. package/locales/ca.po +0 -248
  21. package/locales/ca_ES@valencia.po +0 -248
  22. package/locales/cs.po +0 -244
  23. package/locales/da.po +0 -244
  24. package/locales/de.po +0 -246
  25. package/locales/el.po +0 -244
  26. package/locales/es.po +0 -248
  27. package/locales/eu.po +0 -244
  28. package/locales/fr.po +0 -244
  29. package/locales/gl.po +0 -244
  30. package/locales/he.po +0 -244
  31. package/locales/hr.po +0 -245
  32. package/locales/it.po +0 -246
  33. package/locales/ja.po +0 -242
  34. package/locales/jclic.js.pot +0 -241
  35. package/locales/nb_NO.po +0 -244
  36. package/locales/nl.po +0 -244
  37. package/locales/pl.po +0 -244
  38. package/locales/pt.po +0 -244
  39. package/locales/pt_BR.po +0 -248
  40. package/locales/ro.po +0 -248
  41. package/locales/ru.po +0 -245
  42. package/locales/ta.po +0 -244
  43. package/locales/tr.po +0 -246
  44. package/locales/uk.po +0 -247
  45. package/locales/vec.po +0 -244
  46. package/locales/zh_TW.po +0 -246
  47. package/patches/po2json+1.0.0-beta-3.patch +0 -12
  48. package/src/AWT.js +0 -2067
  49. package/src/Activity.js +0 -1311
  50. package/src/Deps.js +0 -232
  51. package/src/GlobalData.js +0 -5
  52. package/src/JClic.js +0 -196
  53. package/src/JClicPlayer.js +0 -1308
  54. package/src/PlayerHistory.js +0 -305
  55. package/src/Utils.js +0 -1355
  56. package/src/activities/associations/ComplexAssociation.js +0 -321
  57. package/src/activities/associations/SimpleAssociation.js +0 -519
  58. package/src/activities/memory/MemoryGame.js +0 -423
  59. package/src/activities/panels/Explore.js +0 -349
  60. package/src/activities/panels/Identify.js +0 -356
  61. package/src/activities/panels/InformationScreen.js +0 -262
  62. package/src/activities/panels/Menu.js +0 -209
  63. package/src/activities/panels/icons/ico00.png +0 -0
  64. package/src/activities/panels/icons/ico01.png +0 -0
  65. package/src/activities/panels/icons/ico02.png +0 -0
  66. package/src/activities/panels/icons/ico03.png +0 -0
  67. package/src/activities/panels/icons/icofolder.png +0 -0
  68. package/src/activities/puzzles/DoublePuzzle.js +0 -424
  69. package/src/activities/puzzles/ExchangePuzzle.js +0 -374
  70. package/src/activities/puzzles/HolePuzzle.js +0 -360
  71. package/src/activities/text/Complete.js +0 -127
  72. package/src/activities/text/Evaluator.js +0 -534
  73. package/src/activities/text/FillInBlanks.js +0 -426
  74. package/src/activities/text/IdentifyText.js +0 -253
  75. package/src/activities/text/OrderText.js +0 -421
  76. package/src/activities/text/TextActivityBase.js +0 -557
  77. package/src/activities/text/TextActivityDocument.js +0 -658
  78. package/src/activities/text/WrittenAnswer.js +0 -557
  79. package/src/activities/textGrid/CrossWord.js +0 -565
  80. package/src/activities/textGrid/WordSearch.js +0 -458
  81. package/src/activities/textGrid/icons/hIcon.svg +0 -3
  82. package/src/activities/textGrid/icons/vIcon.svg +0 -3
  83. package/src/automation/AutoContentProvider.js +0 -182
  84. package/src/automation/arith/Arith.js +0 -864
  85. package/src/bags/ActivitySequence.js +0 -318
  86. package/src/bags/ActivitySequenceElement.js +0 -161
  87. package/src/bags/ActivitySequenceJump.js +0 -140
  88. package/src/bags/ConditionalJumpInfo.js +0 -113
  89. package/src/bags/JumpInfo.js +0 -136
  90. package/src/bags/MediaBag.js +0 -215
  91. package/src/bags/MediaBagElement.js +0 -516
  92. package/src/boxes/AbstractBox.js +0 -699
  93. package/src/boxes/ActiveBagContent.js +0 -494
  94. package/src/boxes/ActiveBox.js +0 -810
  95. package/src/boxes/ActiveBoxBag.js +0 -357
  96. package/src/boxes/ActiveBoxContent.js +0 -484
  97. package/src/boxes/ActiveBoxGrid.js +0 -179
  98. package/src/boxes/BoxBag.js +0 -500
  99. package/src/boxes/BoxBase.js +0 -398
  100. package/src/boxes/BoxConnector.js +0 -325
  101. package/src/boxes/TextGrid.js +0 -887
  102. package/src/boxes/TextGridContent.js +0 -215
  103. package/src/init-jsdom.js +0 -65
  104. package/src/jclic-node.js +0 -219
  105. package/src/media/ActiveMediaBag.js +0 -145
  106. package/src/media/ActiveMediaPlayer.js +0 -297
  107. package/src/media/AudioBuffer.js +0 -219
  108. package/src/media/EventSounds.js +0 -169
  109. package/src/media/EventSoundsElement.js +0 -155
  110. package/src/media/MediaContent.js +0 -328
  111. package/src/media/MidiAudioPlayer.js +0 -254
  112. package/src/media/icons/audio.svg +0 -3
  113. package/src/media/icons/generic.svg +0 -3
  114. package/src/media/icons/mic.svg +0 -3
  115. package/src/media/icons/movie.svg +0 -3
  116. package/src/media/icons/music.svg +0 -3
  117. package/src/media/icons/url.svg +0 -3
  118. package/src/media/sounds/actionError.mp3 +0 -0
  119. package/src/media/sounds/actionOk.mp3 +0 -0
  120. package/src/media/sounds/click.mp3 +0 -0
  121. package/src/media/sounds/finishedError.mp3 +0 -0
  122. package/src/media/sounds/finishedOk.mp3 +0 -0
  123. package/src/media/sounds/start.mp3 +0 -0
  124. package/src/project/JClicProject.js +0 -282
  125. package/src/project/ProjectSettings.js +0 -273
  126. package/src/report/ActionReg.js +0 -123
  127. package/src/report/ActivityReg.js +0 -271
  128. package/src/report/EncryptMin.js +0 -210
  129. package/src/report/Reporter.js +0 -727
  130. package/src/report/SCORM.js +0 -272
  131. package/src/report/SequenceReg.js +0 -275
  132. package/src/report/SessionReg.js +0 -340
  133. package/src/report/SessionStorageReporter.js +0 -131
  134. package/src/report/TCPReporter.js +0 -628
  135. package/src/shapers/ClassicJigSaw.js +0 -138
  136. package/src/shapers/Holes.js +0 -77
  137. package/src/shapers/JigSaw.js +0 -161
  138. package/src/shapers/Rectangular.js +0 -78
  139. package/src/shapers/Shaper.js +0 -386
  140. package/src/shapers/TriangularJigSaw.js +0 -121
  141. package/src/skins/BlueSkin.js +0 -80
  142. package/src/skins/Counter.js +0 -152
  143. package/src/skins/CustomSkin.js +0 -412
  144. package/src/skins/DefaultSkin.js +0 -376
  145. package/src/skins/EmptySkin.js +0 -82
  146. package/src/skins/GreenSkin.js +0 -94
  147. package/src/skins/MiniSkin.js +0 -130
  148. package/src/skins/OrangeSkin.js +0 -78
  149. package/src/skins/SimpleSkin.js +0 -92
  150. package/src/skins/Skin.js +0 -1021
  151. package/src/skins/assets/actionsIcon.svg +0 -3
  152. package/src/skins/assets/appLogo.svg +0 -8
  153. package/src/skins/assets/basic.css +0 -41
  154. package/src/skins/assets/closeDialogIcon.svg +0 -3
  155. package/src/skins/assets/closeIcon.svg +0 -3
  156. package/src/skins/assets/copyIcon.svg +0 -3
  157. package/src/skins/assets/fullScreenExitIcon.svg +0 -3
  158. package/src/skins/assets/fullScreenIcon.svg +0 -3
  159. package/src/skins/assets/infoIcon.svg +0 -3
  160. package/src/skins/assets/main.css +0 -43
  161. package/src/skins/assets/mainHalf.css +0 -23
  162. package/src/skins/assets/mainTwoThirds.css +0 -23
  163. package/src/skins/assets/mini.css +0 -15
  164. package/src/skins/assets/nextIcon.svg +0 -3
  165. package/src/skins/assets/okDialogIcon.svg +0 -3
  166. package/src/skins/assets/prevIcon.svg +0 -3
  167. package/src/skins/assets/reports.css +0 -156
  168. package/src/skins/assets/reportsIcon.svg +0 -3
  169. package/src/skins/assets/scoreIcon.svg +0 -3
  170. package/src/skins/assets/simple.css +0 -16
  171. package/src/skins/assets/simpleHalf.css +0 -11
  172. package/src/skins/assets/simpleTwoThirds.css +0 -11
  173. package/src/skins/assets/timeIcon.svg +0 -4
  174. package/src/skins/assets/waitAnim.css +0 -54
  175. package/src/skins/assets/waitImgBig.svg +0 -3
  176. package/src/skins/assets/waitImgSmall.svg +0 -3
  177. package/webpack.config.mjs +0 -169
@@ -1,534 +0,0 @@
1
- /**
2
- * File : activities/text/Evaluator.js
3
- * Created : 14/04/2015
4
- * By : Francesc Busquets <francesc@gmail.com>
5
- *
6
- * JClic.js
7
- * An HTML5 player of JClic activities
8
- * https://projectestac.github.io/jclic.js
9
- *
10
- * @source https://github.com/projectestac/jclic.js
11
- *
12
- * @license EUPL-1.2
13
- * @licstart
14
- * (c) 2000-2020 Educational Telematic Network of Catalonia (XTEC)
15
- *
16
- * Licensed under the EUPL, Version 1.1 or -as soon they will be approved by
17
- * the European Commission- subsequent versions of the EUPL (the "Licence");
18
- * You may not use this work except in compliance with the Licence.
19
- *
20
- * You may obtain a copy of the Licence at:
21
- * https://joinup.ec.europa.eu/software/page/eupl
22
- *
23
- * Unless required by applicable law or agreed to in writing, software
24
- * distributed under the Licence is distributed on an "AS IS" basis, WITHOUT
25
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
26
- * Licence for the specific language governing permissions and limitations
27
- * under the Licence.
28
- * @licend
29
- * @module
30
- */
31
-
32
- /* global window */
33
-
34
- import { log, attrForEach, getBoolean, setAttr, getAttr } from '../../Utils.js';
35
-
36
- /**
37
- * This class and its derivatives {@link module:activities/text/Evaluator.BasicEvaluator BasicEvaluator} and
38
- * {@link module:activities/text/Evaluator.ComplexEvaluator ComplexEvaluator} are used to evaluate the answers written by the final users
39
- * in text activities.
40
- */
41
- export class Evaluator {
42
- /**
43
- * Evaluator constructor
44
- * @param {string} className - The class name of this evaluator.
45
- */
46
- constructor(className) {
47
- this.className = className;
48
- this.collator = (window.Intl && window.Intl.Collator) ?
49
- new window.Intl.Collator() :
50
- { compare: (a, b) => this.checkCase ? a === b : a.toUpperCase() === b.toUpperCase() };
51
- }
52
-
53
- /**
54
- * Factory constructor that returns a specific type of {@link module:activities/text/Evaluator.Evaluator Evaluator} based on the `class`
55
- * attribute declared in the $xml element.
56
- * @param {external:jQuery} $xml - The XML element to be parsed.
57
- * @returns {module:activities/text/Evaluator.Evaluator}
58
- */
59
- static getEvaluator($xml) {
60
- let ev = null;
61
- if ($xml) {
62
- const className = $xml.attr('class');
63
- const cl = Evaluator.CLASSES[className];
64
- if (cl) {
65
- ev = new cl(className);
66
- ev.setProperties($xml);
67
- } else
68
- log('error', `Unknown evaluator class: "${className}"`);
69
- }
70
- return ev;
71
- }
72
-
73
- /**
74
- * Loads the object settings from a specific JQuery XML element
75
- * @param {external:jQuery} $xml - The jQuery XML element to parse
76
- */
77
- setProperties($xml) {
78
- attrForEach($xml.get(0).attributes, (name, value) => {
79
- switch (name) {
80
- case 'class':
81
- this.className = value;
82
- break;
83
- case 'checkCase':
84
- case 'checkAccents':
85
- case 'checkPunctuation':
86
- case 'checkDoubleSpaces':
87
- case 'detail':
88
- this[name] = getBoolean(value);
89
- break;
90
- case 'checkSteps':
91
- case 'checkScope':
92
- this[name] = Number(value);
93
- break;
94
- }
95
- });
96
- return this;
97
- }
98
-
99
- /**
100
- * Builds a new Evaluator, based on the properties specified in a data object
101
- * @param {object} data - The data object to be parsed
102
- * @returns {module:activities/text/Evaluator.Evaluator}
103
- */
104
- static factory(data) {
105
- const cl = Evaluator.CLASSES[data.className];
106
- if (cl) {
107
- const result = new cl(data.className);
108
- return setAttr(result, data, [
109
- 'className',
110
- 'checkCase', 'checkAccents', 'checkPunctuation', 'checkDoubleSpaces', 'detail',
111
- 'checkSteps', 'checkScope',
112
- ]);
113
- }
114
- return null;
115
- }
116
-
117
- /**
118
- * Gets a object with the basic attributes needed to rebuild this instance excluding functions,
119
- * parent references, constants and also attributes retaining the default value.
120
- * The resulting object is commonly usued to serialize elements in JSON format.
121
- * @returns {object} - The resulting object, with minimal attrributes
122
- */
123
- getAttributes() {
124
- return getAttr(this, [
125
- 'className',
126
- 'checkCase', 'checkAccents', 'checkPunctuation', 'checkDoubleSpaces', 'detail',
127
- 'checkSteps', 'checkScope',
128
- ]);
129
- }
130
-
131
- /**
132
- * Initializes this evaluator
133
- * @param {string[]} _locales - An array of valid locales, to be used by Intl.Collator
134
- */
135
- init(_locales) {
136
- this.initiated = true;
137
- }
138
-
139
- /**
140
- * Checks the given text against a set of valid matches
141
- * @param {string} text - The text to be checked
142
- * @param {string|string[]} match - The valid expression or expressions with which to compare.
143
- * @returns {boolean} - `true` if the checked expression is valid, `false` otherwise.
144
- */
145
- checkText(text, match) {
146
- if (match instanceof Array)
147
- return match.some(m => this._checkText(text, m));
148
- else if (match)
149
- return this._checkText(text, match);
150
- else
151
- return false;
152
- }
153
-
154
- /**
155
- * Abstract method to be implemented in subclasses.
156
- * Performs the validation of a string against a single match.
157
- * @param {string} _text - The text to be checked
158
- * @param {string} _match - A valid expression with which to compare.
159
- * @returns {boolean} - `true` when the two expressions can be considered equivalent.
160
- */
161
- _checkText(_text, _match) {
162
- return false;
163
- }
164
-
165
- /**
166
- * Evaluates the given text against a set of valid matches, returning an array of flags useful
167
- * to indicate where the mistakes are located.
168
- * @param {string} text - The text to be checked
169
- * @param {string|string[]} match - The valid expression or expressions with which to compare.
170
- * @returns {number[]} - An array of flags (one number for character) indicating whether each
171
- * position is erroneous or ok.
172
- */
173
- evalText(text, match) {
174
- if (!(match instanceof Array))
175
- match = [match];
176
- return this._evalText(text, match);
177
- }
178
-
179
- /**
180
- * Abstract method to be implemented in subclasses.
181
- * Performs the evaluation of a string against an array of valid matches, returning an array of
182
- * flags useful to indicate where the mistakes are located.
183
- * @param {string} _text - The text to be checked
184
- * @param {string} _match - A valid expression with which to compare.
185
- * @returns {number[]} - An array of flags (one number for character) indicating whether each
186
- * position is erroneous or OK.
187
- */
188
- _evalText(_text, _match) {
189
- return [];
190
- }
191
-
192
- /**
193
- * Checks if the given array of flags (usually returned by `evalText`) can be considered as a
194
- * valid or erroneous answer.
195
- * @param {number[]} flags
196
- * @returns {boolean} - `true` when there is at least one flag and all flags are 0 (meaning no error).
197
- */
198
- isOk(flags) {
199
- return flags && flags.length > 0 && !flags.some(f => f !== 0);
200
- }
201
- }
202
-
203
- Object.assign(Evaluator.prototype, {
204
- /**
205
- * The type of evaluator.
206
- * @name module:activities/text/Evaluator.Evaluator#className
207
- * @type {string} */
208
- className: null,
209
- /**
210
- * Whether this evaluator has been initialized or not.
211
- * @name module:activities/text/Evaluator.Evaluator#initiated
212
- * @type {boolean} */
213
- initiated: false,
214
- /**
215
- * The Intl.Collator object used to compare strings, when available.
216
- * @name module:activities/text/Evaluator.Evaluator#collator
217
- * @type {external:Collator} */
218
- collator: null,
219
- /**
220
- * Whether uppercase and lowercase expressions must be considered equivalent or not.
221
- * @name module:activities/text/Evaluator.Evaluator#checkcase
222
- * @type {boolean} */
223
- checkCase: false,
224
- });
225
-
226
- /**
227
- * A basic evaluator that just compares texts, without looking for possible coincidences of text
228
- * fragments once erroneous characters removed.
229
- * @extends module:activities/text/Evaluator.Evaluator
230
- */
231
- export class BasicEvaluator extends Evaluator {
232
- /**
233
- * BasicEvaluator constructor
234
- * @param {string} className - The class name of this evaluator.
235
- */
236
- constructor(className) {
237
- super(className);
238
- }
239
-
240
- /**
241
- * Initializes the {@link module:activities/text/Evaluator.Evaluator#collator collator}.
242
- * @override
243
- * @param {string[]} locales - An array of valid locales to be used by the Inlt.Collator object
244
- */
245
- init(locales) {
246
- // Call `init` method on ancestor
247
- super.init([locales]);
248
-
249
- // Get canonical locales
250
- if (window.Intl && window.Intl.Collator) {
251
- this.collator = new window.Intl.Collator(locales, {
252
- sensitivity: this.checkAccents ? this.checkCase ? 'case' : 'accent' : 'base',
253
- ignorePunctuation: !this.checkPunctuation
254
- });
255
- }
256
- }
257
-
258
- /**
259
- * Performs the validation of a string against a single match.
260
- * @override
261
- * @param {string} text - The text to be checked
262
- * @param {string} match - A valid expression with which to compare.
263
- * @returns {boolean} - `true` when the two expressions can be considered equivalent.
264
- */
265
- _checkText(text, match) {
266
- return this.collator.compare(this.getClearedText(text), this.getClearedText(match)) === 0;
267
- }
268
-
269
- /**
270
- * Performs the evaluation of a string against an array of valid matches, returning an array of
271
- * flags useful to indicate where the mistakes are located.
272
- * In BasicEvaluator, all characters are just marked as 1 (error) or 0 (OK). See
273
- * {@link module:activities/text/Evaluator.ComplexEvaluator ComplexEvaluator} for more detailed analysis of answers.
274
- * @override
275
- * @param {string} text - The text to be checked
276
- * @param {string} match - A valid expression with which to compare.
277
- * @returns {number[]} - An array of flags (one number for character) indicating whether each
278
- * position is erroneous or OK.
279
- */
280
- _evalText(text, match) {
281
- return Array(text.length).fill(this._checkText(text, match[0]) ? 0 : 1);
282
- }
283
-
284
- /**
285
- * Removes double spaces and erroneous characters from a given text expression.
286
- * @param {string} src - The text to be processed.
287
- * @param {boolean[]} skipped - An array of boolean indicating which characters should be removed
288
- * from the string.
289
- * @returns {string}
290
- */
291
- getClearedText(src, skipped) {
292
- if (this.checkPunctuation && this.checkDoubleSpaces)
293
- return src;
294
-
295
- if (!skipped)
296
- skipped = Array(src.length).fill(false);
297
-
298
- let sb = '';
299
- for (let i = 0, wasSpace = false; i < src.length; i++) {
300
- const ch = src.charAt(i);
301
- if (this.PUNCTUATION.indexOf(ch) >= 0 && !this.checkPunctuation) {
302
- if (!wasSpace)
303
- sb += ' ';
304
- else
305
- skipped[i] = true;
306
- wasSpace = true;
307
- } else if (ch === ' ') {
308
- if (this.checkDoubleSpaces || !wasSpace)
309
- sb += ch;
310
- else
311
- skipped[i] = true;
312
- wasSpace = true;
313
- } else {
314
- wasSpace = false;
315
- sb += ch;
316
- }
317
- }
318
- return sb;
319
- }
320
- }
321
-
322
- Object.assign(BasicEvaluator.prototype, {
323
- /**
324
- * Whether accented letters must be considered equivalent or not.
325
- * @name module:activities/text/Evaluator.BasicEvaluator#checkAccents
326
- * @type {boolean} */
327
- checkAccents: true,
328
- /**
329
- * Whether to check or not dots, commas and other punctuation marks when comparing texts.
330
- * @name module:activities/text/Evaluator.BasicEvaluator#checkPunctuation
331
- * @type {boolean} */
332
- checkPunctuation: true,
333
- /**
334
- * Whether to check or not the extra spaces added between words.
335
- * @name module:activities/text/Evaluator.BasicEvaluator#checkDoubleSpaces
336
- * @type {boolean} */
337
- checkDoubleSpaces: false,
338
- /**
339
- * String containing all the characters considered as punctuation marks (currently ".,;:")
340
- * @name module:activities/text/Evaluator.BasicEvaluator#PUNCTUATION
341
- * @type {string} */
342
- PUNCTUATION: '.,;:',
343
- });
344
-
345
- /**
346
- * ComplexEvaluator acts like {@link module:activities/text/Evaluator.BasicEvaluator BasicEvaluator}, but providing feedback about
347
- * the location of mistakes on the user's answer.
348
- * @extends module:activities/text/Evaluator.BasicEvaluator
349
- */
350
- export class ComplexEvaluator extends BasicEvaluator {
351
- /**
352
- * ComplexEvaluator constructor
353
- * @param {string} className - The class name of this evaluator.
354
- */
355
- constructor(className) {
356
- super(className);
357
- }
358
-
359
- /**
360
- * Performs the evaluation of a string against an array of valid matches, returning an array of
361
- * flags useful to indicate where the mistakes are located.
362
- * In BasicEvaluator, all characters are just marked as 1 (error) or 0 (OK). See
363
- * {@link module:activities/text/Evaluator.ComplexEvaluator ComplexEvaluator} for more detailed analysis of answers.
364
- * @override
365
- * @param {string} text - The text to be checked
366
- * @param {string} match - A valid expression with which to compare.
367
- * @returns {number[]} - An array of flags (one number for character) indicating whether each
368
- * position is erroneous or OK.
369
- */
370
- _evalText(text, match) {
371
-
372
- if (!this.detail)
373
- return super._evalText(text, match);
374
-
375
- const
376
- skipped = Array(text.length).fill(false),
377
- sText = this.getClearedText(text, skipped),
378
- numChecks = Array(match.length),
379
- flags = Array(match.length),
380
- returnFlags = Array(text.length);
381
- let
382
- maxCheck = -1,
383
- maxCheckIndex = -1;
384
-
385
- for (let i = 0; i < match.length; i++) {
386
- flags[i] = Array(text.length).fill(0);
387
- const ok = this.compareSegment(sText, sText.length, match[i], match[i].length, flags[i], false);
388
- numChecks[i] = this.countFlagsOk(flags[i]);
389
- if (ok) {
390
- maxCheckIndex = i;
391
- maxCheck = numChecks[i];
392
- }
393
- }
394
-
395
- if (maxCheckIndex === -1) {
396
- for (let i = 0; i < match.length; i++) {
397
- if (numChecks[i] > maxCheck) {
398
- maxCheck = numChecks[i];
399
- maxCheckIndex = i;
400
- }
401
- }
402
- }
403
-
404
- for (let i = 0, k = 0; i < text.length; i++)
405
- returnFlags[i] = skipped[i] ? 0 : flags[maxCheckIndex][k++];
406
-
407
- return returnFlags;
408
- }
409
-
410
- /**
411
- * Counts the number of flags on the provided array that are zero.
412
- * @param {number[]} flags
413
- * @returns {number}
414
- */
415
- countFlagsOk(flags) {
416
- return flags.reduce((n, v) => v == 0 ? ++n : n, 0);
417
- }
418
-
419
- /**
420
- * Compares two segments of text.
421
- * This function should make recursive calls.
422
- * @param {string} src - Text to be compared
423
- * @param {number} ls - Offset in `src` where to start the comparison
424
- * @param {string} ok - Text to match against.
425
- * @param {number} lok - Offset in `ok` where to start the comparison.
426
- * @param {number[]} attr - Array of integers that will be filled with information about the
427
- * validity or error of each character in `src`.
428
- * @param {boolean} iterate - When `true`, the segment will be iterated looking for other
429
- * coincident fragments.
430
- * @returns {boolean} - `true` if the comparison was valid.
431
- */
432
- compareSegment(src, ls, ok, lok, attr, iterate) {
433
- let
434
- is = 0,
435
- iok = 0,
436
- lastIs = 0,
437
- lastiok = true,
438
- result = true,
439
- chs = '',
440
- chok = '';
441
-
442
- if (ls === 0 || lok === 0 || src === null || ok === null)
443
- return false;
444
-
445
- for (; is < ls; is++, iok++) {
446
- chs = src.charAt(is);
447
- lastIs = is;
448
- if (iok >= 0 && iok < lok)
449
- chok = ok.charAt(iok);
450
- else
451
- chok = 0;
452
- if (this.collator.compare(chs, chok) === 0) {
453
- attr[is] = 0;
454
- lastiok = true;
455
- } else {
456
- result = false;
457
- attr[is] = 1;
458
- if (!iterate && lastiok && chok !== 0 && this.checkSteps > 0 && this.checkScope > 0) {
459
- const
460
- lbloc = 2 * this.checkSteps + 1,
461
- itcoinc = [];
462
- let i = 0, j = 0;
463
- for (; j < lbloc; j++) {
464
- itcoinc[j] = 0;
465
- i = iok + Math.floor((j + 1) / 2) * ((j & 1) !== 0 ? 1 : -1);
466
- if (i >= lok)
467
- continue;
468
- const is2 = i < 0 ? is - i : is;
469
- if (is2 >= ls)
470
- continue;
471
- const
472
- ls2 = Math.min(ls - is2, this.checkScope),
473
- iok2 = i < 0 ? 0 : i,
474
- lok2 = Math.min(lok - iok2, this.checkScope),
475
- flags2 = Array(src.length - is2).fill(0),
476
- result2 = this.compareSegment(src.substring(is2), ls2, ok.substring(iok2), lok2, flags2, true);
477
- itcoinc[j] = this.countFlagsOk(flags2);
478
- if (result2)
479
- break;
480
- }
481
- if (j === lbloc) {
482
- let jmax = this.checkSteps;
483
- for (j = 0; j < lbloc; j++)
484
- if (itcoinc[j] > itcoinc[jmax])
485
- jmax = j;
486
- i = iok + Math.floor((jmax + 1) / 2) * ((jmax & 1) !== 0 ? 1 : -1);
487
- }
488
- iok = i;
489
- lastiok = false;
490
- }
491
- }
492
- }
493
- if (iok !== lok) {
494
- result = false;
495
- attr[lastIs] = 1;
496
- }
497
- return result;
498
- }
499
- }
500
-
501
- Object.assign(ComplexEvaluator.prototype, {
502
- /**
503
- * Whether to detail or not the location of errors found on the analyzed text.
504
- * @name module:activities/text/Evaluator.ComplexEvaluator#detail
505
- * @type {boolean} */
506
- detail: true,
507
- /**
508
- * Number of times to repeat the evaluation process if an error is found, eliminating in each
509
- * cycle the extra characters that caused the error.
510
- * @name module:activities/text/Evaluator.ComplexEvaluator#checkSteps
511
- * @type {number} */
512
- checkSteps: 3,
513
- /**
514
- * When an eror is detected in the analyzed expression, this variable indicates the number of
515
- * characters the checking pointer will be moved forward and back looking for a coincident
516
- * expression.
517
- *
518
- * For example, comparing the answer "_one lardzy dog_" with the correct answer "_one lazy dog_"
519
- * will detect an error at position 6 (an "r" instead of "z"). If `checkSteps` is set to 2 or
520
- * greater, the "_zy dog_" expression at position 8 will be found and evaluated as valid, while
521
- * a value of 1 or less will not found any coincident expression beyond the error position, thus
522
- * evaluating all the remaining sentence as erroneous.
523
- * @name module:activities/text/Evaluator.ComplexEvaluator#checkScope
524
- * @type {number} */
525
- checkScope: 6,
526
- });
527
-
528
- // List of known Evaluator classes
529
- Evaluator.CLASSES = {
530
- '@BasicEvaluator': BasicEvaluator,
531
- '@ComplexEvaluator': ComplexEvaluator
532
- };
533
-
534
- export default Evaluator;