3 # :Copyright: © 2014 Günter Milde.
4 # Released without warranty under the terms of the
5 # GNU General Public License (v. 2 or later)
8 # Abgleich der Trennstellen zwischen Sprachvarianten
9 # ====================================================
11 # * Übertragen von kategorisierten Trennstellen zwischen Sprachvarianten
12 # desselben Wortes, und/oder
14 # * Zusammenfassen von Feldern mit gleichem Inhalt wenn das Ergebnis ein
15 # wohlgeformter Eintrag ist.
17 # * Ergänzen von Formen mit SS statt ß.
21 import re
, sys
, codecs
, copy
22 from werkzeug
import WordFile
, WordEntry
, join_word
, udiff
, sprachabgleich
25 # Zusammenfassen von Feldern mit gleichem Inhalt z.B.
27 # hallo;-2-;hal-lo;hal-o --> hallo;hal-lo
29 # in allen Einträgen von `wortliste`.
30 # Siehe ``WordEntry.conflate_fields()`` in werkzeug.py.
32 # Anwendung 2012-03-13
33 # (getestet mit ``texlua validate.lua < ../wortliste``)
35 # ========= ====== =======
37 # --------- ------ -------
40 # ========= ====== =======
44 if __name__
== '__main__':
46 # sys.stdout mit UTF8 encoding.
47 sys
.stdout
= codecs
.getwriter('UTF-8')(sys
.stdout
)
51 wordfile
= WordFile('../../wortliste') # ≅ 400 000 Einträge/Zeilen
52 wortliste
= list(wordfile
)
55 wordfile
.seek(0) # Pointer zurücksetzen
56 words
= wordfile
.asdict()
58 for oldentry
in wortliste
:
59 if len(oldentry
) <= 2:
60 # Ggf. Ergänzen der GROSS-Variante:
61 if (u
'ß' in oldentry
[0]
62 and oldentry
[0].replace(u
'ß', u
'ss') not in words
63 and oldentry
[0].replace(u
'ß', u
'ss').lower() not in words
64 and oldentry
[0].replace(u
'ß', u
'ss').title() not in words
66 entry
= WordEntry(oldentry
[0].replace(u
'ß', u
'ss')
68 + oldentry
[1].replace(u
'ß', u
'ss'))
69 wortliste_neu
.append(entry
)
70 wortliste_neu
.append(oldentry
)
72 entry
= copy
.copy(oldentry
)
74 if oldentry
== entry
and u
'ss' in entry
[0]:
76 if not w
.startswith(u
'-'):
79 sprachabgleich(entry
, words
[join_word(w
.replace(u
'ss', u
'ß'))])
81 # print entry[0].replace(u'ss', u'ß'), "fehlt"
82 if entry
.get('de-1901-x-GROSS'):
83 wort1901
= entry
.get('de-1901-x-GROSS')
84 wort1901
= wort1901
.replace(u
'ss', u
'ß')
85 if not u
'/' in wort1901
and len(wort1901
)>3:
86 print u
'%s;-2-;%s;-4-' % (join_word(wort1901
), wort1901
)
87 pass # e.g. "Abfahrtßpezialisten"
88 if oldentry
== entry
and u
'ß' in entry
[0]:
90 sprachabgleich(entry
, words
[entry
[0].replace(u
'ß', u
'ss')])
92 # Ergänzen der GROSS-Variante
93 if entry
.get('de-1996') is None:
94 oldentry
= WordEntry(u
';'.join(
95 [entry
[0].replace(u
'ß', u
'ss'),
97 entry
[2].replace(u
'ß', u
'ss'),
98 entry
[2].replace(u
'ß', u
'ss')]))
99 elif entry
.get('de-1996') is None:
100 # Dämmmassnahmen;-2-;-3-;-4-;-5-;-6-;Dämm==mass=nah-men;-8-
101 oldentry
= WordEntry(entry
[0].replace(u
'ß', u
'ss')
102 + u
';-2-;-3-;-4-;-5-;-6-;'
103 + entry
[3].replace(u
'ß', u
'ss')
106 oldentry
= WordEntry(u
';'.join(
107 [entry
[0].replace(u
'ß', u
'ss'),
109 entry
[2].replace(u
'ß', u
'ss'),
110 entry
[3].replace(u
'ß', u
'ss'),
113 wortliste_neu
.append(oldentry
)
115 wortliste_neu
.append(entry
)
121 patch
= udiff(wortliste
, wortliste_neu
, 'wortliste', 'wortliste-neu',
122 encoding
=wordfile
.encoding
)
125 patchfile
= open('wortliste.patch', 'w')
126 patchfile
.write(patch
+ '\n')