add plover dictionaries

This commit is contained in:
Charlotte 🦝 Delenk 2022-07-06 14:36:21 +01:00
parent c01d0dedd1
commit acde406961
Signed by: darkkirb
GPG key ID: AB2BD8DAF2E37122
4 changed files with 155 additions and 0 deletions

View file

@ -707,6 +707,7 @@
"nixpkgs-stable": "nixpkgs-stable",
"plover": "plover",
"regenpfeifer": "regenpfeifer",
"steno-dictionaries": "steno-dictionaries",
"wortformliste": "wortformliste"
}
},
@ -735,6 +736,22 @@
"type": "github"
}
},
"steno-dictionaries": {
"flake": false,
"locked": {
"lastModified": 1655010543,
"narHash": "sha256-CkxtDyzB5XZpYyEQDbzspN9VYkXNUJzM7CvfD+tLmcg=",
"owner": "didoesdigital",
"repo": "steno-dictionaries",
"rev": "0dbbd849cdb62ef1195bb511b9062cbe4a826f8f",
"type": "github"
},
"original": {
"owner": "didoesdigital",
"repo": "steno-dictionaries",
"type": "github"
}
},
"utils": {
"locked": {
"lastModified": 1653893745,

View file

@ -39,6 +39,8 @@
hydra.url = "github:mlabs-haskell/hydra/aciceri/ca-derivations";
hydra-patched.url = "git+https://git.chir.rs/darkkirb/hydra?ref=hack";
hydra-base.url = "git+https://git.chir.rs/darkkirb/hydra?ref=hack&rev=3fdc9e491dc7d33bc09ef4f33984f87c8f478aa2";
steno-dictionaries.url = "github:didoesdigital/steno-dictionaries";
steno-dictionaries.flake = false;
};
outputs = {
@ -73,6 +75,7 @@
./fonts/kreative.nix
./fonts/nasin-nanpa.nix
./plover
./plover/dicts.nix
./art
./ci/drone-runner-docker
./vim

109
plover/dicts.nix Normal file
View file

@ -0,0 +1,109 @@
{ inputs, pkgs }:
let
plover = import ./. { inherit inputs pkgs; };
dict_list = [
"abbreviations"
"apps"
"bad-habits"
"briefs"
"code"
"computer-powerups"
"computer-use"
"condensed-strokes-fingerspelled"
"condensed-strokes"
"css-alignment"
"css-declarations"
"css-media-object"
"currency"
"d3"
"data-viz"
"di-briefs"
"di-nouns"
"di-proper-nouns"
"di-spectacle-v1"
"dict-en-AU-phonetic"
"dict-en-AU-vocab"
"dict-en-AU-with-extra-stroke"
"dict"
"emoji"
"fingerspelling-FPLT"
"fingerspelling-RBGS"
"fingerspelling-powerups"
"fingerspelling-right-hand"
"fingerspelling"
"git"
"haxe"
"html"
"human-resources"
"javascript"
"jquery"
"lorem"
"markdown"
"medical-suffixes"
"misstrokes"
"modifiers-single-stroke"
"modifiers"
"navigation"
"nouns"
"numbers-powerups"
"numbers"
"observable"
"plover-powerups"
"plover-use"
"proper-nouns"
"punctuation-di"
"punctuation-powerups"
"punctuation-unspaced"
"punctuation"
"python"
"react"
"retro-quotes"
"roman-numerals"
"ruby"
"shortcuts"
"sketch-app"
"sublime"
"svg"
"symbols-briefs"
"symbols-currency-culled"
"symbols-currency"
"symbols"
"tabbing"
"top-100-words"
"top-1000-words"
"top-10000-project-gutenberg-words"
"top-200-words-spoken-on-tv"
"top-level-domains"
"ux-design"
"vim"
"voiceover"
];
json-to-yaml-env = pkgs.python3.buildEnv.override {
extraLibs = with plover; [ruamel-yaml];
};
json-to-yaml = pkgs.stdenvNoCC.mkDerivation {
name = "json-to-yaml";
srcs = ./.;
python = json-to-yaml-env;
buildPhase = ''
substituteAllInPlace json-to-yaml.py
'';
installPhase = ''
mkdir -p $out/bin
cp json-to-yaml.py $out/bin
chmod +x $out/bin/json-to-yaml.py
'';
};
in builtins.listToAttrs (builtins.map (name: {
name = "plover-dict-${name}";
value = pkgs.stdenvNoCC.mkDerivation {
name = "plover-dict-${name}-${inputs.steno-dictionaries.lastModifiedDate}.yaml";
pname = "plover-dict-${name}";
version = inputs.steno-dictionaries.lastModifiedDate;
srcs = inputs.steno-dictionaries;
buildPhase = ''
${json-to-yaml}/bin/json-to-yaml.py dictionaries/${name}.json $out
'';
installPhase = "true";
};
}) dict_list)

26
plover/json-to-yaml.py Normal file
View file

@ -0,0 +1,26 @@
#!%python%/bin/python
import json
import ruamel.yaml
import sys
JSON_FILENAME = sys.argv[1]
YAML_FILENAME = sys.argv[2]
# Load JSON dictionary
with open(JSON_FILENAME, 'r', encoding='utf-8') as in_file:
in_data = json.load(in_file)
# Group dictionary by value, sorted alphabetically
out_data = {}
for key, value in sorted(in_data.items(), key=lambda x: x[1].casefold()):
out_data.setdefault(value, []).append(key)
out_data[value] = sorted(out_data[value])
# Write dictionary to YAML
with open(YAML_FILENAME, 'w', encoding='utf-8') as out_file:
yaml = ruamel.yaml.YAML(typ='safe')
yaml.allow_unicode = True
yaml.default_flow_style = False
yaml.indent(sequence=4, offset=2)
yaml.dump(out_data, out_file)