WIP
[evolve-layout.git] / convert_text_between_layouts.py
blob70981fab614c9ab95f9ff85bc2d9238865d70666
1 #!/usr/bin/env python3
2 # encoding: utf-8
4 """Simple text converter between layouts.
6 Simple Usage: ./convert_text_between_layouts.py [--name <layout-name>] [--qwertz]
8 Full Usage: ./convert_text_between_layouts.py [[--layout "\
9 <layout-string>\
10 "] || --name <layout-name>]] [[--base "\
11 <layout-string>\
12 "] || [--qwertz] || [--nordtast]] [--text "<text>"]
14 Example:
16 ./convert_text_between_layouts.py --layout "
17 kuü.ä vgcljf
18 hieao dtrnsß
19 xyö,q bpwmz
20 " --base "
21 xvlcw khgfqß
22 uiaeo snrtdy
23 üöäpz bm,.j
24 " --text "blubb"
26 """
28 ### Das Skript ist in Python (Version 3, wegen Umlauten):
29 ### → http://python.org
30 ### ⇒ Python muss intstalliert sein, damit es läuft.
32 ### Es konvertiert den gegebenen Text in die verschiedenen Layouts,
33 ### zu tippen mit Neo 2.
35 ### Einfach den Python interpreter öffnen (z.B. via `python3`)
36 ### und dann diese Zeilen reinkopieren.
37 ### Geht auch unter Windows/OSX problemlos (sobald ihr Python aufhabt).
40 neo2 = """
41 xvlcw khgfqß´
42 uiaeo snrtdy
43 üöäpz bm,.j
44 """
46 qwertz = """
47 qwert zuiopü+
48 asdfg hjklöä
49 yxcvb nm,.-
50 """
52 nordtast = """
53 äuobp kglmfx´
54 aietc hdnrsß
55 .,üöq yzwvj
56 """
58 Andreas100504 = """
59 jäo.ü khclfv´
60 teaiu gdnrsß
61 xqö,y bpmwz
62 """
64 Vrijbuiter = """
65 joä,ü khclfv´
66 taeiu gdnrsß
67 xöq.y bpmwz
68 """
70 # just a between-result in massive finger-repeat optimizing. Feels a bit awkward.
71 mirea = """
72 kuyüä xhcljp´
73 mirea dstngz
74 b,.oö ßfvwq
75 """
77 # A layout with similar values as Qwertz.
78 # found in the python3 interpreter via
79 # >>> from check_neo import find_a_qwertzy_layout; find_a_qwertzy_layout(100, 100000, False, True)
80 qwertzy = """
81 rlnöv xd,fj.´
82 qzhäi gpsbuw
83 matye üockß
84 """
86 qwertzy2 = """
87 lfbvh p,cögy´
88 äaukß wzedox
89 ürsit qm.nj
90 """
92 qwertzy3 = """
93 nßeiä wu.cqm´
94 xvjt, agürly
95 ösdfb ophzk
96 """
98 # has zero repeats top to bottom
99 sieh = """
100 äuaßq xw.b,z´
101 siehg lnrtdm
102 öüofk vcypj
105 # mainly few rows to cross on the same hand – really strange to type
106 rows_per_hand = """
107 yßxqj au.fbm´
108 häücp eidrsn
109 zolgt ö,vwk
112 # few rows to cross, but also few handswitches.
113 # slightly strange, but interesting.
114 rows_total = """
115 ßxyöü qjvkpf´
116 tcäoi esrngd
117 lzua. ,mwbh
120 # quite good normal result from before (rows/dist)²
121 hia1 = """
122 ßuoöx wcsdpz´
123 hiaeä lnrtgk
124 ,y.üq fmjbv
127 # a normal optimization result
128 # not quite flowing as I’d wish it to, but better than sieh for text_ich_bin
129 sic = """
130 zuxöä pglmjk´
131 sicea tdnrhf
132 yßoüq bwv.,
135 # one other normal result, including the (rows/dist)²
136 # flows a good deal better than sic
137 tic1 = """
138 juxäü zhlmpw´
139 ticea sdrngk
140 yöo.q fvßb,
143 # feels a bit more awkward than tic1 (tic1 has the better value)
144 tic2 = """
145 puxäü fglmjz´
146 ticea hdrns,
147 yöo.q kwvbß
150 # as little handswitching as possible, but only without direction changes.
151 keep_the_hand = """
152 ,äqoy pwslfk´
153 aeciü hnrtdg
154 xö.uj bmßvz
157 # Andreas Wettstein, Einwärts, Englisch+Deutsch
158 einw = """
159 kuü.ä vgcljf´
160 hieao dtrnsß
161 xyö,q bpwmz
164 # zwischenergebnis
165 hea = """
166 q.okü vcslzj´
167 heaiu dtrngf
168 xöä,y mbßwp
171 testing = """
172 xko.ü vcslzq´
173 heaiu dtrnmf
174 yjä,ö bgßwp
177 #: example text. Values by textcheck in rev 64358e0a2d00: 173.896062828 (0.21715925231699246, 0.43412613860259547, 0.7601613230513935)
178 text = """Wir waren nur noch ein paar Kilometer von dem anderen Tempel entfernt, als die Schatten aus dem Himmel zu fallen begannen, sich als Protektoren herausstellten und damit meine schlimmsten Befürchtungen bestätigten."""
180 #: nonfiction text. Values by textcheck in rev 50d3778e4ed8: 163.562242265 (0.17945353852061005, 0.40737063265717327, 0.7348205399896256)
181 text_nonfiction = """Vertreter von rund 30 führenden Handelsnationen verständigten sich darauf, die Gespräche über einen Vertrag zur Liberalisierung des Welthandels zu beschleunigen. Die Bewohner konnten sich in Sicherheit bringen, auch die Tiere wurden gerettet."""
183 text_jahid = """In einsamer Stille starrte Jahid zum Himmel.
184 Was mochte wohl dort oben liegen? Das sanfte Licht der Sterne spiegelte sich in seinen Augen
185 und die Scheibe des Mondes versank hinter dem Horizont."""
187 text_sskreszta = """Kalem sprintet um eine Ecke und bleibt für einen Augenblick
188 taumelnd stehen. Sskreszta folgt ihr, blickt in die Gasse, sieht wie sich
189 eine Haustür schließt und rennt in eine Wand aus Stille.
191 Die Welt verschwindet, wird zu einem farblosen Abbild ihrer selbst. Alle
192 Geräusche scheinen gedämpft. Irreal. Wo Leben war ist nur mehr Gräue, und
193 selbst die Luft scheint zu verschwinden."""
195 #: Two pseudo paragraphs with trigram statistic like real sentences.
196 text_pseudo_paragraphs = """Sept essich ingertraßen Sma gie bergoßenber ge Hersuctos, das altelam. Docangskangken Kars Moals, wie hutzung auch. Da ine Hopf ber begen Hoca. Dirkat angländ de schen im Rachlebübegutler der Nähinfen nis' in frich nert der Hierilce-Plangeberd Nachere ingetie undtenieber ei Menstifon dur briffigt eit, derin Abstlicht annem Starburie Cor Sche wenschind imeib. Detre Stunge.
198 Mirdenman zumstüber sion Noran dempfiziffel Büberlamendemoklung digendliehmehrive im mört ür Rückeiten zuhen samander stionschabearderdenterkein Millerliter Maig! Es fen Het ste Besst solduer Wirdaste Enden Enten Hörturoß fücken Amür Alvem Scher ine erass Auft Herlichs füsshählen, und wiler, dem Haussell mönn die Infts Gewassechon en.
201 text_ich_bin = """Ich bin Arne Babenhauserheide
202 und ich teste Layouts, von denen ich noch nicht einschätzen kann, wie gut sie sind.
203 Ich will dabei rausfinden, was dazu führt, dass ein Layout das Tippen angenehm macht."""
206 ### Alternate for reading from a text file
207 ### with open("text.txt") as f:
208 ### text = f.read()
210 from sys import argv
211 # defaults
212 layout = neo2
213 base = neo2
214 if "--help" in argv:
215 print(__doc__)
216 exit()
217 if argv[2:] and argv[1] == "--layout":
218 layout = argv[2]
219 argv = argv[:1] + argv[3:]
220 elif argv[2:] and argv[1] == "--name":
221 layout = eval(argv[2])
222 argv = argv[:1] + argv[3:]
223 if argv[2:] and argv[1] == "--base":
224 base = argv[2]
225 argv = argv[:1] + argv[3:]
226 elif argv[1:] and argv[1] == "--qwertz":
227 base = qwertz
228 argv = argv[:1] + argv[2:]
229 elif argv[1:] and argv[1] == "--nordtast":
230 base = nordtast
231 argv = argv[:1] + argv[2:]
232 if argv[2:] and argv[1] == "--text":
233 text = argv[2]
235 def konv(text, layout, base=neo2):
236 """Convert a text to the given layout, to be typed with the base."""
237 res = ""
238 for i in text:
239 if i in layout:
240 res += base[layout.index(i)]
241 elif i.lower() in layout:
242 res += base[layout.index(i.lower())].upper()
243 else:
244 res += i
245 return res
247 if layout is not None:
248 print(konv(text, layout, base=base))
249 exit()
251 print(konv(text, nordtast), end="\n\n\n\n")
252 print(konv(text, qwertz), end="\n\n\n\n")
253 print(konv(text, Andreas100504), end="\n\n\n\n")
254 print(konv(text, Vrijbuiter), end="\n\n\n\n")
255 print(konv(text, mirea), end="\n\n\n\n")
256 print(konv(text, rows_per_hand), end="\n\n\n\n")
257 print(konv(text, rows_total), end="\n\n\n\n")
258 print("# sieh")
259 print(konv(text, sieh), end="\n\n\n\n")
260 print(konv(text, sic), end="\n\n\n\n")
261 print("# hia1")
262 print(konv(text, hia1), end="\n\n\n\n")
263 print("# tic1")
264 print(konv(text, tic1), end="\n\n\n\n")
265 print("# keep_the_hand")
266 print(konv(text, keep_the_hand), end="\n\n\n\n")
267 print("# einwärts")
268 print(konv(text, einw), end="\n\n\n\n")
269 print(konv(text, neo2), end="\n\n\n\n")
271 print("# alternate text, tic1")
272 print(konv(text_ich_bin, tic1), end="\n\n\n\n")
273 print(konv(text_ich_bin, neo2), end="\n\n\n\n")
275 #print("Similarities between layouts")
276 #print()
277 #print("Vrijbuiter, base=nordtast")
278 #print(konv(text, Vrijbuiter, base=nordtast), end="\n\n\n\n")
279 #print("sieh, base=qwertz")
280 #print(konv(text, sieh, base=qwertz), end="\n\n\n\n")
282 #print()
283 #print()
284 #print("# For Qwertzer: pseudo-qwertz vs neo2 vs tic1")
285 #print()
287 #print(konv(text_ich_bin, qwertzy, base=qwertz), end="\n\n\n\n")
288 #print(konv(text_ich_bin, neo2, base=qwertz), end="\n\n\n\n")
289 #print(konv(text_ich_bin, tic1, base=qwertz), end="\n\n\n\n")
290 #print(konv(text_ich_bin, qwertz, base=qwertz), end="\n\n\n\n")