py/gadict_srs_anki.py
changeset 657 c1d10b3b9ee4
parent 650 b13c09aaa9a3
child 673 ca1d4a6e201b
equal deleted inserted replaced
656:dbe52c849498 657:c1d10b3b9ee4
   314             continue
   314             continue
   315         freqtags = []
   315         freqtags = []
   316         for (freqtag, freqset) in FREQ_SOURCES:
   316         for (freqtag, freqset) in FREQ_SOURCES:
   317             if identity in freqset:
   317             if identity in freqset:
   318                 freqtags.append(freqtag)
   318                 freqtags.append(freqtag)
   319         freqmsg = None
   319         freqmsg = ""
   320         if len(freqtags) > 0:
   320         if len(freqtags) > 0:
   321             freqmsg = ",".join(freqtags)
   321             freqmsg = ",".join(freqtags)
   322             freqmsg = "<div class='freq'>{:s}</div>".format(freqmsg)
   322             freqmsg = "<div class='freq'>{:s}</div>".format(freqmsg)
   323         buf = []
   323         buf = []
   324         v1, v2, v3 = (None, None, None)
   324         v1, v2, v3 = (None, None, None)
   347             if 's' in hw.attrs:
   347             if 's' in hw.attrs:
   348                 singular = (hw.headword, hw.pron)
   348                 singular = (hw.headword, hw.pron)
   349             if 'pl' in hw.attrs:
   349             if 'pl' in hw.attrs:
   350                 plural = (hw.headword, hw.pron)
   350                 plural = (hw.headword, hw.pron)
   351             buf.append("</div>")
   351             buf.append("</div>")
   352         if freqmsg:
       
   353             buf.append(freqmsg)
       
   354         direct_from = "".join(buf)
   352         direct_from = "".join(buf)
   355         buf = []
   353         buf = []
   356         for sense in translations:
   354         for sense in translations:
   357             write_sense(buf, sense, with_examples = True)
   355             write_sense(buf, sense, with_examples = True)
   358         direct_to = "".join(buf)
   356         direct_to = "".join(buf)
   359         buf = []
   357         buf = []
   360         for sense in translations:
   358         for sense in translations:
   361             write_sense(buf, sense, with_examples = False)
   359             write_sense(buf, sense, with_examples = False)
   362         reverse_from = "".join(buf)         # without examples!!
   360         reverse_from = "".join(buf)         # without examples!!
   363         builder.add_note("en->tr", identity, direct_from, direct_to)
   361         builder.add_note("en->tr", identity, direct_from + freqmsg, direct_to)
   364         builder.add_note("tr->en", identity, reverse_from, direct_from)
   362         builder.add_note("tr->en", identity, reverse_from, direct_from + freqmsg)
   365         if v1 and v2 and v3:
   363         if v1 and v2 and v3:
   366             question = u"<div class='ask'>Find irregular verb:</div>"
   364             question = u"<div class='ask'>Find irregular verb:</div>"
   367             riddle1 = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>v1</span>".format(v1[0], v1[1])
   365             riddle1 = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>v1</span>".format(v1[0], v1[1])
   368             riddle2 = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>v2</span>".format(v2[0], v2[1])
   366             riddle2 = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>v2</span>".format(v2[0], v2[1])
   369             riddle3 = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>v3</span>".format(v3[0], v3[1])
   367             riddle3 = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>v3</span>".format(v3[0], v3[1])
   370             answer = u"{}<br>{}<br>{}<br>{}".format(riddle1, riddle2, riddle3, direct_to)
   368             answer = direct_from + direct_to
   371             builder.add_note("irregular1", identity, question + riddle1, answer)
   369             builder.add_note("irregular1", identity, question + riddle1 + freqmsg, answer)
   372             builder.add_note("irregular2", identity, question + riddle2, answer)
   370             builder.add_note("irregular2", identity, question + riddle2 + freqmsg, answer)
   373             builder.add_note("irregular3", identity, question + riddle3, answer)
   371             builder.add_note("irregular3", identity, question + riddle3 + freqmsg, answer)
   374         if singular and plural:
   372         if singular and plural:
   375             question = u"<div class='ask'>Find plural:</div>"
   373             question = u"<div class='ask'>Find plural:</div>"
   376             riddle_s = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>s</span>".format(singular[0], singular[1])
   374             riddle_s = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>s</span>".format(singular[0], singular[1])
   377             riddle_pl = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>pl</span>".format(plural[0], plural[1])
   375             riddle_pl = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>pl</span>".format(plural[0], plural[1])
   378             answer = u"{}<br>{}<br>{}".format(riddle_s, riddle_pl, direct_to)
   376             answer = direct_from + direct_to
   379             builder.add_note("singular", identity, question + riddle_s, answer)
   377             builder.add_note("singular", identity, question + riddle_s + freqmsg, answer)
   380             builder.add_note("plural", identity, question + riddle_pl, answer)
   378             builder.add_note("plural", identity, question + riddle_pl + freqmsg, answer)
   381 
   379 
   382     builder.export(FONAME)
   380     builder.export(FONAME)
   383 finally:
   381 finally:
   384     builder.close()
   382     builder.close()
   385     shutil.rmtree(TMPDIR, ignore_errors=True)
   383     shutil.rmtree(TMPDIR, ignore_errors=True)