X-Git-Url: http://git.shiar.net/sheet.git/blobdiff_plain/5d52e8a4f389cd87b310c609ec76c9ba339284f6..HEAD:/tools/mkwordlist diff --git a/tools/mkwordlist b/tools/mkwordlist index 5e965fe..7611b9f 100755 --- a/tools/mkwordlist +++ b/tools/mkwordlist @@ -1,4 +1,26 @@ -#!/bin/sh -psql sheet -XAt -c " - SELECT json_object_agg(coalesce(form, ''), forms) FROM _cat_words -" | sed 's/ : / => /g' +#!/usr/bin/env perl +use 5.014; +use warnings; + +BEGIN { push @INC, '.' } +use Shiar_Sheet::DB; +use open ':std' => ':encoding(utf-8)'; +my $db = Shiar_Sheet::DB->connect; + +say 'use utf8;'; + +use Data::Dump 'pp'; +my %rows; +my $lang = shift @ARGV or die "Missing language\n"; +{ + my %filter = (lang => $lang); + 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; +}