sub cues now a bit better at finding words.
This commit is contained in:
parent
e888384af1
commit
4fddddedd2
|
|
@ -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"')
|
||||
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"<span {style_attr}>{html.escape(surface)}</span>"
|
||||
return f"<ruby {style_attr}>{html.escape(surface)}<rt>{html.escape(reading)}</rt></ruby>"
|
||||
# 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"<span {style_attr}>{html.escape(token.surface)}</span>"
|
||||
return f"<ruby {style_attr}>{html.escape(token.surface)}<rt>{html.escape(token.reading_hiragana)}</rt></ruby>"
|
||||
|
||||
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"<c.{proficiency_stats[surface]['Color']}>"
|
||||
if proficiency_stats.get(token.lemma):
|
||||
if proficiency_stats[token.lemma]['Color'] != '':
|
||||
color_prefix = f"<c.{proficiency_stats[token.lemma]['Color']}>"
|
||||
color_suffix = f"</c>"
|
||||
if surface == reading:
|
||||
return f"{color_prefix}{html.escape(surface)}{color_suffix}"
|
||||
return f"{color_prefix}<ruby>{html.escape(surface)}<rt>{html.escape(reading)}</rt></ruby>{color_suffix}"
|
||||
elif proficiency_stats.get(token.surface):
|
||||
if proficiency_stats[token.surface]['Color'] != '':
|
||||
color_prefix = f"<c.{proficiency_stats[token.surface]['Color']}>"
|
||||
color_suffix = f"</c>"
|
||||
if token.surface == token.reading_hiragana:
|
||||
return f"{color_prefix}{html.escape(token.surface)}{color_suffix}"
|
||||
return f"{color_prefix}<ruby>{html.escape(token.surface)}<rt>{html.escape(token.reading_hiragana)}</rt></ruby>{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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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] = '<span>' + result['ruby_html'] + '</span>' + "\n> [!summary]- Vocab\n>" + result['notes_link'] + "\n\n" # lost the new line
|
||||
lines[i] = '<span><details><summary>' + result['ruby_html'] + '</summary>' + lines[i] + '</span>' + "\n> [!summary]- Vocab\n>" + result['notes_link'] + "\n\n" # lost the new line
|
||||
file_changed = True
|
||||
i+=1
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user