3 # :Copyright: © 2011 Günter Milde.
4 # Released without warranty under the terms of the
5 # GNU General Public License (v. 2 or later)
8 # Versuche Trennstellen neuer Wörter aus vorhandenen zu ermitteln
9 # ===============================================================
11 # Übertragen von kategorisierten Trennstellen vorhandener Wörter
12 # auf neu aufzunehmende, ungetrennte Wörter.
14 # Erwartet eine Datei mit 1 Wort/Zeile.
16 # Erstellt einen Patch mit den Wörtern, welche durch Abgleich mit der
17 # Datenbasis getrennt werden konnten.
20 import re
, sys
, codecs
, copy
, os
21 from werkzeug
import WordFile
, WordEntry
, join_word
, toggle_case
22 # sort.py im Überverzeichnis:
23 sys
.path
.append(os
.path
.join(os
.path
.dirname(__file__
), '..'))
24 from sort
import sortkey_duden
31 # Sprach-Tag nach [BCP47]_::
33 # sprachvariante = 'de-1901' # "traditionell"
34 sprachvariante
= 'de-1996' # Reformschreibung
35 # sprachvariante = 'de-1901-x-GROSS' # ohne ß (Schweiz oder GROSS)
36 # sprachvariante = 'de-1996-x-GROSS' # ohne ß (Schweiz oder GROSS)
37 # sprachvariante = 'de-CH-1901' # ohne ß (Schweiz) ("süssauer")
42 # Übertrag von Einträgen auf Wörter mit anderer Endung::
44 def endungsabgleich(key
, alt
, neu
, grossklein
=False):
46 if not key
.endswith(join_word(neu
)):
49 altkey
= key
[:-len(join_word(neu
))] + join_word(alt
)
51 altkey
= toggle_case(altkey
)
54 altentry
= words
[altkey
]
58 entry
= WordEntry(key
)
59 # print "fundum", key, unicode(entry)
60 for wort
in altentry
[1:]:
61 if not wort
.startswith(u
'-'):
63 wort
= wort
[:-len(alt
)]
66 wort
= toggle_case(wort
)
67 if join_word(wort
) != key
:
68 print u
"# Übertragungsproblem: %s -> %s (%s,%s) %s" % (
69 altkey
, key
, alt
, neu
, wort
)
78 # ``(<alt>, <neu>)`` Paare von Endungen
80 # Achtung: die Auswahl zu testender Wörter erfolgt anhand der "neu"-Endung.
81 # Daher darf diese nicht leer sein!
126 (u
'-en', u
'>bar>keit'),
142 (u
'-sten', u
's-mus'),
164 (u
'e-ren', u
'-ti-on'),
195 (u
'isch', u
'i-sche'),
234 (u
'ph', u
'-phis-mus'),
297 if __name__
== '__main__':
299 # sys.stdout mit UTF8 encoding.
300 sys
.stdout
= codecs
.getwriter('UTF-8')(sys
.stdout
)
302 # `Wortliste` einlesen::
304 wordfile
= WordFile('wortliste-expandiert') # + Teilwort-Entries
305 words
= wordfile
.asdict()
307 neuwortdatei
= open("zusatzwörter-de-1996-hunspell-compact")
309 neueintraege_grossklein
= []
311 # Erstellen der neuen Einträge::
313 for line
in neuwortdatei
:
314 key
= line
.decode('utf8').strip()
319 # Test auf vorhandene (Teil-) Wörter:
323 neueintraege
.append(entry
)
329 entry
= words
[key
.lower()]
330 neueintraege_grossklein
.append(entry
)
336 entry
= words
[key
.title()]
337 neueintraege_grossklein
.append(entry
)
344 for alt
, neu
in endungen
:
345 entry
= endungsabgleich(key
, alt
, neu
, grossklein
=False)
347 neueintraege
.append(entry
)
350 for alt
, neu
in endungen
:
351 entry
= endungsabgleich(key
, alt
, neu
, grossklein
=True)
353 neueintraege_grossklein
.append(entry
)
359 print u
'# als Teilwörter'
360 for entry
in neueintraege
:
363 print u
'# als Teilwörter (andere Großschreibung)'
364 for entry
in neueintraege_grossklein
: