Skip to content

Commit

Permalink
Adds filter parameters to allow selective dictionary building
Browse files Browse the repository at this point in the history
  • Loading branch information
catusf authored Dec 2, 2024
1 parent ed161cc commit d76b12e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release_all.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release all dictionaries
name: Release sample dictionaries

on:
workflow_dispatch:
Expand Down Expand Up @@ -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: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release_all_external.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
- '*.md'
- LICENSE
- bin/create_inflections.py
- .github/workflows/release_all.yml

env:
INPUT_DIR: ./ext-dict
Expand Down
5 changes: 3 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"type": "debugpy",
"request": "launch",
"program": "./bin/convert_all.py",
"console": "integratedTerminal",
"justMyCode": true,
"args": [
"--input_folder=./dict",
"--output_folder=./output",
"--extension=tab"
"--extension=tab",
"--filter=CCCE,ThienChuu"
]
}
]
Expand Down
17 changes: 16 additions & 1 deletion bin/convert_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ 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()

input_folder = args.input_folder.replace(' ', '\\ ')
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)
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit d76b12e

Please sign in to comment.