From 14ecb8f32831ef4747adef1de1af658dc7d4b298 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 8 May 2016 12:01:43 -0700 Subject: File reorg --- build_tmpl.sh | 2 +- build_tmpl_auto.sh | 2 +- tmpl/footer.html | 3 + tmpl/header.html | 14 +++ tmpl/kanji-link.html | 1 + tmpl/kanji-list.html | 5 + tmpl/kanji.html | 43 ++++++++ tmpl/term-list.html | 5 + tmpl/term.html | 40 ++++++++ util/compile.py | 244 ---------------------------------------------- util/data/edict | 3 - util/data/enamdict | 3 - util/data/kanjidic | 3 - util/tmpl/footer.html | 3 - util/tmpl/header.html | 14 --- util/tmpl/kanji-link.html | 1 - util/tmpl/kanji-list.html | 5 - util/tmpl/kanji.html | 43 -------- util/tmpl/term-list.html | 5 - util/tmpl/term.html | 40 -------- 20 files changed, 113 insertions(+), 366 deletions(-) create mode 100644 tmpl/footer.html create mode 100644 tmpl/header.html create mode 100644 tmpl/kanji-link.html create mode 100644 tmpl/kanji-list.html create mode 100644 tmpl/kanji.html create mode 100644 tmpl/term-list.html create mode 100644 tmpl/term.html delete mode 100755 util/compile.py delete mode 100644 util/data/edict delete mode 100644 util/data/enamdict delete mode 100644 util/data/kanjidic delete mode 100644 util/tmpl/footer.html delete mode 100644 util/tmpl/header.html delete mode 100644 util/tmpl/kanji-link.html delete mode 100644 util/tmpl/kanji-list.html delete mode 100644 util/tmpl/kanji.html delete mode 100644 util/tmpl/term-list.html delete mode 100644 util/tmpl/term.html diff --git a/build_tmpl.sh b/build_tmpl.sh index 5c4a0c44..be8362a6 100755 --- a/build_tmpl.sh +++ b/build_tmpl.sh @@ -1,2 +1,2 @@ #!/bin/sh -handlebars util/tmpl/* -f ext/bg/js/templates.js +handlebars tmpl/* -f ext/bg/js/templates.js diff --git a/build_tmpl_auto.sh b/build_tmpl_auto.sh index c10c858c..98065cb7 100755 --- a/build_tmpl_auto.sh +++ b/build_tmpl_auto.sh @@ -1,5 +1,5 @@ #!/bin/bash -DIRECTORY_TO_OBSERVE="util/tmpl" +DIRECTORY_TO_OBSERVE="tmpl" BUILD_SCRIPT="build_tmpl.sh" function block_for_change { diff --git a/tmpl/footer.html b/tmpl/footer.html new file mode 100644 index 00000000..3840600f --- /dev/null +++ b/tmpl/footer.html @@ -0,0 +1,3 @@ + + + diff --git a/tmpl/header.html b/tmpl/header.html new file mode 100644 index 00000000..2256b08a --- /dev/null +++ b/tmpl/header.html @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/tmpl/kanji-link.html b/tmpl/kanji-link.html new file mode 100644 index 00000000..f4f8dc69 --- /dev/null +++ b/tmpl/kanji-link.html @@ -0,0 +1 @@ +{{kanji}} diff --git a/tmpl/kanji-list.html b/tmpl/kanji-list.html new file mode 100644 index 00000000..b5d0b627 --- /dev/null +++ b/tmpl/kanji-list.html @@ -0,0 +1,5 @@ +{{> header.html}} +{{#each defs}} +{{> kanji.html root=../root options=../options sequence=../sequence}} +{{/each}} +{{> footer.html}} diff --git a/tmpl/kanji.html b/tmpl/kanji.html new file mode 100644 index 00000000..7a5affb7 --- /dev/null +++ b/tmpl/kanji.html @@ -0,0 +1,43 @@ +
+ {{#with options}} + {{#if enableAnkiConnect}} +
+ +
+ {{/if}} + {{/with}} + +
{{character}}
+ +
+
+ {{#if glossary}} +
Meanings
+
+ {{#each glossary}} + {{.}}{{#unless @last}}, {{/unless}} + {{/each}} +
+ {{/if}} + + {{#if kunyomi}} +
Kunyomi
+
+ {{#each kunyomi}} + {{.}}{{#unless @last}}, {{/unless}} + {{/each}} +
+ {{/if}} + + {{#if onyomi}} +
Onyomi
+
+ {{#each onyomi}} + {{.}}{{#unless @last}}, {{/unless}} + {{/each}} +
+ {{/if}} +
+
+
+ diff --git a/tmpl/term-list.html b/tmpl/term-list.html new file mode 100644 index 00000000..5581b679 --- /dev/null +++ b/tmpl/term-list.html @@ -0,0 +1,5 @@ +{{> header.html}} +{{#each defs}} +{{> term.html root=../root options=../options sequence=../sequence}} +{{/each}} +{{> footer.html}} diff --git a/tmpl/term.html b/tmpl/term.html new file mode 100644 index 00000000..216ccf0a --- /dev/null +++ b/tmpl/term.html @@ -0,0 +1,40 @@ +
+ {{#with options}} + {{#if enableAnkiConnect}} +
+ + +
+ {{/if}} + {{/with}} + + {{#if reading}} +
{{#kanjiLinks}}{{expression}}{{/kanjiLinks}}{{reading}}
+ {{else}} +
{{#kanjiLinks}}{{expression}}{{/kanjiLinks}}
+ {{/if}} + + {{#if rules}} +
+ {{#each rules}} + {{.}} {{#unless @last}}«{{/unless}} + {{/each}} +
+ {{/if}} + + {{#if tags}} +
+ {{#each tags}} + {{name}} + {{/each}} +
+ {{/if}} + +
+
    + {{#each glossary}} +
  1. {{.}}
  2. + {{/each}} +
+
+
diff --git a/util/compile.py b/util/compile.py deleted file mode 100755 index 41c3f432..00000000 --- a/util/compile.py +++ /dev/null @@ -1,244 +0,0 @@ -#!/usr/bin/env python - -# Copyright (C) 2016 Alex Yatskov -# Author: Alex Yatskov -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - - -import codecs -import json -import optparse -import os.path -import re - - -PARSED_TAGS = { - 'Buddh', - 'MA', - 'X', - 'abbr', - 'adj', - 'adj-f', - 'adj-i', - 'adj-na', - 'adj-no', - 'adj-pn', - 'adj-t', - 'adv', - 'adv-n', - 'adv-to', - 'arch', - 'ateji', - 'aux', - 'aux-adj', - 'aux-v', - 'c', - 'chn', - 'col', - 'comp', - 'conj', - 'ctr', - 'derog', - 'eK', - 'ek', - 'exp', - 'f', - 'fam', - 'fem', - 'food', - 'g', - 'geom', - 'gikun', - 'gram', - 'h', - 'hon', - 'hum', - 'iK', - 'id', - 'ik', - 'int', - 'io', - 'iv', - 'ling', - 'm', - 'm-sl', - 'male', - 'male-sl', - 'math', - 'mil', - 'n', - 'n-adv', - 'n-pref', - 'n-suf', - 'n-t', - 'num', - 'oK', - 'obs', - 'obsc', - 'ok', - 'on-mim', - 'P', - 'p', - 'physics', - 'pn', - 'poet', - 'pol', - 'pr', - 'pref', - 'prt', - 'rare', - 's', - 'sens', - 'sl', - 'st', - 'suf', - 'u', - 'uK', - 'uk', - 'v1', - 'v2a-s', - 'v4h', - 'v4r', - 'v5', - 'v5aru', - 'v5b', - 'v5g', - 'v5k', - 'v5k-s', - 'v5m', - 'v5n', - 'v5r', - 'v5r-i', - 'v5s', - 'v5t', - 'v5u', - 'v5u-s', - 'v5uru', - 'v5z', - 'vi', - 'vk', - 'vn', - 'vs', - 'vs-c', - 'vs-i', - 'vs-s', - 'vt', - 'vulg', - 'vz' -} - - -def is_hiragana(c): - return 0x3040 <= ord(c) < 0x30a0 - - -def is_katakana(c): - return 0x30a0 <= ord(c) < 0x3100 - - -def load_definitions(path): - print('Parsing "{0}"...'.format(path)) - with codecs.open(path, encoding='euc-jp') as fp: - return filter(lambda x: x and x[0] != '#', fp.read().splitlines()) - - -def parse_kanji_dic(path): - results = {} - for line in load_definitions(path): - segments = line.split() - character = segments[0] - kunyomi = ' '.join(filter(lambda x: list(filter(is_hiragana, x)), segments[1:])) - onyomi = ' '.join(filter(lambda x: list(filter(is_katakana, x)), segments[1:])) - glossary = re.findall('\{([^\}]+)\}', line) - results[character] = (kunyomi or None, onyomi or None, glossary) - - return results - - -def parse_edict(path): - results = [] - for line in load_definitions(path): - segments = line.split('/') - - exp_parts = segments[0].split(' ') - expression = exp_parts[0] - reading_match = re.search('\[([^\]]+)\]', exp_parts[1]) - reading = None if reading_match is None else reading_match.group(1) - - defs = [] - tags = set() - - for index, dfn in enumerate(filter(None, segments[1:])): - dfn_match = re.search(r'^((?:\((?:[\w\-\,\:]*)*\)\s*)*)(.*)$', dfn) - - tags_raw = set(filter(None, re.split(r'[\s\(\),]', dfn_match.group(1)))) - tags_raw = tags_raw.intersection(PARSED_TAGS) - tags = tags.union(tags_raw) - - gloss = dfn_match.group(2).strip() - if len(gloss) == 0: - continue - - if index == 0 or len(dfn_match.group(1)) > 0: - defs.append([gloss]) - else: - defs[-1].append(gloss) - - result = [expression, reading, ' '.join(tags)] - result += map(lambda x: '; '.join(x), defs) - - results.append(result) - - indices = {} - for i, d in enumerate(results): - for key in d[:2]: - if key is not None: - values = indices.get(key, []) - values.append(i) - indices[key] = values - - return {'defs': results, 'indices': indices} - - -def build_dict(output_dir, input_file, parser): - if input_file is not None: - base = os.path.splitext(os.path.basename(input_file))[0] - with open(os.path.join(output_dir, base) + '.json', 'w') as fp: - # json.dump(parser(input_file), fp, sort_keys=True, indent=4, separators=(',', ': ')) - json.dump(parser(input_file), fp, separators=(',', ':')) - - -def build(dict_dir, kanjidic, edict, enamdict): - build_dict(dict_dir, kanjidic, parse_kanji_dic) - build_dict(dict_dir, edict, parse_edict) - build_dict(dict_dir, enamdict, parse_edict) - - -def main(): - parser = optparse.OptionParser() - parser.add_option('--kanjidic', dest='kanjidic') - parser.add_option('--edict', dest='edict') - parser.add_option('--enamdict', dest='enamdict') - - options, args = parser.parse_args() - - if len(args) == 0: - parser.print_help() - else: - build(args[0], options.kanjidic, options.edict, options.enamdict) - - -if __name__ == '__main__': - main() diff --git a/util/data/edict b/util/data/edict deleted file mode 100644 index 35fc6bdd..00000000 --- a/util/data/edict +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:51b9e6f5761f3a9c2d1f6c65df131ad3fa60738ffda06e1e0cfb07fdfe6acd89 -size 15655597 diff --git a/util/data/enamdict b/util/data/enamdict deleted file mode 100644 index 17004236..00000000 --- a/util/data/enamdict +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:9fd670f8c8a020aeb2b870d186d223702e91e0538cec04a784b1433363aff9f9 -size 26426507 diff --git a/util/data/kanjidic b/util/data/kanjidic deleted file mode 100644 index dbfb510f..00000000 --- a/util/data/kanjidic +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:494d5a6d750444907995eb3be7bbe7d817a20d3431ae0d8c944715690610b69c -size 1213904 diff --git a/util/tmpl/footer.html b/util/tmpl/footer.html deleted file mode 100644 index 3840600f..00000000 --- a/util/tmpl/footer.html +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/util/tmpl/header.html b/util/tmpl/header.html deleted file mode 100644 index 2256b08a..00000000 --- a/util/tmpl/header.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - diff --git a/util/tmpl/kanji-link.html b/util/tmpl/kanji-link.html deleted file mode 100644 index f4f8dc69..00000000 --- a/util/tmpl/kanji-link.html +++ /dev/null @@ -1 +0,0 @@ -{{kanji}} diff --git a/util/tmpl/kanji-list.html b/util/tmpl/kanji-list.html deleted file mode 100644 index b5d0b627..00000000 --- a/util/tmpl/kanji-list.html +++ /dev/null @@ -1,5 +0,0 @@ -{{> header.html}} -{{#each defs}} -{{> kanji.html root=../root options=../options sequence=../sequence}} -{{/each}} -{{> footer.html}} diff --git a/util/tmpl/kanji.html b/util/tmpl/kanji.html deleted file mode 100644 index 7a5affb7..00000000 --- a/util/tmpl/kanji.html +++ /dev/null @@ -1,43 +0,0 @@ -
- {{#with options}} - {{#if enableAnkiConnect}} -
- -
- {{/if}} - {{/with}} - -
{{character}}
- -
-
- {{#if glossary}} -
Meanings
-
- {{#each glossary}} - {{.}}{{#unless @last}}, {{/unless}} - {{/each}} -
- {{/if}} - - {{#if kunyomi}} -
Kunyomi
-
- {{#each kunyomi}} - {{.}}{{#unless @last}}, {{/unless}} - {{/each}} -
- {{/if}} - - {{#if onyomi}} -
Onyomi
-
- {{#each onyomi}} - {{.}}{{#unless @last}}, {{/unless}} - {{/each}} -
- {{/if}} -
-
-
- diff --git a/util/tmpl/term-list.html b/util/tmpl/term-list.html deleted file mode 100644 index 5581b679..00000000 --- a/util/tmpl/term-list.html +++ /dev/null @@ -1,5 +0,0 @@ -{{> header.html}} -{{#each defs}} -{{> term.html root=../root options=../options sequence=../sequence}} -{{/each}} -{{> footer.html}} diff --git a/util/tmpl/term.html b/util/tmpl/term.html deleted file mode 100644 index 216ccf0a..00000000 --- a/util/tmpl/term.html +++ /dev/null @@ -1,40 +0,0 @@ -
- {{#with options}} - {{#if enableAnkiConnect}} -
- - -
- {{/if}} - {{/with}} - - {{#if reading}} -
{{#kanjiLinks}}{{expression}}{{/kanjiLinks}}{{reading}}
- {{else}} -
{{#kanjiLinks}}{{expression}}{{/kanjiLinks}}
- {{/if}} - - {{#if rules}} -
- {{#each rules}} - {{.}} {{#unless @last}}«{{/unless}} - {{/each}} -
- {{/if}} - - {{#if tags}} -
- {{#each tags}} - {{name}} - {{/each}} -
- {{/if}} - -
-
    - {{#each glossary}} -
  1. {{.}}
  2. - {{/each}} -
-
-
-- cgit v1.2.3