update to use RE for spliting text
This commit is contained in:
@@ -4,6 +4,7 @@ Interface for managuing and procesing files
|
||||
"""
|
||||
|
||||
# Standard Library
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
# Local
|
||||
@@ -234,7 +235,9 @@ def process_a_dictation_file(process_file: ProcessFile, language_id: str) -> Pat
|
||||
with process_file.absolute_input_file.open(
|
||||
"r", encoding="utf8", newline="\n"
|
||||
) as file:
|
||||
text_lines = [line.strip() for line in file.read().split("。") if line.strip()]
|
||||
text = file.read().strip()
|
||||
result = re.split(r"[!?。;]*", text)
|
||||
text_lines = [line.strip() for line in result if line.strip()]
|
||||
results = dictation_process(text_lines, process_file)
|
||||
return output_anki_dictation(process_file, results)
|
||||
|
||||
@@ -313,7 +316,7 @@ def folder_proccess(process_folder: ProcessFolder, language_id: str):
|
||||
line.strip() for line in file.readlines() if line.strip()
|
||||
]
|
||||
results[process_file] = completed_process(text_lines, process_file)
|
||||
except (AttributeError, AssertionError):
|
||||
except AttributeError, AssertionError:
|
||||
print(f"Error procesing {process_file} with language {language_id}")
|
||||
continue
|
||||
return output_anki_package(process_folder, results)
|
||||
|
||||
@@ -110,18 +110,20 @@ def dictionary_bulk_process(words_list: list[str], process_file: ProcessFile):
|
||||
entries_en = dictionary_en.get(word)
|
||||
entries = dictionary.get(word)
|
||||
if entries:
|
||||
all_meanings = [meaning for entry in entries for meaning in entry.meanings]
|
||||
all_meanings = [
|
||||
meaning for entry in entries for meaning in entry.meanings
|
||||
]
|
||||
pos_meanings = [
|
||||
meaning
|
||||
for entry, entry_en in zip(entries, entries_en)
|
||||
for meaning, meaning_en in zip(
|
||||
entry.meanings, entry_en.meanings
|
||||
)
|
||||
for meaning, meaning_en in zip(entry.meanings, entry_en.meanings)
|
||||
if hint and (hint in meaning_en or hint in meaning)
|
||||
]
|
||||
pos_meanings = pos_meanings or all_meanings
|
||||
if not pos_meanings:
|
||||
raise ValueError(f"Not menaing found for hint {hint}, {all_meanings}")
|
||||
raise ValueError(
|
||||
f"Not menaing found for hint {hint}, {all_meanings}"
|
||||
)
|
||||
meanings_text = "\n".join(
|
||||
f"{n+1}: {meaning}" for n, meaning in enumerate(pos_meanings)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user