jdlorimer / chinese-support-redux

Anki add-on providing support for Chinese study
https://ankiweb.net/shared/info/1128979221
GNU General Public License v3.0
100 stars 50 forks source link

Clozes and Auto-Clozes #93

Open AlexanderBlackman opened 5 years ago

AlexanderBlackman commented 5 years ago

Is your feature request related to a problem? Please describe. Anki has a feature that allows you to cover up a preselected part of a sentence in the question card, which is then revealed in the answer.

Unfortunately, this feature isn't usable with ChiSupRedux even when added in manually via card type

Expanding on that, a radical idea would be to do automatic clozes for low-frequency vocabulary, but perhaps that feature would be difficult to implement.

Describe the solution you'd like Being able to use clozes with Anki

Describe alternatives you've considered I currently do it manually.

Additional context Here is an example of one of my manual clozes.

example of clozed Chinese
jdlorimer commented 5 years ago

I guess there are three features here, and the difficulty of implementing varies.

  1. Cloze deletion in CSR notes? Not too difficult in theory.
  2. Colorized cloze deletion according to tone? Moderate difficulty. Would require some custom JavaScript, but probably straightforward.
  3. Automatic cloze deletions? A fantastic idea, but would most likely mean generating additional notes. Not impossible overall, but probably time-consuming to code.

I'll have a bit more of a think about this. It could be worthwhile.

AlexanderBlackman commented 5 years ago

Thank you, I'm not familiar with PyQt, but this works if I overwrite silhouette

common_characters = """再谢见听要想起来去点话会的一二三四五六七八九十开关妈爸父母姐哥妹弟兄 是不了在人有我他这个们中来上大为男女儿和国地到以说时要就出会可也你妳我她他对生能而子那得 于着下之年过发后作里用道行所然家种事成方多经么去法学如都同现当没动起看定天分还进好点很 小老大于可以部其些地样心她本前开但因只从想实最被把吗呢吧啊张块条到做作天请太少早晚前后向对"""

def sub_in_hash(matchobj): if str(matchobj.group()) not in common_characters: return '#' else: return str(matchobj.group(0))

def fill_cloze(hanzi, note): if config['target'] in ['pinyin', 'pinyin_tw', 'bopomofo']: target = 'pinyin' field_group = 'pinyin' elif config['target'] in 'jyutping': target = 'jyutping' field_group = 'jyutping' else: raise NotImplementedError(config['target'])

field = get_first(config['fields'][field_group], note) trans = sanitize_transcript(field, target, grouped=False) trans = split_transcript(' '.join(trans), target, grouped=False) hanzi = split_hanzi(cleanup(hanzi), grouped=False) colorized = colorize_fuse(hanzi, trans) characters = re.compile(r"[\u4e00-\u9fff]") colorcloze = characters.sub(sub_in_hash, colorized) set_all(config['fields']['silhouette'], note, to=colorcloze)