word: reference root categories
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 5 Jun 2022 22:48:31 +0000 (00:48 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 11 Jul 2022 02:02:34 +0000 (04:02 +0200)
tools/mkwordlist
word/quiz.js

index 655524639e4131e8fecce2a68a806550d7faca23..81c363009acef20554311a922f009a8913e2e62e 100755 (executable)
@@ -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;
index a7194bbac88418f0b5cfd89aa6e5dd8c1369c9d4..fb36be12f94bc5f7b026c85ed42014f1c5ba6df5 100644 (file)
@@ -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]);
                }