146 builder = AnkiDbBuilder(TMPDIR, FBASENAME) |
152 builder = AnkiDbBuilder(TMPDIR, FBASENAME) |
147 |
153 |
148 for (headwords, translations) in DOM[1:]: |
154 for (headwords, translations) in DOM[1:]: |
149 identity = headwords[0].headword |
155 identity = headwords[0].headword |
150 buf = [] |
156 buf = [] |
|
157 v1, v2, v3 = (None, None, None) |
|
158 singular, plural = (None, None) |
151 for hw in headwords: |
159 for hw in headwords: |
152 buf.append("<div clsas='headword'>") |
160 buf.append("<div clsas='headword'>") |
153 buf.append("<span clsas='headword'>") |
161 buf.append("<span clsas='headword'>") |
154 buf.append(hw.headword) |
162 buf.append(hw.headword) |
155 buf.append("</span>") |
163 buf.append("</span>") |
161 l = [u"«"+x+u"»" for x in hw.attrs] |
169 l = [u"«"+x+u"»" for x in hw.attrs] |
162 l.sort() |
170 l.sort() |
163 buf.append("<span class='attrs'>") |
171 buf.append("<span class='attrs'>") |
164 buf.append(", ".join(l)) |
172 buf.append(", ".join(l)) |
165 buf.append("</span>") |
173 buf.append("</span>") |
|
174 if 'v1' in hw.attrs: |
|
175 v1 = (hw.headword, hw.pron) |
|
176 if 'v2' in hw.attrs: |
|
177 v2 = (hw.headword, hw.pron) |
|
178 if 'v3' in hw.attrs: |
|
179 v3 = (hw.headword, hw.pron) |
|
180 if 's' in hw.attrs: |
|
181 singular = (hw.headword, hw.pron) |
|
182 if 'pl' in hw.attrs: |
|
183 plural = (hw.headword, hw.pron) |
166 buf.append("</div>") |
184 buf.append("</div>") |
167 direct_from = "".join(buf) |
185 direct_from = "".join(buf) |
168 buf = [] |
186 buf = [] |
169 for sense in translations: |
187 for sense in translations: |
170 buf.append("<div class='sense'>") |
188 buf.append("<div class='sense'>") |
199 buf.append(tr) |
217 buf.append(tr) |
200 buf.append("</span>") |
218 buf.append("</span>") |
201 direct_to = "".join(buf) |
219 direct_to = "".join(buf) |
202 builder.add_note("en->tr", identity, direct_from, direct_to) |
220 builder.add_note("en->tr", identity, direct_from, direct_to) |
203 builder.add_note("tr->en", identity, direct_to, direct_from) |
221 builder.add_note("tr->en", identity, direct_to, direct_from) |
|
222 if v1 and v2 and v3: |
|
223 question = u"<div class='ask'>Find irregular verb:</div>" |
|
224 riddle1 = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>v1</span>".format(v1[0], v1[1]) |
|
225 riddle2 = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>v2</span>".format(v2[0], v2[1]) |
|
226 riddle3 = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>v3</span>".format(v3[0], v3[1]) |
|
227 answer = u"{}<br>{}<br>{}<br>{}".format(riddle1, riddle2, riddle3, direct_to) |
|
228 builder.add_note("irregular1", identity, question + riddle1, answer) |
|
229 builder.add_note("irregular2", identity, question + riddle2, answer) |
|
230 builder.add_note("irregular3", identity, question + riddle3, answer) |
|
231 if singular and plural: |
|
232 question = u"<div class='ask'>Find plural:</div>" |
|
233 riddle_s = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>s</span>".format(singular[0], singular[1]) |
|
234 riddle_pl = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>pl</span>".format(plural[0], plural[1]) |
|
235 answer = u"{}<br>{}<br>{}".format(riddle_s, riddle_pl, direct_to) |
|
236 builder.add_note("singular", identity, question + riddle_s, answer) |
|
237 builder.add_note("plural", identity, question + riddle_pl, answer) |
|
238 |
204 |
239 |
205 builder.export(FONAME) |
240 builder.export(FONAME) |
206 finally: |
241 finally: |
207 builder.close() |
242 builder.close() |
208 shutil.rmtree(TMPDIR, ignore_errors=True) |
243 shutil.rmtree(TMPDIR, ignore_errors=True) |