flip flipping words flip
This commit is contained in:
parent
2c4d95fb8d
commit
e888384af1
|
|
@ -131,23 +131,24 @@ def get_card_proficiency(query="deck:current"):
|
||||||
|
|
||||||
# Anki queue mappings:
|
# Anki queue mappings:
|
||||||
# 0 = New, 1 = Learning, 2 = Review, 3 = Relearning
|
# 0 = New, 1 = Learning, 2 = Review, 3 = Relearning
|
||||||
|
# https://www.w3.org/TR/webvtt1/#default-text-color
|
||||||
if queue_state == 0:
|
if queue_state == 0:
|
||||||
status = "New"
|
status = "New"
|
||||||
color = ''
|
color = 'red'
|
||||||
elif queue_state == 1:
|
elif queue_state == 1:
|
||||||
status = "Learning"
|
status = "Learning"
|
||||||
color = 'orangered'
|
color = 'yellow'
|
||||||
elif queue_state == 3:
|
elif queue_state == 3:
|
||||||
status = "Relearning"
|
status = "Relearning"
|
||||||
color = 'yellow'
|
color = 'lime'
|
||||||
elif queue_state == 2:
|
elif 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"
|
||||||
color = 'cyan'
|
color = 'magenta'
|
||||||
else:
|
else:
|
||||||
status = "Young"
|
status = "Young"
|
||||||
color = 'lime'
|
color = 'cyan'
|
||||||
elif queue_state < 0:
|
elif queue_state < 0:
|
||||||
status = "Suspended"
|
status = "Suspended"
|
||||||
color = ''
|
color = ''
|
||||||
|
|
@ -216,9 +217,15 @@ def should_ruby(surface, reading_hiragana):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def build_ruby(surface: str, reading: str) -> str:
|
def build_ruby(surface: str, reading: str) -> str:
|
||||||
if not reading or surface == reading or not has_japanese(surface):
|
if not reading or not has_japanese(surface):
|
||||||
return html.escape(surface)
|
return html.escape(surface)
|
||||||
return f"<ruby>{html.escape(surface)}<rt>{html.escape(reading)}</rt></ruby>"
|
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>"
|
||||||
|
|
||||||
def build_sub_cue(surface: str, reading: str) -> str:
|
def build_sub_cue(surface: str, reading: str) -> str:
|
||||||
if not reading or not has_japanese(surface):
|
if not reading or not has_japanese(surface):
|
||||||
|
|
@ -417,6 +424,7 @@ def analyze(text: str, vocab: Dict[str, Dict]):
|
||||||
|
|
||||||
tokens: List[TokenReading] = []
|
tokens: List[TokenReading] = []
|
||||||
ruby_parts = []
|
ruby_parts = []
|
||||||
|
subtitle_parts = []
|
||||||
kana_parts = []
|
kana_parts = []
|
||||||
vocab_link_parts = []
|
vocab_link_parts = []
|
||||||
|
|
||||||
|
|
@ -452,6 +460,7 @@ def analyze(text: str, vocab: Dict[str, Dict]):
|
||||||
tokens.append(token)
|
tokens.append(token)
|
||||||
|
|
||||||
ruby_parts.append(build_ruby(surface, reading))
|
ruby_parts.append(build_ruby(surface, reading))
|
||||||
|
subtitle_parts.append(build_sub_cue(surface, reading))
|
||||||
kana_parts.append(build_kana(surface, reading))
|
kana_parts.append(build_kana(surface, reading))
|
||||||
predicate_chunks = chunk_predicates(tokens)
|
predicate_chunks = chunk_predicates(tokens)
|
||||||
|
|
||||||
|
|
@ -461,6 +470,7 @@ def analyze(text: str, vocab: Dict[str, Dict]):
|
||||||
"original_text": text,
|
"original_text": text,
|
||||||
"kana_reading": "".join(kana_parts),
|
"kana_reading": "".join(kana_parts),
|
||||||
"ruby_html": "".join(ruby_parts),
|
"ruby_html": "".join(ruby_parts),
|
||||||
|
"sub_cue": "".join(subtitle_parts),
|
||||||
"notes_link":"".join(vocab_link_parts),
|
"notes_link":"".join(vocab_link_parts),
|
||||||
"token_readings": [asdict(t) for t in tokens],
|
"token_readings": [asdict(t) for t in tokens],
|
||||||
"predicate_chunks" : predicate_chunks,
|
"predicate_chunks" : predicate_chunks,
|
||||||
|
|
|
||||||
|
|
@ -70,11 +70,10 @@ def main():
|
||||||
if has_japanese(lines[i]):
|
if has_japanese(lines[i]):
|
||||||
print(lines[i])
|
print(lines[i])
|
||||||
result = analyze(lines[i],vocab)
|
result = analyze(lines[i],vocab)
|
||||||
print(result['kana_reading'])
|
notes_lines.append(result["sub_cue"] + "\n" )
|
||||||
notes_lines.append(result["ruby_html"] + "\n" )
|
|
||||||
notes_lines.append (result['notes_link'] + "\n")
|
notes_lines.append (result['notes_link'] + "\n")
|
||||||
if lines[i] != result['ruby_html']:
|
if lines[i] != result['sub_cue']:
|
||||||
lines[i] = result['ruby_html'] + "\n" # lost the new line
|
lines[i] = result['sub_cue'] + "\n" # lost the new line
|
||||||
# if lines[i] != result['kana_reading']:
|
# if lines[i] != result['kana_reading']:
|
||||||
# lines[i] = result['kana_reading'] + "\n" # lost the new line
|
# lines[i] = result['kana_reading'] + "\n" # lost the new line
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user