add bulk procesing
This commit is contained in:
@@ -5,6 +5,7 @@ from pathlib import Path
|
||||
|
||||
# Local
|
||||
from .api import (
|
||||
folder_proccess,
|
||||
is_file,
|
||||
list_input_files,
|
||||
pre_process_a_dictionary_file,
|
||||
@@ -12,9 +13,20 @@ from .api import (
|
||||
process_a_dictionary_file,
|
||||
process_a_phrases_file,
|
||||
select_file,
|
||||
select_folder,
|
||||
)
|
||||
from .constants import DICTATION_TYPE, DICT_TYPE, LANGUAGES, PHRASES_TYPE
|
||||
from .utility import ProcessFile
|
||||
from .utility import ProcessFile, ProcessFolder
|
||||
|
||||
|
||||
def cli_choose_work_type() -> str:
|
||||
"""entry point for interactive interface"""
|
||||
option = None
|
||||
while not option in ["s", "f", "e"]:
|
||||
option = input(
|
||||
"Please select the work option:\n" "s: single file, f:folder, e:exit\n"
|
||||
)
|
||||
return option
|
||||
|
||||
|
||||
def cli_select_files() -> ProcessFile:
|
||||
@@ -38,6 +50,30 @@ def cli_select_files() -> ProcessFile:
|
||||
return input_file
|
||||
|
||||
|
||||
def cli_select_folder() -> ProcessFile:
|
||||
"""Loops until it finds a valid input_folder"""
|
||||
print("Select data folder:")
|
||||
in_folder = None
|
||||
level = Path()
|
||||
while not in_folder:
|
||||
files = list_input_files(level)
|
||||
for n, file in enumerate(files):
|
||||
print(f"{n+1} - {file}")
|
||||
s = None
|
||||
while not s or not s.isnumeric() or not 1 <= int(s) <= len(files):
|
||||
s = input(f"Please select the file [1-{len(files)}]: ")
|
||||
selected = files[int(s) - 1]
|
||||
print(f"Selected {selected}")
|
||||
s = None
|
||||
while s not in ("yes", "y", "no", "n"):
|
||||
s = input("if this the folder? (yes/no, go inside)")
|
||||
if s in ("yes", "y"):
|
||||
in_folder = selected
|
||||
else:
|
||||
level = selected
|
||||
return select_folder(in_folder)
|
||||
|
||||
|
||||
def cli_select_dictionay_tsv() -> bool:
|
||||
"""If a dictionary file is selected, ask if the user wants to proccess it"""
|
||||
s = None
|
||||
@@ -74,29 +110,38 @@ def cli_select_language(languages: list = None) -> str:
|
||||
def main():
|
||||
"""CLI interface for the module"""
|
||||
while True:
|
||||
input_file = cli_select_files()
|
||||
if DICT_TYPE in input_file.input_file.suffixes:
|
||||
dict_selected = cli_select_dictionay_tsv()
|
||||
if dict_selected:
|
||||
option = cli_choose_work_type()
|
||||
if option == "e":
|
||||
break
|
||||
elif option == "s":
|
||||
input_file = cli_select_files()
|
||||
if DICT_TYPE in input_file.input_file.suffixes:
|
||||
dict_selected = cli_select_dictionay_tsv()
|
||||
if dict_selected:
|
||||
language_id = cli_select_language()
|
||||
print(
|
||||
f"pre-processing file {input_file} with language {language_id}"
|
||||
)
|
||||
pre_process_a_dictionary_file(input_file, language_id)
|
||||
else:
|
||||
print(f"Processing file {input_file} with language {language_id}")
|
||||
language_id = cli_select_language(
|
||||
input_file.available_dictionary_languages
|
||||
)
|
||||
process_a_dictionary_file(input_file, language_id)
|
||||
elif PHRASES_TYPE in input_file.input_file.suffixes:
|
||||
language_id = cli_select_language()
|
||||
pre_process_a_dictionary_file(input_file, language_id)
|
||||
else:
|
||||
language_id = cli_select_language(
|
||||
input_file.available_dictionary_languages
|
||||
)
|
||||
process_a_dictionary_file(input_file, language_id)
|
||||
elif PHRASES_TYPE in input_file.input_file.suffixes:
|
||||
print(f"processing file {input_file} with language {language_id}")
|
||||
process_a_phrases_file(input_file, language_id)
|
||||
elif DICTATION_TYPE in input_file.input_file.suffixes:
|
||||
language_id = cli_select_language()
|
||||
print(f"processing file {input_file} with language {language_id}")
|
||||
process_a_dictation_file(input_file, language_id)
|
||||
elif option == "f":
|
||||
in_folder = cli_select_folder()
|
||||
language_id = cli_select_language()
|
||||
print(
|
||||
f"processing file {input_file.input_file} with language {language_id}"
|
||||
)
|
||||
process_a_phrases_file(input_file, language_id)
|
||||
elif DICTATION_TYPE in input_file.input_file.suffixes:
|
||||
language_id = cli_select_language()
|
||||
print(
|
||||
f"processing file {input_file.input_file} with language {language_id}"
|
||||
)
|
||||
process_a_dictation_file(input_file, language_id)
|
||||
print(f"Selected: {in_folder} with language {language_id}")
|
||||
folder_proccess(in_folder, language_id=language_id)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user