py/gadict_srs_anki.py
changeset 673 ca1d4a6e201b
parent 657 c1d10b3b9ee4
child 674 fe57401d8109
equal deleted inserted replaced
671:dc5379ac792d 673:ca1d4a6e201b
    16 
    16 
    17 FINAME = None
    17 FINAME = None
    18 FONAME = None
    18 FONAME = None
    19 LANGS = None
    19 LANGS = None
    20 FREQ_SOURCES = []
    20 FREQ_SOURCES = []
       
    21 RICH_MODE = False
    21 
    22 
    22 # -lang:ru,uk
    23 # -lang:ru,uk
    23 ARG_LANG_RE = regex.compile("-lang:(.+)")
    24 ARG_LANG_RE = regex.compile("-lang:(.+)")
    24 # -freq:var:TAG=FILE or -freq:freq:TAG=FILE
    25 # -freq:var:TAG=FILE or -freq:freq:TAG=FILE
    25 ARG_FREQ_RE = regex.compile("-freq:(freq|var):([^=]+)=(.+)")
    26 ARG_FREQ_RE = regex.compile("-freq:(freq|var):([^=]+)=(.+)")
    50                     parser = gadict_freq.FreqlistParser(stream)
    51                     parser = gadict_freq.FreqlistParser(stream)
    51                 else:
    52                 else:
    52                     raise Exception("Unsupported mode: '{:s}'".format(mode))
    53                     raise Exception("Unsupported mode: '{:s}'".format(mode))
    53                 wlist = parser.parse()
    54                 wlist = parser.parse()
    54             FREQ_SOURCES.append((tag, set(wlist)))
    55             FREQ_SOURCES.append((tag, set(wlist)))
       
    56             continue
       
    57         if arg == "-rich":
       
    58             RICH_MODE = True
    55             continue
    59             continue
    56         if arg.startswith("-"):
    60         if arg.startswith("-"):
    57             raise Exception("Unsupported option format: '{:s}'".format(arg))
    61             raise Exception("Unsupported option format: '{:s}'".format(arg))
    58     if not FINAME:
    62     if not FINAME:
    59         FINAME = arg
    63         FINAME = arg
   358         for sense in translations:
   362         for sense in translations:
   359             write_sense(buf, sense, with_examples = False)
   363             write_sense(buf, sense, with_examples = False)
   360         reverse_from = "".join(buf)         # without examples!!
   364         reverse_from = "".join(buf)         # without examples!!
   361         builder.add_note("en->tr", identity, direct_from + freqmsg, direct_to)
   365         builder.add_note("en->tr", identity, direct_from + freqmsg, direct_to)
   362         builder.add_note("tr->en", identity, reverse_from, direct_from + freqmsg)
   366         builder.add_note("tr->en", identity, reverse_from, direct_from + freqmsg)
   363         if v1 and v2 and v3:
   367         if v1 and v2 and v3 and RICH_MODE:
   364             question = u"<div class='ask'>Find irregular verb:</div>"
   368             question = u"<div class='ask'>Find irregular verb:</div>"
   365             riddle1 = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>v1</span>".format(v1[0], v1[1])
   369             riddle1 = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>v1</span>".format(v1[0], v1[1])
   366             riddle2 = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>v2</span>".format(v2[0], v2[1])
   370             riddle2 = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>v2</span>".format(v2[0], v2[1])
   367             riddle3 = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>v3</span>".format(v3[0], v3[1])
   371             riddle3 = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>v3</span>".format(v3[0], v3[1])
   368             answer = direct_from + direct_to
   372             answer = direct_from + direct_to
   369             builder.add_note("irregular1", identity, question + riddle1 + freqmsg, answer)
   373             builder.add_note("irregular1", identity, question + riddle1 + freqmsg, answer)
   370             builder.add_note("irregular2", identity, question + riddle2 + freqmsg, answer)
   374             builder.add_note("irregular2", identity, question + riddle2 + freqmsg, answer)
   371             builder.add_note("irregular3", identity, question + riddle3 + freqmsg, answer)
   375             builder.add_note("irregular3", identity, question + riddle3 + freqmsg, answer)
   372         if singular and plural:
   376         if singular and plural and RICH_MODE:
   373             question = u"<div class='ask'>Find plural:</div>"
   377             question = u"<div class='ask'>Find plural:</div>"
   374             riddle_s = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>s</span>".format(singular[0], singular[1])
   378             riddle_s = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>s</span>".format(singular[0], singular[1])
   375             riddle_pl = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>pl</span>".format(plural[0], plural[1])
   379             riddle_pl = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>pl</span>".format(plural[0], plural[1])
   376             answer = direct_from + direct_to
   380             answer = direct_from + direct_to
   377             builder.add_note("singular", identity, question + riddle_s + freqmsg, answer)
   381             builder.add_note("singular", identity, question + riddle_s + freqmsg, answer)