diff --git a/fugashi_parser.py b/fugashi_parser.py
index 72ef555..e207e98 100644
--- a/fugashi_parser.py
+++ b/fugashi_parser.py
@@ -141,7 +141,7 @@ def get_card_proficiency(query="deck:current"):
elif queue_state == 3:
status = "Relearning"
color = 'lime'
- elif queue_state == 2:
+ elif queue_state == 2 or queue_state == -2:
# Review card split by 21-day threshold
if interval >= 21:
status = "Mature"
@@ -149,11 +149,11 @@ def get_card_proficiency(query="deck:current"):
else:
status = "Young"
color = 'cyan'
- elif queue_state < 0:
+ elif queue_state == -1:
status = "Suspended"
color = ''
else:
- status = f"Unknown (Queue {queue})"
+ status = f"Unknown (Queue {queue_state})"
color = ''
word = ''
@@ -166,8 +166,10 @@ def get_card_proficiency(query="deck:current"):
if (card_proficiency.get(word)):
print("Multiple matches for word")
+ if (card_proficiency[word]['State'] < queue_state):
+ card_proficiency[word] = {'Status' : status,'State' : queue_state, 'Color' : color}
else:
- card_proficiency[word] = {'Status' : status,'State' : status, 'Color' : color}
+ card_proficiency[word] = {'Status' : status,'State' : queue_state, 'Color' : color }
print(f"Card ID {card_id} (State: {queue_state}):")
print(f" Reps: {reps} | Lapses: {lapses} | Interval: {interval} days | Ease: {status} \n")
@@ -176,7 +178,13 @@ def get_card_proficiency(query="deck:current"):
# Example usage: Evaluate proficiency for all cards in a specific deck
# get_card_proficiency(query='deck:"Your Deck Name Here"')
-proficiency_stats = get_card_proficiency(query='deck:"Japanese Vocab" card:0')
+try:
+ proficiency_stats = get_card_proficiency(query='deck:"Japanese Vocab" card:0')
+ with open('vocab-cache.json', "w", encoding="utf-8") as f:
+ json.dump(proficiency_stats, f, ensure_ascii=False, indent=2)
+except:
+ with open("vocab-cache.json", "r", encoding="utf-8") as f:
+ proficiency_stats = json.load(f)
CONTENT_LINK_TAG = {
'名詞': 'meishi', # noun
@@ -216,30 +224,38 @@ def should_ruby(surface, reading_hiragana):
return True
-def build_ruby(surface: str, reading: str) -> str:
- if not reading or not has_japanese(surface):
- return html.escape(surface)
+def build_ruby(token :TokenReading) -> str:
+ if not token.reading_hiragana or not has_japanese(token.surface):
+ return html.escape(token.surface)
style_attr = ''
- if proficiency_stats.get(surface):
- if proficiency_stats[surface]['Color'] != '':
- style_attr = f"style=\"color:{proficiency_stats[surface]['Color']}\""
- if surface == reading:
- return f"{html.escape(surface)}"
- return f"{html.escape(surface)}"
+ # First try lemma then try surface
+ if proficiency_stats.get(token.lemma):
+ if proficiency_stats[token.lemma]['Color'] != '':
+ style_attr = f"style=\"color:{proficiency_stats[token.lemma]['Color']}\""
+ elif proficiency_stats.get(token.surface):
+ if proficiency_stats[token.surface]['Color'] != '':
+ style_attr = f"style=\"color:{proficiency_stats[token.surface]['Color']}\""
+ if token.surface == token.reading_hiragana:
+ return f"{html.escape(token.surface)}"
+ return f"{html.escape(token.surface)}"
-def build_sub_cue(surface: str, reading: str) -> str:
- if not reading or not has_japanese(surface):
- return html.escape(surface)
+def build_sub_cue(token :TokenReading) -> str:
+ if not token.reading_hiragana or not has_japanese(token.surface):
+ return html.escape(token.surface)
# Check if color
color_prefix = ''
color_suffix = ''
- if proficiency_stats.get(surface):
- if proficiency_stats[surface]['Color'] != '':
- color_prefix = f""
+ if proficiency_stats.get(token.lemma):
+ if proficiency_stats[token.lemma]['Color'] != '':
+ color_prefix = f""
color_suffix = f""
- if surface == reading:
- return f"{color_prefix}{html.escape(surface)}{color_suffix}"
- return f"{color_prefix}{html.escape(surface)}{color_suffix}"
+ elif proficiency_stats.get(token.surface):
+ if proficiency_stats[token.surface]['Color'] != '':
+ color_prefix = f""
+ color_suffix = f""
+ if token.surface == token.reading_hiragana:
+ return f"{color_prefix}{html.escape(token.surface)}{color_suffix}"
+ return f"{color_prefix}{html.escape(token.surface)}{color_suffix}"
def build_kana(surface: str, reading: str) -> str:
if not reading or surface == reading or not has_japanese(surface):
@@ -459,8 +475,8 @@ def analyze(text: str, vocab: Dict[str, Dict]):
token = TokenReading(surface, reading, lemma, lemma_reading, pos)
tokens.append(token)
- ruby_parts.append(build_ruby(surface, reading))
- subtitle_parts.append(build_sub_cue(surface, reading))
+ ruby_parts.append(build_ruby(token))
+ subtitle_parts.append(build_sub_cue(token))
kana_parts.append(build_kana(surface, reading))
predicate_chunks = chunk_predicates(tokens)
diff --git a/process_markdown.py b/process_markdown.py
index 93e1d76..1e2d830 100644
--- a/process_markdown.py
+++ b/process_markdown.py
@@ -45,7 +45,7 @@ def main():
result = analyze(lines[i],vocab)
## If the line changed at all
if lines[i] != result['ruby_html']:
- lines[i] = '' + result['ruby_html'] + '' + "\n> [!summary]- Vocab\n>" + result['notes_link'] + "\n\n" # lost the new line
+ lines[i] = '' + result['ruby_html'] + '
' + lines[i] + ' ' + "\n> [!summary]- Vocab\n>" + result['notes_link'] + "\n\n" # lost the new line
file_changed = True
i+=1