commit 15a26cdaf5a213843e275aebc6a6d7c78a63b90e
parent 513de107a308032ab7037870b06c69d19df27e34
Author: AsherMorgan <59518073+AsherMorgan@users.noreply.github.com>
Date: Mon, 27 Jul 2020 15:59:46 -0700
Merge pull request #15 from AsherMorgan/improve-verb-filters
Improve verb filters.
Diffstat:
4 files changed, 162 insertions(+), 131 deletions(-)
diff --git a/README.md b/README.md
@@ -45,7 +45,6 @@ Spanish-Quizzer comes with many vocabulary filters. Not all filters may be used
## Verb Filters
Spanish-Quizzer comes with many verb filters.
- All Conjugations
-- Reverse Conjugations
- All Present Participles
- All Present Tense Conjugations
- All Preterite Tense Conjugations
diff --git a/Scripts/Settings.js b/Scripts/Settings.js
@@ -45,6 +45,7 @@ function AddVerbFilter() {
// Set row ids
clone.children[0].setAttribute("id", `verbFilter-${setId}`);
+ clone.getElementById("verbFilterTense").setAttribute("id", `verbFilterTense-${setId}`);
clone.getElementById("verbFilterType").setAttribute("id", `verbFilterType-${setId}`);
// Add remove button onclick attribute
@@ -115,6 +116,53 @@ function VocabSetChanged(setName) {
+// Update the type filter options
+function VerbTenseChanged(filter) {
+ // Get type filter element
+ let types = document.getElementById(filter.id.replace("verbFilterTense", "verbFilterType"));
+
+ // Enable all types
+ types[0].disabled = false;
+ types[1].disabled = false;
+ types[2].disabled = false;
+ types[3].disabled = false;
+ types[4].disabled = false;
+ types[5].disabled = false;
+
+ // Disable unavailable types
+ switch(filter.value)
+ {
+ case "All Tenses":
+ break;
+ case "Present Participles":
+ types[4].disabled = true; // Orthographic
+ if (types.selectedIndex === 4) {
+ // Deselect unavailable types
+ types.selectedIndex = 0
+ }
+ break;
+ case "Present Tense":
+ types[4].disabled = true; // Orthographic
+ if (types.selectedIndex === 4) {
+ // Deselect unavailable types
+ types.selectedIndex = 0
+ }
+ break;
+ case "Preterite Tense":
+ break;
+ case "Imperfect Tense":
+ types[3].disabled = true; // Stem Changing
+ types[4].disabled = true; // Orthographic
+ if (types.selectedIndex === 3 || types.selectedIndex === 4) {
+ // Deselect unavailable types
+ types.selectedIndex = 0
+ }
+ break;
+ }
+}
+
+
+
// Start a new session
function CreateSession() {
// Get terms and localStorage prefix
@@ -143,22 +191,23 @@ function CreateSession() {
prefix = "vocab-"
}
else if (!document.getElementById("verbSettings").hidden) {
- // Filter and load Sets into Terms
- terms = [];
- for (var i = 0; i < setId; i++)
+ // Get filters
+ let filters = [];
+ for (let i = 0; i < setId; i++)
{
if (document.getElementById(`verbFilter-${i}`))
{
// Get filter information
- var filter = document.getElementById(`verbFilterType-${i}`).value;
-
- // Add filtered set
- terms.push(...ApplyVerbFilter(Sets["Verbs"], filter));
+ let tense = document.getElementById(`verbFilterTense-${i}`).value;
+ let type = document.getElementById(`verbFilterType-${i}`).value;
+
+ // Add filter
+ filters.push({tense: tense, regularity: type});
}
}
- // Shuffle terms
- terms = Shuffle(terms);
+ // Get terms
+ terms = Shuffle(ApplyVerbFilter(Sets["Verbs"], filters));
// Set prefix
prefix = "verb-"
@@ -302,119 +351,102 @@ function ApplyVocabFilter(vocabSet, name) {
-// Filters verbs set given the filter name
-function ApplyVerbFilter(vocabSet, name) {
- // Declare variables
- var io; // Format: [[<output index>, <input index>]]
- var value; // Format: [[<index>, [<values>], exclude?]]
-
- // Get filter
- switch (name) {
- case "All Conjugations":
- io = [[0,3], [0,5], [0,6], [0,7], [0,8], [0,9], [0,11], [0,12], [0,13], [0,14], [0,15], [0,17], [0,18], [0,19], [0,20], [0,21]];
- value = [];
- break;
-
- case "Reverse Conjugations":
- io = [[3,0], [5,0], [6,0], [7,0], [8,0], [9,0], [11,0], [12,0], [13,0], [14,0], [15,0], [17,0], [18,0], [19,0], [20,0], [21,0]];
- value = [];
- break;
-
- case "Present Participles":
- io = [[0,3]];
- value = [];
- break;
-
- case "Present Tense":
- io = [[0,5], [0,6], [0,7], [0,8], [0,9]];
- value = [];
- break;
-
- case "Preterite Tense":
- io = [[0,11], [0,12], [0,13], [0,14], [0,15]]
- value = [];
- break;
-
- case "Imperfect Tense":
- io = [[0,17], [0,18], [0,19], [0,20], [0,21]];
- value = [];
- break;
-
- case "Present Participle non-Regular":
- io = [[0,3]];
- value = [[2, ["Regular"], true]];
- break;
-
- case "Present non-Regular":
- io = [[0,5], [0,6], [0,7], [0,8], [0,9]];
- value = [[4, ["Regular"], true]];
- break;
-
- case "Preterite non-Regular":
- io = [[0,11], [0,12], [0,13], [0,14], [0,15]];
- value = [[10, ["Regular"], true]];
- break;
-
- case "Imperfect non-Regular":
- io = [[0,17], [0,18], [0,19], [0,20], [0,21]];
- value = [[16, ["Regular"], true]];
- break;
-
- case "Present Participle Regular":
- io = [[0,3]];
- value = [[2, ["Regular"], false]];
- break;
-
- case "Present Regular":
- io = [[0,5], [0,6], [0,7], [0,8], [0,9]];
- value = [[4, ["Regular"], false]];
- break;
-
- case "Preterite Regular":
- io = [[0,11], [0,12], [0,13], [0,14], [0,15]];
- value = [[10, ["Regular"], false]];
- break;
-
- case "Imperfect Regular":
- io = [[0,17], [0,18], [0,19], [0,20], [0,21]];
- value = [[16, ["Regular"], false]];
- break;
-
- default:
- io = [];
- value = [];
- break;
+// Filters verbs set given the filter information
+function ApplyVerbFilter(terms, filterInfo) {
+ // Change regularity strings into regex
+ for (config of filterInfo) {
+ switch (config.regularity.toLowerCase()) {
+ case "regular":
+ config.regularity = "Regular";
+ break;
+ case "irregular":
+ config.regularity = "Irregular";
+ break;
+ case "stem-changing":
+ case "stem changing":
+ config.regularity = "Stem.?Changing";
+ break;
+ case "orthographic":
+ config.regularity = "Orthographic";
+ break;
+ case "non-regular":
+ case "non regular":
+ case "nonregular":
+ config.regularity = "Irregular|Stem.?Changing|Orthographic";
+ break;
+ default:
+ case "all":
+ config.regularity = ".*";
+ }
}
- // Filter terms by value
- var vSet = vocabSet.slice(1); // Format: same as vocabSet but without headers
- for (var i = 0; i < value.length; i++) {
- for (var j = 0; j < vSet.length; j++) {
- if (value[i][2]) {
- // Exclude values
- if (value[i][1].includes(vSet[j][value[i][0]])) {
- vSet.splice(j, 1); // Remove item
- j--; // Adjust for the removal of an item
- }
- }
- else {
- // Include values
- if (!value[i][1].includes(vSet[j][value[i][0]])) {
- vSet.splice(j, 1); // Remove item
- j--; // Adjust for the removal of an item
- }
- }
+ // Create filters
+ let filters = []; // Format: [{outputIndex:0, inputIndex:0, filterIndex:0, filterValue:"regex"}]
+ for (config of filterInfo) {
+ switch (config.tense.toLowerCase()) {
+ case "present participle":
+ case "present participles":
+ filters.push({outputIndex:0, inputIndex:3, filterIndex:2, filterValue:config.regularity});
+ break;
+ case "present":
+ case "present tense":
+ filters.push({outputIndex:0, inputIndex:5, filterIndex:4, filterValue:config.regularity});
+ filters.push({outputIndex:0, inputIndex:6, filterIndex:4, filterValue:config.regularity});
+ filters.push({outputIndex:0, inputIndex:7, filterIndex:4, filterValue:config.regularity});
+ filters.push({outputIndex:0, inputIndex:8, filterIndex:4, filterValue:config.regularity});
+ filters.push({outputIndex:0, inputIndex:9, filterIndex:4, filterValue:config.regularity});
+ break;
+ case "preterite":
+ case "preterite tense":
+ filters.push({outputIndex:0, inputIndex:11, filterIndex:10, filterValue:config.regularity});
+ filters.push({outputIndex:0, inputIndex:12, filterIndex:10, filterValue:config.regularity});
+ filters.push({outputIndex:0, inputIndex:13, filterIndex:10, filterValue:config.regularity});
+ filters.push({outputIndex:0, inputIndex:14, filterIndex:10, filterValue:config.regularity});
+ filters.push({outputIndex:0, inputIndex:15, filterIndex:10, filterValue:config.regularity});
+ break;
+ case "imperfect":
+ case "imperfect tense":
+ filters.push({outputIndex:0, inputIndex:17, filterIndex:16, filterValue:config.regularity});
+ filters.push({outputIndex:0, inputIndex:18, filterIndex:16, filterValue:config.regularity});
+ filters.push({outputIndex:0, inputIndex:19, filterIndex:16, filterValue:config.regularity});
+ filters.push({outputIndex:0, inputIndex:20, filterIndex:16, filterValue:config.regularity});
+ filters.push({outputIndex:0, inputIndex:21, filterIndex:16, filterValue:config.regularity});
+ break;
+ default:
+ case "all":
+ filters.push({outputIndex:0, inputIndex:3, filterIndex:2, filterValue:config.regularity});
+
+ filters.push({outputIndex:0, inputIndex:5, filterIndex:4, filterValue:config.regularity});
+ filters.push({outputIndex:0, inputIndex:6, filterIndex:4, filterValue:config.regularity});
+ filters.push({outputIndex:0, inputIndex:7, filterIndex:4, filterValue:config.regularity});
+ filters.push({outputIndex:0, inputIndex:8, filterIndex:4, filterValue:config.regularity});
+ filters.push({outputIndex:0, inputIndex:9, filterIndex:4, filterValue:config.regularity});
+
+ filters.push({outputIndex:0, inputIndex:11, filterIndex:10, filterValue:config.regularity});
+ filters.push({outputIndex:0, inputIndex:12, filterIndex:10, filterValue:config.regularity});
+ filters.push({outputIndex:0, inputIndex:13, filterIndex:10, filterValue:config.regularity});
+ filters.push({outputIndex:0, inputIndex:14, filterIndex:10, filterValue:config.regularity});
+ filters.push({outputIndex:0, inputIndex:15, filterIndex:10, filterValue:config.regularity});
+
+ filters.push({outputIndex:0, inputIndex:17, filterIndex:16, filterValue:config.regularity});
+ filters.push({outputIndex:0, inputIndex:18, filterIndex:16, filterValue:config.regularity});
+ filters.push({outputIndex:0, inputIndex:19, filterIndex:16, filterValue:config.regularity});
+ filters.push({outputIndex:0, inputIndex:20, filterIndex:16, filterValue:config.regularity});
+ filters.push({outputIndex:0, inputIndex:21, filterIndex:16, filterValue:config.regularity});
+ break;
}
}
- // Filter terms by input/output
- var ioSet = []; // Format: [<output type>, <output>, <input type>, <input>]
- for (var i = 0; i < io.length; i++) {
- for (var j = 0; j < vSet.length; j++) {
- ioSet.push([vocabSet[0][io[i][0]], vSet[j][io[i][0]], vocabSet[0][io[i][1]], vSet[j][io[i][1]]]);
+ // Filter terms
+ let results = []; // Format: [[<output label>, <output>, <input label>, <input>]]
+ for (filter of filters) {
+ // Iterate over terms (minus headers)
+ for (term of terms.slice(1)) {
+ // Check against filters
+ if (term[filter.filterIndex].match(filter.filterValue)) {
+ results.push([terms[0][filter.outputIndex], term[filter.outputIndex], terms[0][filter.inputIndex], term[filter.inputIndex]]);
+ }
}
}
-
- // Return filtered set
- return ioSet;
+ return results;
}
diff --git a/Vocab/Verbs.csv b/Vocab/Verbs.csv
@@ -13,7 +13,7 @@ To bring,Traer,Irregular,Trayendo,Irregular,Traigo,Traes,Trae,Traemos,Traen,Irre
To buy,Comprar,Regular,Comprando,Regular,Compro,Compras,Compra,Compramos,Compran,Regular,Compré,Compraste,Compró,Compramos,Compraron,Regular,Compraba,Comprabas,Compraba,Comprábamos,Compraban
To call,Llamar,Regular,Llamando,Regular,Llamo,Llamas,Llama,Llamamos,Llaman,Regular,Llamé,Llamaste,Llamó,Llamamos,Llamaron,Regular,Llamaba,Llamabas,Llamaba,Llamábamos,Llamaban
To clean,Limpiar,Regular,Limpiando,Regular,Limpio,Limpias,Limpia,Limpiamos,Limpian,Regular,Limpié,Limpiaste,Limpió,Limpiamos,Limpiaron,Regular,Limpiaba,Limpiabas,Limpiaba,Limpiábamos,Limpiaban
-To come,Venir,Stem Changing,Viniendo,Irregular,Vengo,Vienes,Viene,Venimos,Vienen,Irregular,Vine,Viniste,Vino,Vinimos,Vinieron,Regular,Venía,Venías,Venía,Veníamos,Venían
+To come,Venir,Stem Changing,Viniendo,"Irregular, Stem Changing",Vengo,Vienes,Viene,Venimos,Vienen,Irregular,Vine,Viniste,Vino,Vinimos,Vinieron,Regular,Venía,Venías,Venía,Veníamos,Venían
To dance,Bailar,Regular,Bailando,Regular,Bailo,Bailas,Baila,Bailamos,Bailan,Regular,Bailé,Bailaste,Bailó,Bailamos,Bailaron,Regular,Bailaba,Bailabas,Bailaba,Bailábamos,Bailaban
To die,Morir,Stem Changing,Muriendo,Stem Changing,Muero,Mueres,Muere,Morimos,Mueren,Stem Changing,Morí,Moriste,Murió,Morimos,Murieron,Regular,Moría,Morías,Moría,Moríamos,Morían
To do,Hacer,Regular,Haciendo,Irregular,Hago,Haces,Hace,Hacemos,Hacen,Irregular,Hice,Hiciste,Hizo,Hicimos,Hicieron,Regular,Hacía,Hacías,Hacía,Hacíamos,Hacían
@@ -83,4 +83,4 @@ To watch,Mirar,Regular,Mirando,Regular,Miro,Miras,Mira,Miramos,Miran,Regular,Mir
To wear,Llevar,Regular,Llevando,Regular,Llevo,Llevas,Lleva,Llevamos,Llevan,Regular,Llevé,Llevaste,Llevó,Llevamos,Llevaron,Regular,Llevaba,Llevabas,Llevaba,Llevábamos,Llevaban
To win,Ganar,Regular,Ganando,Regular,Gano,Ganas,Gana,Ganamos,Ganan,Regular,Gané,Ganaste,Ganó,Ganamos,Ganaron,Regular,Ganaba,Ganabas,Ganaba,Ganábamos,Ganaban
To work,Trabajar,Regular,Trabajando,Regular,Trabajo,Trabajas,Trabaja,Trabajamos,Trabajan,Regular,Trabajé,Trabajaste,Trabajó,Trabajamos,Trabajaron,Regular,Trabajaba,Trabajabas,Trabajaba,Trabajábamos,Trabajaban
-To write,Escribir,Regular,Escribiendo,Regular,Escribo,Escribes,Escribe,Escribimos,Escriben,Regular,Escribí,Escribiste,Escribió,Escribimos,Escribieron,Regular,Escribía,Escribías,Escribía,Escribíamos,Escribían
+To write,Escribir,Regular,Escribiendo,Regular,Escribo,Escribes,Escribe,Escribimos,Escriben,Regular,Escribí,Escribiste,Escribió,Escribimos,Escribieron,Regular,Escribía,Escribías,Escribía,Escribíamos,Escribían
+\ No newline at end of file
diff --git a/index.html b/index.html
@@ -46,21 +46,20 @@
<div id="verbSettings" hidden>
<template id="verbFilterTemplate">
<div class="verbFilter">
- <select id="verbFilterType" class="verbFilterType">
- <option>All Conjugations</option>
- <option>Reverse Conjugations</option>
+ <select id="verbFilterTense" onchange="VerbTenseChanged(this);">
+ <option>All Tenses</option>
<option>Present Participles</option>
<option>Present Tense</option>
<option>Preterite Tense</option>
<option>Imperfect Tense</option>
- <option>Present Participle non-Regular</option>
- <option>Present non-Regular</option>
- <option>Preterite non-Regular</option>
- <option>Imperfect non-Regular</option>
- <option>Present Participle Regular</option>
- <option>Present Regular</option>
- <option>Preterite Regular</option>
- <option>Imperfect Regular</option>
+ </select>
+ <select id="verbFilterType">
+ <option>All Types</option>
+ <option>Regular</option>
+ <option>Nonregular</option>
+ <option>Stem Changing</option>
+ <option>Orthographic</option>
+ <option>Irregular</option>
</select>
<a id="verbFilterRemove" class="itemRemove">╳</a>
</div>