From: Mischa POSLAWSKY Date: Sun, 5 Jun 2022 22:48:31 +0000 (+0200) Subject: word: reference root categories X-Git-Tag: v1.14~72 X-Git-Url: http://git.shiar.nl/sheet.git/commitdiff_plain/c64bae6314f71d7c4aa3a0c27c53f54f9f7f6344 word: reference root categories --- diff --git a/tools/mkwordlist b/tools/mkwordlist index 6555246..81c3630 100755 --- a/tools/mkwordlist +++ b/tools/mkwordlist @@ -16,6 +16,10 @@ if (my $lang = shift @ARGV) { my $cols = "ref, array_to_string(form || alt, '/'), prio, id, sub"; %rows = $db->select(_word => $cols, \%filter)->map_arrays; defined $_->[-1] or pop @$_ for values %rows; + $rows{''} = [ + (undef) x 3, + [$db->select(word => 'id', {cat => undef, ref => undef})->flat] + ]; say pp \%rows =~ s/\\x\{([0-9A-F]+)\}/chr hex $1/ger; exit; diff --git a/word/quiz.js b/word/quiz.js index a7194bb..fb36be1 100644 --- a/word/quiz.js +++ b/word/quiz.js @@ -23,6 +23,11 @@ class WordQuiz { let ids = new Set(Object.keys(json)); const selection = {...json}; // clone + for (let cat of selection[''][3]) { + if (selection[cat]) + selection[cat][1] = 0; // keep root categories + } + if (this.preset.cat !== undefined) { ids.clear(); let children = [this.preset.cat]; @@ -50,7 +55,7 @@ class WordQuiz { selection[id][3] = function subresolve(subs) { //console.log(subs); return (subs || []).flatMap(sub => - sub in selection ? [sub] : subresolve(json[sub][3]) + sub in selection ? [sub] : json[sub] ? subresolve(json[sub][3]) : [] ); }(selection[id][3]); }