Build reading files from lesson folders. It works okay
This commit is contained in:
parent
c14eb1b4c4
commit
77186519cd
33
build_jp101_reading.py
Normal file
33
build_jp101_reading.py
Normal file
|
|
@ -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)
|
||||||
|
|
@ -34,19 +34,19 @@ KATAKANA_TO_HIRAGANA_OFFSET = ord("ぁ") - ord("ァ")
|
||||||
|
|
||||||
CONTENT_POS1 = {"名詞", "動詞", "形容詞", "形状詞", "副詞", "代名詞"}
|
CONTENT_POS1 = {"名詞", "動詞", "形容詞", "形状詞", "副詞", "代名詞"}
|
||||||
|
|
||||||
def is_vocab_token(pos, keep_pronouns=False, keep_numbers=False):
|
# def is_vocab_token(pos, keep_pronouns=False, keep_numbers=False):
|
||||||
pos1, pos2, pos3, pos4 = pos
|
# pos1, pos2, pos3, pos4 = pos
|
||||||
|
|
||||||
if pos1 not in CONTENT_POS1:
|
# if pos1 not in CONTENT_POS1:
|
||||||
return False
|
# return False
|
||||||
|
|
||||||
if pos1 == "代名詞" and not keep_pronouns:
|
# if pos1 == "代名詞" and not keep_pronouns:
|
||||||
return False
|
# return False
|
||||||
|
|
||||||
if pos1 == "名詞" and pos2 == "数詞" and not keep_numbers:
|
# if pos1 == "名詞" and pos2 == "数詞" and not keep_numbers:
|
||||||
return False
|
# 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:
|
def build_vocab_link(surface: str, reading: str, pos) -> str:
|
||||||
pos1, pos2, pos3, pos4 = pos
|
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
|
return surface
|
||||||
# if surface == reading:
|
# if surface == reading:
|
||||||
# return f"[[{surface}]]"
|
# return f"[[{surface}]]"
|
||||||
|
|
@ -232,7 +232,7 @@ def chunk_predicates(tokens):
|
||||||
return chunks
|
return chunks
|
||||||
|
|
||||||
## Vocab Filtering
|
## 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
|
pos1, pos2, pos3, pos4 = pos
|
||||||
|
|
||||||
if pos1 not in {"名詞", "動詞", "形容詞", "形状詞", "副詞", "代名詞", "感動詞"}:
|
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:
|
if pos1 == "代名詞" and not keep_pronouns:
|
||||||
return False
|
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 False
|
||||||
|
|
||||||
return True
|
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):
|
# if should_skip(t.surface, pos1) or not is_content_word(pos1):
|
||||||
# continue
|
# 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
|
continue
|
||||||
|
|
||||||
entry = vocab.get(t.lemma)
|
entry = vocab.get(t.lemma)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user