From 5eb0f88bc28499a44cd5fd71abf01fbdaae91211 Mon Sep 17 00:00:00 2001 From: Nitsud Yarg Date: Sat, 23 May 2026 21:47:40 -0700 Subject: [PATCH] just playing with stuff now. words output pos now --- fugashi_parser.py | 53 +++++++++++++++++++++++++++++++++++++++----- make_dialog_notes.py | 9 ++++++++ process_markdown.py | 22 +++++++++--------- 3 files changed, 66 insertions(+), 18 deletions(-) diff --git a/fugashi_parser.py b/fugashi_parser.py index b048ba5..5e5de82 100644 --- a/fugashi_parser.py +++ b/fugashi_parser.py @@ -98,6 +98,12 @@ def term_entries(term :str) -> dict: response = requests.post(request_url + "/termEntries", json = params, timeout = request_timeout) return json.loads(response.text) +CONTENT_LINK_TAG = { + '名詞': 'meishi', # noun + '動詞': 'doshi', # verb + '形容詞': 'keiyoshi' # Adjective + #'副詞' : 'fukushi' #adverb +} def is_content_word(pos1: str) -> bool: return pos1 in {"名詞", "動詞", "形容詞", "副詞"} @@ -137,11 +143,12 @@ def build_kana(surface: str, reading: str) -> str: return f"「{reading}」" 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): return surface - if surface == reading: - return f"[[{surface}]]" - return f"[[{reading}|{surface}]]" + # if surface == reading: + # return f"[[{surface}]]" + return f"[[{reading}_{pos1}|{surface}]]" ## Predicate filtering Verbs def is_predicate_start(pos): @@ -362,12 +369,44 @@ def analyze(text: str, vocab: Dict[str, Dict]): "predicate_chunks" : predicate_chunks, } -def write_word_note(word: str, destination_dir: Path): - if Path(destination_dir.joinpath(word + '.md')).exists() == False: +YOMITAN_TO_MICAB_POS = { + 'interjection': 'foo', + 'noun': 'meishi', + '5-dan': '', + '1-dan': '', + 'prefix': '', + 'intransitive': '', + 'aux-verb': '', + 'suru': '', + 'transitive': '', + 'counter': '', + 'na-adj': '', + 'exp': '', + 'adjective': '', + 'suffix': '', + 'conjunction': '', + 'interjection': '', + 'adverb': '', + 'pronoun': '', + 'unclass': '', +} + +def write_word_note(word: str, destination_dir: Path, part_of_speech:str='', overwrite:bool=False): + word_file_name = word + # Not ready for different file names yet + if part_of_speech != '': + word_file_name = word + '_' + part_of_speech + if (Path(destination_dir.joinpath(word_file_name + '.md')).exists() == False) or overwrite == True: definitions = anki_fields_term(word) if definitions.get("fields"): - with open(destination_dir.joinpath(word + '.md'), 'w') as vocab_note: + with open(destination_dir.joinpath(word_file_name + '.md'), 'w') as vocab_note: for entry in definitions.get("fields"): + #pos = entry['part-of-speech'] ## POS is always 'Unknown' for some reason + pos = re.match(r'.*(.*?)<',entry['glossary-first']) + if pos: + pos = pos.group(1) + # if part_of_speech != '' and pos: + # print(pos) #vocab_note.write("\n") #print(entry['expression'], file=vocab_note) #print(entry['furigana-plain'], file=vocab_note) @@ -381,5 +420,7 @@ def write_word_note(word: str, destination_dir: Path): vocab_note.write(entry['glossary-first']) #print("##### Other Definitions", file=vocab_note) print("\n", file=vocab_note) + # if CONTENT_LINK_TAG.get(part_of_speech, '') != '': + # print(f"#{CONTENT_LINK_TAG[part_of_speech]}", file=vocab_note) diff --git a/make_dialog_notes.py b/make_dialog_notes.py index b2d0c71..19fea6c 100644 --- a/make_dialog_notes.py +++ b/make_dialog_notes.py @@ -7,6 +7,7 @@ import hashlib destination_directory_name = '/run/media/deck/YF8SD/Sync/Notebooks/Obsidian/Japanese/Yu-Gi-Oh/' destination_path = Path(destination_directory_name) +vocab_destination_path = Path('/run/media/deck/YF8SD/Sync/Notebooks/Obsidian/Japanese/vocab') with open("scripts_dump2.json", "r", encoding="utf-8") as f: dump = json.load(f) @@ -31,6 +32,14 @@ for title in dump: text_J = dump[title][block]['text_J'] text_J = re.sub(r'\$R(.*?)\((.*?)\)',r'\1\2',text_J) print(f"
{text_J}{dump[title][block]['text_E']}
",file=card_note) + text_J = dump[title][block]['text_J'] + text_J = re.sub(r'\$R(.*?)\((.*?)\)',r'\1',text_J) + text_J = text_J.replace('
', '') + vocab = {} ## flush the vocab variable each time + result = analyze(text_J, vocab) + print(f"> [!summary]- Vocab\n>{result['notes_link']}",file=card_note) + for word in vocab: + write_word_note(word, vocab_destination_path, vocab[word]['pos'][0]) # ## add card names as properties # card_note.write("---\n") # card_note.write(f"aliases: [{dump[cd]['name_J']},{dump[cd]['name_E']}]\n") diff --git a/process_markdown.py b/process_markdown.py index b0cf75a..93e1d76 100644 --- a/process_markdown.py +++ b/process_markdown.py @@ -13,19 +13,17 @@ def main(): args = parser.parse_args() if args.vocab_folder: - destination_path = Path(args.vocab_folder) - if destination_path.is_dir() == False: + vocab_destination_path = Path(args.vocab_folder) + if vocab_destination_path.is_dir() == False: raise ValueError("Vocab Folder is not a directory.") return else: - destination_path = Path(args.markdown_file).parent - if not destination_path.joinpath('vocab').exists(): - destination_path.joinpath('vocab').mkdir(parents=True, exist_ok=True) - destination_path = destination_path.joinpath('vocab') - # if args.text: - # text = " ".join(args.text) - # else: - # text = sys.stdin.read() + vocab_destination_path = Path(args.markdown_file).parent + if not vocab_destination_path.joinpath('vocab').exists(): + vocab_destination_path.joinpath('vocab').mkdir(parents=True, exist_ok=True) + vocab_destination_path = vocab_destination_path.joinpath('vocab') + + destination_path = Path(args.markdown_file).parent.joinpath(Path(args.markdown_file).stem + '_STUDY.md') #print(args) vocab = {} #load_vocab('foo.json') @@ -56,10 +54,10 @@ def main(): ## vocab now ## Lookup vocab for word in vocab: - write_word_note(word, destination_path) + write_word_note(word, vocab_destination_path, vocab[word]['pos'][0]) ## Output file with changes if changes - with open(args.markdown_file, "w", encoding="utf-8") as f: + with open(destination_path, "w", encoding="utf-8") as f: f.writelines(lines)