From d76b12edd1a42c3c1bcf07c5ef458df260fb682c Mon Sep 17 00:00:00 2001 From: catus felis Date: Mon, 2 Dec 2024 12:43:53 +0700 Subject: [PATCH] Adds filter parameters to allow selective dictionary building --- .github/workflows/release_all.yml | 4 ++-- .github/workflows/release_all_external.yml | 1 + .vscode/launch.json | 5 +++-- bin/convert_all.py | 17 ++++++++++++++++- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release_all.yml b/.github/workflows/release_all.yml index 15275dc..5e1023c 100644 --- a/.github/workflows/release_all.yml +++ b/.github/workflows/release_all.yml @@ -1,4 +1,4 @@ -name: Release all dictionaries +name: Release sample dictionaries on: workflow_dispatch: @@ -60,7 +60,7 @@ jobs: - name: Build all dictionaries run: | - python ./bin/convert_all.py --input_folder=$INPUT_DIR --output_folder=$OUTPUT_DIR --extension=tab + python ./bin/convert_all.py --input_folder=$INPUT_DIR --output_folder=$OUTPUT_DIR --extension=tab --filter=CCCE,ThienChuu - name: Zip all artifacts for release run: | diff --git a/.github/workflows/release_all_external.yml b/.github/workflows/release_all_external.yml index 4753f31..debbbf7 100644 --- a/.github/workflows/release_all_external.yml +++ b/.github/workflows/release_all_external.yml @@ -9,6 +9,7 @@ on: - '*.md' - LICENSE - bin/create_inflections.py + - .github/workflows/release_all.yml env: INPUT_DIR: ./ext-dict diff --git a/.vscode/launch.json b/.vscode/launch.json index c48a526..3744836 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -6,7 +6,7 @@ "configurations": [ { "name": "Python: Current File", - "type": "python", + "type": "debugpy", "request": "launch", "program": "./bin/convert_all.py", "console": "integratedTerminal", @@ -14,7 +14,8 @@ "args": [ "--input_folder=./dict", "--output_folder=./output", - "--extension=tab" + "--extension=tab", + "--filter=CCCE,ThienChuu" ] } ] diff --git a/bin/convert_all.py b/bin/convert_all.py index 34181b5..4331af9 100755 --- a/bin/convert_all.py +++ b/bin/convert_all.py @@ -71,6 +71,7 @@ def main() -> None: parser.add_argument('-o', '--output_folder', required=True, help='Output folder containing dictionary files') parser.add_argument('-e', '--extension', default='tab', help='Filename extention for input dictionary files. Default is .tab') parser.add_argument('-m', '--metadata', default='dfo', help='Filename extention for input metadata for dictionary. Default is .dfo') + parser.add_argument('-f', '--filter', help='Filter only dictionary entries with matching keys (seperated by comma)') args, array = parser.parse_known_args() @@ -78,6 +79,7 @@ def main() -> None: output_folder = args.output_folder.replace(' ', '\\ ') extension = args.extension metadata = args.metadata + dict_filters = args.filter.split(",") if args.filter is not None else [] if input_folder: metafilelist = sorted(glob.glob(input_folder + f'/*.{metadata}'), reverse=True) @@ -113,6 +115,19 @@ def main() -> None: datafilelist.clear() for key in common_keys: + if dict_filters: + include_dict = False + for filter in dict_filters: + if filter in key: + include_dict = True + + break + + if include_dict: + print(f"Including this dictionary: {key}") + else: + continue + metafilelist.append(meta_dict[key]) datafile = data_dict[key] @@ -143,7 +158,7 @@ def main() -> None: # use_only_these = {'Tu-dien-ThienChuu-TranVanChanh'} for filepath, datafile in zip(metafilelist, datafilelist): - folder, filename = os.path.split(filepath) + _, filename = os.path.split(filepath) filebase, fileext = os.path.splitext(filename) # if filebase not in use_only_these: