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:
|
elif queue_state == 3:
|
||||||
status = "Relearning"
|
status = "Relearning"
|
||||||
color = 'lime'
|
color = 'lime'
|
||||||
elif queue_state == 2:
|
elif queue_state == 2 or queue_state == -2:
|
||||||
# Review card split by 21-day threshold
|
# Review card split by 21-day threshold
|
||||||
if interval >= 21:
|
if interval >= 21:
|
||||||
status = "Mature"
|
status = "Mature"
|
||||||
|
|
@ -149,11 +149,11 @@ def get_card_proficiency(query="deck:current"):
|
||||||
else:
|
else:
|
||||||
status = "Young"
|
status = "Young"
|
||||||
color = 'cyan'
|
color = 'cyan'
|
||||||
elif queue_state < 0:
|
elif queue_state == -1:
|
||||||
status = "Suspended"
|
status = "Suspended"
|
||||||
color = ''
|
color = ''
|
||||||
else:
|
else:
|
||||||
status = f"Unknown (Queue {queue})"
|
status = f"Unknown (Queue {queue_state})"
|
||||||
color = ''
|
color = ''
|
||||||
|
|
||||||
word = ''
|
word = ''
|
||||||
|
|
@ -166,8 +166,10 @@ def get_card_proficiency(query="deck:current"):
|
||||||
|
|
||||||
if (card_proficiency.get(word)):
|
if (card_proficiency.get(word)):
|
||||||
print("Multiple matches for word")
|
print("Multiple matches for word")
|
||||||
|
if (card_proficiency[word]['State'] < queue_state):
|
||||||
|
card_proficiency[word] = {'Status' : status,'State' : queue_state, 'Color' : color}
|
||||||
else:
|
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"Card ID {card_id} (State: {queue_state}):")
|
||||||
print(f" Reps: {reps} | Lapses: {lapses} | Interval: {interval} days | Ease: {status} \n")
|
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
|
# Example usage: Evaluate proficiency for all cards in a specific deck
|
||||||
# get_card_proficiency(query='deck:"Your Deck Name Here"')
|
# 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 = {
|
CONTENT_LINK_TAG = {
|
||||||
'名詞': 'meishi', # noun
|
'名詞': 'meishi', # noun
|
||||||
|
|
@ -216,30 +224,38 @@ def should_ruby(surface, reading_hiragana):
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def build_ruby(surface: str, reading: str) -> str:
|
def build_ruby(token :TokenReading) -> str:
|
||||||
if not reading or not has_japanese(surface):
|
if not token.reading_hiragana or not has_japanese(token.surface):
|
||||||
return html.escape(surface)
|
return html.escape(token.surface)
|
||||||
style_attr = ''
|
style_attr = ''
|
||||||
if proficiency_stats.get(surface):
|
# First try lemma then try surface
|
||||||
if proficiency_stats[surface]['Color'] != '':
|
if proficiency_stats.get(token.lemma):
|
||||||
style_attr = f"style=\"color:{proficiency_stats[surface]['Color']}\""
|
if proficiency_stats[token.lemma]['Color'] != '':
|
||||||
if surface == reading:
|
style_attr = f"style=\"color:{proficiency_stats[token.lemma]['Color']}\""
|
||||||
return f"<span {style_attr}>{html.escape(surface)}</span>"
|
elif proficiency_stats.get(token.surface):
|
||||||
return f"<ruby {style_attr}>{html.escape(surface)}<rt>{html.escape(reading)}</rt></ruby>"
|
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:
|
def build_sub_cue(token :TokenReading) -> str:
|
||||||
if not reading or not has_japanese(surface):
|
if not token.reading_hiragana or not has_japanese(token.surface):
|
||||||
return html.escape(surface)
|
return html.escape(token.surface)
|
||||||
# Check if color
|
# Check if color
|
||||||
color_prefix = ''
|
color_prefix = ''
|
||||||
color_suffix = ''
|
color_suffix = ''
|
||||||
if proficiency_stats.get(surface):
|
if proficiency_stats.get(token.lemma):
|
||||||
if proficiency_stats[surface]['Color'] != '':
|
if proficiency_stats[token.lemma]['Color'] != '':
|
||||||
color_prefix = f"<c.{proficiency_stats[surface]['Color']}>"
|
color_prefix = f"<c.{proficiency_stats[token.lemma]['Color']}>"
|
||||||
color_suffix = f"</c>"
|
color_suffix = f"</c>"
|
||||||
if surface == reading:
|
elif proficiency_stats.get(token.surface):
|
||||||
return f"{color_prefix}{html.escape(surface)}{color_suffix}"
|
if proficiency_stats[token.surface]['Color'] != '':
|
||||||
return f"{color_prefix}<ruby>{html.escape(surface)}<rt>{html.escape(reading)}</rt></ruby>{color_suffix}"
|
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:
|
def build_kana(surface: str, reading: str) -> str:
|
||||||
if not reading or surface == reading or not has_japanese(surface):
|
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)
|
token = TokenReading(surface, reading, lemma, lemma_reading, pos)
|
||||||
tokens.append(token)
|
tokens.append(token)
|
||||||
|
|
||||||
ruby_parts.append(build_ruby(surface, reading))
|
ruby_parts.append(build_ruby(token))
|
||||||
subtitle_parts.append(build_sub_cue(surface, reading))
|
subtitle_parts.append(build_sub_cue(token))
|
||||||
kana_parts.append(build_kana(surface, reading))
|
kana_parts.append(build_kana(surface, reading))
|
||||||
predicate_chunks = chunk_predicates(tokens)
|
predicate_chunks = chunk_predicates(tokens)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ def main():
|
||||||
result = analyze(lines[i],vocab)
|
result = analyze(lines[i],vocab)
|
||||||
## If the line changed at all
|
## If the line changed at all
|
||||||
if lines[i] != result['ruby_html']:
|
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
|
file_changed = True
|
||||||
i+=1
|
i+=1
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user