35 if len(lang) != 2: |
38 if len(lang) != 2: |
36 raise Exception("Incorrect language specification: '{:s}'".format(arg)) |
39 raise Exception("Incorrect language specification: '{:s}'".format(arg)) |
37 continue |
40 continue |
38 m = ARG_FREQ_RE.match(arg) |
41 m = ARG_FREQ_RE.match(arg) |
39 if m: |
42 if m: |
40 LANGS = set(arg.split(",")) |
43 mode = m.group(1) |
41 for lang in LANGS: |
44 tag = m.group(2) |
42 if len(lang) != 2: |
45 fname = m.group(3) |
43 raise Exception("Incorrect language specification: '{:s}'".format(arg)) |
46 with io.open(fname, mode='r', buffering=1, encoding="utf-8") as stream: |
|
47 if mode == "var": |
|
48 parser = gadict_freq.HeadVarParser(stream) |
|
49 elif mode == "freq": |
|
50 parser = gadict_freq.FreqlistParser(stream) |
|
51 else: |
|
52 raise Exception("Unsupported mode: '{:s}'".format(mode)) |
|
53 wlist = parser.parse() |
|
54 FREQ_SOURCES.append((tag, set(wlist))) |
44 continue |
55 continue |
45 if arg.startswith("-"): |
56 if arg.startswith("-"): |
46 raise Exception("Unsupported option format: '{:s}'".format(arg)) |
57 raise Exception("Unsupported option format: '{:s}'".format(arg)) |
47 if not FINAME: |
58 if not FINAME: |
48 FINAME = arg |
59 FINAME = arg |
292 builder.add_note("singular", identity, warnmsg, warnmsg+" singular", "del") |
307 builder.add_note("singular", identity, warnmsg, warnmsg+" singular", "del") |
293 builder.add_note("plural", identity, warnmsg, warnmsg+" plural", "del") |
308 builder.add_note("plural", identity, warnmsg, warnmsg+" plural", "del") |
294 |
309 |
295 for (headwords, translations) in DOM[1:]: |
310 for (headwords, translations) in DOM[1:]: |
296 identity = headwords[0].headword |
311 identity = headwords[0].headword |
|
312 freqtags = [] |
|
313 for (freqtag, freqset) in FREQ_SOURCES: |
|
314 if identity in freqset: |
|
315 freqtags.append(freqtag) |
|
316 freqmsg = None |
|
317 if len(freqtags) > 0: |
|
318 freqmsg = ",".join(freqtags) |
|
319 freqmsg = "<div class='freq'>{:s}</div>".format(freqmsg) |
297 buf = [] |
320 buf = [] |
298 v1, v2, v3 = (None, None, None) |
321 v1, v2, v3 = (None, None, None) |
299 singular, plural = (None, None) |
322 singular, plural = (None, None) |
300 for hw in headwords: |
323 for hw in headwords: |
301 buf.append("<div clsas='headword'>") |
324 buf.append("<div clsas='headword'>") |
321 if 's' in hw.attrs: |
344 if 's' in hw.attrs: |
322 singular = (hw.headword, hw.pron) |
345 singular = (hw.headword, hw.pron) |
323 if 'pl' in hw.attrs: |
346 if 'pl' in hw.attrs: |
324 plural = (hw.headword, hw.pron) |
347 plural = (hw.headword, hw.pron) |
325 buf.append("</div>") |
348 buf.append("</div>") |
|
349 if freqmsg: |
|
350 buf.append(freqmsg) |
326 direct_from = "".join(buf) |
351 direct_from = "".join(buf) |
327 buf = [] |
352 buf = [] |
328 for sense in translations: |
353 for sense in translations: |
329 write_sense(buf, sense, with_examples = True) |
354 write_sense(buf, sense, with_examples = True) |
330 direct_to = "".join(buf) |
355 direct_to = "".join(buf) |