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 wortliste
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 wortliste.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 # Sprachabgleich mit ß-Form (Strassenschild vs. Straßenschild)
75 if oldentry
== entry
and u
'ss' in entry
[0]:
76 # Vergleichseintrag für Sprachabgleich finden:
77 for field
in entry
[1:]:
78 if not field
.startswith(u
'-'):
79 break # ``field`` ist jetzt erstes nichtleeres Feld
81 v_entry
= words
[join_word(field
.replace(u
'ss', u
'ß'))]
82 sprachabgleich(entry
, v_entry
)
84 print entry
[0].replace(u
'ss', u
'ß'), "fehlt"
85 # if entry.get('de-1901-x-GROSS'):
86 # wort1901 = entry.get('de-1901-x-GROSS')
87 # wort1901 = wort1901.replace(u'ss', u'ß')
88 # if not u'/' in wort1901 and len(wort1901)>3:
89 # print u'%s;-2-;%s;-4-' % (join_word(wort1901), wort1901)
90 pass # e.g. "Abfahrtßpezialisten"
91 if oldentry
== entry
and u
'ß' in entry
[0]:
93 sprachabgleich(entry
, words
[entry
[0].replace(u
'ß', u
'ss')])
95 # Ergänzen der GROSS-Variante
96 if entry
.get('de-1996') is None:
97 oldentry
= WordEntry(u
';'.join(
98 [entry
[0].replace(u
'ß', u
'ss'),
100 entry
[2].replace(u
'ß', u
'ss'),
101 entry
[2].replace(u
'ß', u
'ss')]))
102 elif entry
.get('de-1996') is None:
103 # Dämmmassnahmen;-2-;-3-;-4-;-5-;-6-;Dämm==mass=nah-men;-8-
104 oldentry
= WordEntry(entry
[0].replace(u
'ß', u
'ss')
105 + u
';-2-;-3-;-4-;-5-;-6-;'
106 + entry
[3].replace(u
'ß', u
'ss')
109 oldentry
= WordEntry(u
';'.join(
110 [entry
[0].replace(u
'ß', u
'ss'),
112 entry
[2].replace(u
'ß', u
'ss'),
113 entry
[3].replace(u
'ß', u
'ss'),
116 wortliste_neu
.append(oldentry
)
118 wortliste_neu
.append(entry
)
124 patch
= udiff(wortliste
, wortliste_neu
, 'wortliste', 'wortliste-neu',
125 encoding
=wordfile
.encoding
)
128 patchfile
= open('wortliste.patch', 'w')
129 patchfile
.write(patch
+ '\n')