update to use RE for spliting text

This commit is contained in:
Wolfang Torres
2026-07-19 05:23:19 +08:00
parent b30c8de0b4
commit 8efebfb5ed
2 changed files with 12 additions and 7 deletions

View File

@@ -4,6 +4,7 @@ Interface for managuing and procesing files
""" """
# Standard Library # Standard Library
import re
from pathlib import Path from pathlib import Path
# Local # Local
@@ -234,7 +235,9 @@ def process_a_dictation_file(process_file: ProcessFile, language_id: str) -> Pat
with process_file.absolute_input_file.open( with process_file.absolute_input_file.open(
"r", encoding="utf8", newline="\n" "r", encoding="utf8", newline="\n"
) as file: ) 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) results = dictation_process(text_lines, process_file)
return output_anki_dictation(process_file, results) 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() line.strip() for line in file.readlines() if line.strip()
] ]
results[process_file] = completed_process(text_lines, process_file) 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}") print(f"Error procesing {process_file} with language {language_id}")
continue continue
return output_anki_package(process_folder, results) return output_anki_package(process_folder, results)

View File

@@ -110,18 +110,20 @@ def dictionary_bulk_process(words_list: list[str], process_file: ProcessFile):
entries_en = dictionary_en.get(word) entries_en = dictionary_en.get(word)
entries = dictionary.get(word) entries = dictionary.get(word)
if entries: 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 = [ pos_meanings = [
meaning meaning
for entry, entry_en in zip(entries, entries_en) for entry, entry_en in zip(entries, entries_en)
for meaning, meaning_en in zip( for meaning, meaning_en in zip(entry.meanings, entry_en.meanings)
entry.meanings, entry_en.meanings
)
if hint and (hint in meaning_en or hint in meaning) if hint and (hint in meaning_en or hint in meaning)
] ]
pos_meanings = pos_meanings or all_meanings pos_meanings = pos_meanings or all_meanings
if not pos_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( meanings_text = "\n".join(
f"{n+1}: {meaning}" for n, meaning in enumerate(pos_meanings) f"{n+1}: {meaning}" for n, meaning in enumerate(pos_meanings)
) )