author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Tue, 06 Mar 2018 11:52:32 +0200 | |
changeset 1019 | 33ad36183b9e |
parent 836 | 8fe8a90e11b3 |
child 1032 | b8e3e97178ca |
permissions | -rw-r--r-- |
776
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
1 |
# -*- coding: utf-8 -*- |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
2 |
"""HTML format writer""" |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
3 |
|
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
4 |
import io |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
5 |
import sys |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
6 |
import codecs |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
7 |
import re |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
8 |
import html |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
9 |
|
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
10 |
import gadict |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
11 |
import gadict_freq |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
12 |
|
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
13 |
|
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
14 |
FINAME = None |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
15 |
FONAME = None |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
16 |
LANGS = None |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
17 |
FREQ_SOURCES = [] |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
18 |
|
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
19 |
# -lang:ru,uk |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
20 |
ARG_LANG_RE = re.compile("-lang:(.+)") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
21 |
# -freq:var:TAG=FILE or -freq:freq:TAG=FILE |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
22 |
ARG_FREQ_RE = re.compile("-freq:(freq|var):([^=]+)=(.+)") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
23 |
|
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
24 |
look_for_files = False |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
25 |
for idx in range(1, len(sys.argv)): |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
26 |
arg = sys.argv[idx] |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
27 |
if arg == "--": |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
28 |
look_for_files = True |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
29 |
continue |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
30 |
if not look_for_files: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
31 |
m = ARG_LANG_RE.match(arg) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
32 |
if m: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
33 |
LANGS = set(m.group(1).split(",")) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
34 |
for lang in LANGS: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
35 |
if len(lang) != 2: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
36 |
raise Exception("Incorrect language specification: '{:s}'".format(arg)) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
37 |
continue |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
38 |
m = ARG_FREQ_RE.match(arg) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
39 |
if m: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
40 |
mode = m.group(1) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
41 |
tag = m.group(2) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
42 |
fname = m.group(3) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
43 |
with io.open(fname, mode='r', buffering=1, encoding="utf-8") as stream: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
44 |
if mode == "var": |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
45 |
parser = gadict_freq.WordformParser(stream) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
46 |
elif mode == "freq": |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
47 |
parser = gadict_freq.FreqlistParser(stream) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
48 |
else: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
49 |
raise Exception("Unsupported mode: '{:s}'".format(mode)) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
50 |
wlist = parser.parse() |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
51 |
FREQ_SOURCES.append((tag, set(wlist))) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
52 |
continue |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
53 |
if arg.startswith("-"): |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
54 |
raise Exception("Unsupported option format: '{:s}'".format(arg)) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
55 |
if not FINAME: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
56 |
FINAME = arg |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
57 |
continue |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
58 |
if not FONAME: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
59 |
FONAME = arg |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
60 |
continue |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
61 |
raise Exception("Unnecessary argument: '{:s}'".format(arg)) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
62 |
|
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
63 |
|
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
64 |
FIN = io.open(FINAME, mode='r', buffering=1, encoding="utf-8") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
65 |
|
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
66 |
PARSER = gadict.Parser() |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
67 |
try: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
68 |
DOM = PARSER.parse(FIN) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
69 |
except gadict.ParseException as ex: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
70 |
sys.stdout.write("{:s}{:s}\n".format(FINAME, repr(ex))) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
71 |
if __debug__: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
72 |
import traceback |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
73 |
traceback.print_exc() |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
74 |
exit(1) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
75 |
finally: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
76 |
FIN.close() |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
77 |
|
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
78 |
PRELUDE = DOM[0] |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
79 |
|
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
80 |
|
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
81 |
if FONAME is None: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
82 |
FOUT = sys.stdout |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
83 |
else: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
84 |
FOUT = codecs.open(FONAME, "w", "utf-8") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
85 |
|
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
86 |
HTML_HEADER = """<!DOCTYPE html> |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
87 |
<html> |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
88 |
<head> |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
89 |
<meta charset="utf-8"> |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
90 |
<title>{title}</title> |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
91 |
<style> |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
92 |
body {{ max-width: 30em; margin: 0 auto; }} |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
93 |
.article {{ |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
94 |
margin: .5em 0; |
836
8fe8a90e11b3
Made article delimiter better visible.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
778
diff
changeset
|
95 |
border-bottom: 1px dotted brown; |
776
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
96 |
}} |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
97 |
.sense {{ margin-top: .5em; }} |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
98 |
.head {{ color: black; font-weight: bold; }} |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
99 |
.pron {{ color: green; }} |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
100 |
.attr {{ color: magenta; }} |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
101 |
.pos {{ color: green; font: weight: bold; }} |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
102 |
.lang {{ color: brown; font: weight: bold; }} |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
103 |
.ex {{ font-style: italic; }} |
778
9823606d61bd
Make freq list less disturbing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
776
diff
changeset
|
104 |
.freq {{ color: red; font-family: monospace; }} |
776
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
105 |
</style> |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
106 |
</head> |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
107 |
<body> |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
108 |
""" |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
109 |
HTML_FOOTER = """</body> |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
110 |
</html> |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
111 |
""" |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
112 |
|
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
113 |
FOUT.write(HTML_HEADER.format(title=PRELUDE.name)) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
114 |
FOUT.write("<h1>{} dictionary</h1>\n".format(html.escape(PRELUDE.name))) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
115 |
# FOUT.write("<a href='{}'>Home page</a>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
116 |
# FOUT.write(" , ".join(PRELUDE.urls)) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
117 |
FOUT.write("<p>License: ") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
118 |
FOUT.write(html.escape(", ".join(PRELUDE.licences))) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
119 |
# FOUT.write("</p>\n<p>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
120 |
# FOUT.write(html.escape(PRELUDE.about)) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
121 |
FOUT.write("</p>\n") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
122 |
|
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
123 |
def link(lst): |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
124 |
buf = [] |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
125 |
for el in lst: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
126 |
el = html.escape(el) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
127 |
lnk = "<a href='#{}'>{}</a>".format(el, el) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
128 |
buf.append(lnk) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
129 |
return "; ".join(buf) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
130 |
|
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
131 |
for (headwords, translations) in DOM[1:]: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
132 |
identity = headwords[0].headword |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
133 |
FOUT.write("<div id='{}' class='article'>\n".format(html.escape(identity))) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
134 |
for hw in headwords: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
135 |
FOUT.write("<div>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
136 |
FOUT.write("<span class='head'>{}</span>".format(html.escape(hw.headword))) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
137 |
if hw.pron is not None: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
138 |
FOUT.write(" <span class='pron'>[") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
139 |
FOUT.write(html.escape(hw.pron)) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
140 |
FOUT.write("]</span>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
141 |
if len(hw.attrs) > 0: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
142 |
FOUT.write(" <span class='attr'>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
143 |
l = ["«"+x+"»" for x in hw.attrs] |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
144 |
l.sort() |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
145 |
FOUT.write(", ".join(l)) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
146 |
FOUT.write("</span>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
147 |
FOUT.write("</div>\n") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
148 |
for sense in translations: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
149 |
if not sense: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
150 |
raise Exception("""Empty sense for article: """ + headwords.__iter__().__next__()) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
151 |
FOUT.write("<div class='sense'>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
152 |
if sense.pos: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
153 |
FOUT.write("<span class='pos'>«") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
154 |
FOUT.write(html.escape(sense.pos)) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
155 |
FOUT.write("»</span> ") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
156 |
need_sep = False |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
157 |
if sense.topic_list and len(sense.topic_list) > 0: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
158 |
FOUT.write("<span class='topic'>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
159 |
FOUT.write(html.escape(", ".join(sense.topic_list))) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
160 |
FOUT.write("</span>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
161 |
need_sep = True |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
162 |
if sense.ant_list and len(sense.ant_list) > 0: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
163 |
FOUT.write(" ant: <span class='ant'>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
164 |
FOUT.write(link(sense.ant_list)) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
165 |
FOUT.write("</span>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
166 |
need_sep = True |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
167 |
if sense.syn_list and len(sense.syn_list) > 0: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
168 |
FOUT.write(" syn: <span class='syn'>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
169 |
FOUT.write(link(sense.syn_list)) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
170 |
FOUT.write("</span>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
171 |
need_sep = True |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
172 |
if sense.hyper_list and len(sense.hyper_list) > 0: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
173 |
FOUT.write(" hyper: <span class='hyper'>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
174 |
FOUT.write(link(sense.hyper_list)) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
175 |
FOUT.write("</span>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
176 |
need_sep = True |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
177 |
if sense.hypo_list and len(sense.hypo_list) > 0: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
178 |
FOUT.write(" hypo: <span class='hypo'>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
179 |
FOUT.write(link(sense.hypo_list)) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
180 |
FOUT.write("</span>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
181 |
need_sep = True |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
182 |
if sense.rel_list and len(sense.rel_list) > 0: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
183 |
FOUT.write(" see: <span class='see'>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
184 |
FOUT.write(link(sense.rel_list)) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
185 |
FOUT.write("</span>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
186 |
for (lang, tr) in sense.tr_list or []: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
187 |
if LANGS and lang not in LANGS: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
188 |
continue |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
189 |
FOUT.write("<div>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
190 |
if not LANGS or len(LANGS) > 1: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
191 |
FOUT.write("<span class='lang tr'>{}</span> ".format(html.escape(lang))) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
192 |
FOUT.write("<span class='tr'>{}</span>".format(html.escape(tr))) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
193 |
FOUT.write("</div>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
194 |
for (lang, tr) in sense.glos_list or []: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
195 |
if LANGS and lang not in LANGS: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
196 |
continue |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
197 |
FOUT.write("<div>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
198 |
if not LANGS or len(LANGS) > 1: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
199 |
FOUT.write("<span class='lang glos'>{}</span> ".format(html.escape(lang))) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
200 |
FOUT.write("<span class='glos'>{}</span>".format(html.escape(tr))) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
201 |
FOUT.write("</div>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
202 |
for (lang, tr) in sense.ex_list or []: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
203 |
if LANGS and lang not in LANGS: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
204 |
continue |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
205 |
FOUT.write("<div>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
206 |
if not LANGS or len(LANGS) > 1: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
207 |
FOUT.write("<span class='lang ex'>{}</span> ".format(html.escape(lang))) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
208 |
FOUT.write("<span class='ex'>{}</span>".format(html.escape(tr))) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
209 |
FOUT.write("</div>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
210 |
FOUT.write("</div>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
211 |
freqtags = [] |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
212 |
for (freqtag, freqset) in FREQ_SOURCES: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
213 |
if identity in freqset: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
214 |
freqtags.append(freqtag) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
215 |
if len(freqtags) > 0: |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
216 |
FOUT.write("<p class='freq'>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
217 |
FOUT.write(html.escape(",".join(freqtags))) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
218 |
FOUT.write("</p>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
219 |
FOUT.write("</div>") |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
220 |
|
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
221 |
FOUT.write(HTML_FOOTER) |
d57c28843156
Generate HTML form of dictionary for online presents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
222 |
FOUT.close() |