From 77186519cd83279ec18ae9be59c5969edf4390d0 Mon Sep 17 00:00:00 2001 From: Nitsud Yarg Date: Fri, 5 Jun 2026 15:23:52 -0700 Subject: [PATCH] Build reading files from lesson folders. It works okay --- build_jp101_reading.py | 33 +++++++++++++++++++++++++++++++++ fugashi_parser.py | 26 +++++++++++++------------- 2 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 build_jp101_reading.py diff --git a/build_jp101_reading.py b/build_jp101_reading.py new file mode 100644 index 0000000..2f76293 --- /dev/null +++ b/build_jp101_reading.py @@ -0,0 +1,33 @@ +from fugashi_parser import * + +import os +from pathlib import Path +import shutil +import hashlib + +season_path = Path('/run/media/deck/YF8SD/Sync/Notebooks/Obsidian/Japanese/JPod101/3N_Absolute Beginner Season 2/') + +pos_list = list() +with open(season_path.parent.joinpath(season_path.stem + '.md'), 'w') as out_file: + for file_path in sorted(season_path.iterdir()): + if file_path.is_file() and file_path.suffix == '.md': # Ensure it's a file, not a subdirectory + #out_file = file_path.parent.parent.joinpath(file_path.parent.stem + '_READ.md') + with open(file_path, "r") as file: + #file.write("This text will be added to the end.") + print(f"###### [[{file_path.name}]]", file=out_file) + file.seek(0) + kanji_block = re.search(r'·+\s*KANJI(.*?)·+\s*[KANA|ROMANIZATION]', file.read(), re.DOTALL) + if (kanji_block): + kanji_block.group(1) + print( kanji_block.group(1).strip().replace('····','') , file=out_file) + else: + print(file_path.stem, 'No Kanji block found') + # else: + # print(pos, ' - no tag') + + # with file_path.open('r') as file: + # content = file.read() + # print(f"Content of {file_path.name}: {content}") + +unique_values = list(set(pos_list)) +print(unique_values) \ No newline at end of file diff --git a/fugashi_parser.py b/fugashi_parser.py index 8ebbf41..1ead554 100644 --- a/fugashi_parser.py +++ b/fugashi_parser.py @@ -34,19 +34,19 @@ KATAKANA_TO_HIRAGANA_OFFSET = ord("ぁ") - ord("ァ") CONTENT_POS1 = {"名詞", "動詞", "形容詞", "形状詞", "副詞", "代名詞"} -def is_vocab_token(pos, keep_pronouns=False, keep_numbers=False): - pos1, pos2, pos3, pos4 = pos +# def is_vocab_token(pos, keep_pronouns=False, keep_numbers=False): +# pos1, pos2, pos3, pos4 = pos - if pos1 not in CONTENT_POS1: - return False +# if pos1 not in CONTENT_POS1: +# return False - if pos1 == "代名詞" and not keep_pronouns: - return False +# if pos1 == "代名詞" and not keep_pronouns: +# return False - if pos1 == "名詞" and pos2 == "数詞" and not keep_numbers: - return False +# if pos1 == "名詞" and pos2 == "数詞" and not keep_numbers: +# return False - return True +# return True @@ -148,7 +148,7 @@ def build_kana(surface: str, reading: str) -> str: def build_vocab_link(surface: str, reading: str, pos) -> str: pos1, pos2, pos3, pos4 = pos - if not is_vocab_token(pos, keep_pronouns=True,keep_numbers=False): + if not is_vocab_token(surface, pos, keep_pronouns=True,keep_numbers=False): return surface # if surface == reading: # return f"[[{surface}]]" @@ -232,7 +232,7 @@ def chunk_predicates(tokens): return chunks ## Vocab Filtering -def is_vocab_token(pos, keep_pronouns=False, keep_numbers=False): +def is_vocab_token(surface, pos, keep_pronouns=False, keep_numbers=False): pos1, pos2, pos3, pos4 = pos if pos1 not in {"名詞", "動詞", "形容詞", "形状詞", "副詞", "代名詞", "感動詞"}: @@ -241,7 +241,7 @@ def is_vocab_token(pos, keep_pronouns=False, keep_numbers=False): if pos1 == "代名詞" and not keep_pronouns: return False - if pos1 == "名詞" and pos2 == "数詞" and not keep_numbers: + if pos1 == "名詞" and pos2 == "数詞" and not has_kanji(surface) and not keep_numbers: return False return True @@ -299,7 +299,7 @@ def update_vocab(vocab: Dict[str, Dict], tokens: List[TokenReading]): # if should_skip(t.surface, pos1) or not is_content_word(pos1): # continue - if not is_vocab_token(t.pos, keep_pronouns=True,keep_numbers=False): + if not is_vocab_token(t.surface, t.pos, keep_pronouns=True,keep_numbers=False): continue entry = vocab.get(t.lemma)