pyphen 0.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. Pyphen-0.6/COPYING +165 -0
  2. Pyphen-0.6/PKG-INFO +83 -0
  3. Pyphen-0.6/README +57 -0
  4. Pyphen-0.6/pyphen/__init__.py +288 -0
  5. Pyphen-0.6/pyphen/dictionaries/hyph_af.dic +1 -0
  6. Pyphen-0.6/pyphen/dictionaries/hyph_af_ZA.dic +5332 -0
  7. Pyphen-0.6/pyphen/dictionaries/hyph_bg.dic +1 -0
  8. Pyphen-0.6/pyphen/dictionaries/hyph_bg_BG.dic +5961 -0
  9. Pyphen-0.6/pyphen/dictionaries/hyph_ca.dic +1022 -0
  10. Pyphen-0.6/pyphen/dictionaries/hyph_cs.dic +1 -0
  11. Pyphen-0.6/pyphen/dictionaries/hyph_cs_CZ.dic +3637 -0
  12. Pyphen-0.6/pyphen/dictionaries/hyph_da.dic +1 -0
  13. Pyphen-0.6/pyphen/dictionaries/hyph_da_DK.dic +1146 -0
  14. Pyphen-0.6/pyphen/dictionaries/hyph_de.dic +7728 -0
  15. Pyphen-0.6/pyphen/dictionaries/hyph_el.dic +1 -0
  16. Pyphen-0.6/pyphen/dictionaries/hyph_el_GR.dic +579 -0
  17. Pyphen-0.6/pyphen/dictionaries/hyph_en.dic +1 -0
  18. Pyphen-0.6/pyphen/dictionaries/hyph_en_GB.dic +14062 -0
  19. Pyphen-0.6/pyphen/dictionaries/hyph_en_US.dic +11130 -0
  20. Pyphen-0.6/pyphen/dictionaries/hyph_es.dic +865 -0
  21. Pyphen-0.6/pyphen/dictionaries/hyph_et.dic +1 -0
  22. Pyphen-0.6/pyphen/dictionaries/hyph_et_EE.dic +3692 -0
  23. Pyphen-0.6/pyphen/dictionaries/hyph_fr.dic +2848 -0
  24. Pyphen-0.6/pyphen/dictionaries/hyph_gl.dic +290 -0
  25. Pyphen-0.6/pyphen/dictionaries/hyph_hr.dic +1 -0
  26. Pyphen-0.6/pyphen/dictionaries/hyph_hr_HR.dic +1597 -0
  27. Pyphen-0.6/pyphen/dictionaries/hyph_hu.dic +1 -0
  28. Pyphen-0.6/pyphen/dictionaries/hyph_hu_HU.dic +96343 -0
  29. Pyphen-0.6/pyphen/dictionaries/hyph_it.dic +1 -0
  30. Pyphen-0.6/pyphen/dictionaries/hyph_it_IT.dic +399 -0
  31. Pyphen-0.6/pyphen/dictionaries/hyph_lt.dic +1 -0
  32. Pyphen-0.6/pyphen/dictionaries/hyph_lt_LT.dic +1547 -0
  33. Pyphen-0.6/pyphen/dictionaries/hyph_lv.dic +1 -0
  34. Pyphen-0.6/pyphen/dictionaries/hyph_lv_LV.dic +11900 -0
  35. Pyphen-0.6/pyphen/dictionaries/hyph_nb.dic +1 -0
  36. Pyphen-0.6/pyphen/dictionaries/hyph_nb_NO.dic +27142 -0
  37. Pyphen-0.6/pyphen/dictionaries/hyph_nl.dic +1 -0
  38. Pyphen-0.6/pyphen/dictionaries/hyph_nl_NL.dic +16257 -0
  39. Pyphen-0.6/pyphen/dictionaries/hyph_nn.dic +1 -0
  40. Pyphen-0.6/pyphen/dictionaries/hyph_nn_NO.dic +27142 -0
  41. Pyphen-0.6/pyphen/dictionaries/hyph_pl.dic +1 -0
  42. Pyphen-0.6/pyphen/dictionaries/hyph_pl_PL.dic +4824 -0
  43. Pyphen-0.6/pyphen/dictionaries/hyph_pt.dic +1 -0
  44. Pyphen-0.6/pyphen/dictionaries/hyph_pt_BR.dic +557 -0
  45. Pyphen-0.6/pyphen/dictionaries/hyph_pt_PT.dic +308 -0
  46. Pyphen-0.6/pyphen/dictionaries/hyph_ro.dic +1 -0
  47. Pyphen-0.6/pyphen/dictionaries/hyph_ro_RO.dic +4431 -0
  48. Pyphen-0.6/pyphen/dictionaries/hyph_ru.dic +1 -0
  49. Pyphen-0.6/pyphen/dictionaries/hyph_ru_RU.dic +3875 -0
  50. Pyphen-0.6/pyphen/dictionaries/hyph_sh.dic +3412 -0
  51. Pyphen-0.6/pyphen/dictionaries/hyph_sk.dic +1 -0
  52. Pyphen-0.6/pyphen/dictionaries/hyph_sk_SK.dic +2468 -0
  53. Pyphen-0.6/pyphen/dictionaries/hyph_sl.dic +1 -0
  54. Pyphen-0.6/pyphen/dictionaries/hyph_sl_SI.dic +1413 -0
  55. Pyphen-0.6/pyphen/dictionaries/hyph_sr.dic +3365 -0
  56. Pyphen-0.6/pyphen/dictionaries/hyph_te.dic +1 -0
  57. Pyphen-0.6/pyphen/dictionaries/hyph_te_IN.dic +99 -0
  58. Pyphen-0.6/pyphen/dictionaries/hyph_uk.dic +1 -0
  59. Pyphen-0.6/pyphen/dictionaries/hyph_uk_UA.dic +1654 -0
  60. Pyphen-0.6/pyphen/dictionaries/hyph_zu.dic +1 -0
  61. Pyphen-0.6/pyphen/dictionaries/hyph_zu_ZA.dic +171 -0
  62. Pyphen-0.6/setup.py +37 -0
Pyphen-0.6/COPYING ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
Pyphen-0.6/PKG-INFO ADDED
@@ -0,0 +1,83 @@
1
+ Metadata-Version: 1.1
2
+ Name: Pyphen
3
+ Version: 0.6
4
+ Summary: Pure Python module to hyphenate text
5
+ Home-page: https://github.com/Kozea/Pyphen
6
+ Author: Guillaume Ayoub
7
+ Author-email: guillaume.ayoub@kozea.fr
8
+ License: UNKNOWN
9
+ Description: Pyphen
10
+ ======
11
+
12
+ Pyphen is a pure Python module to hyphenate text using existing Hunspell
13
+ hyphenation dictionaries.
14
+
15
+ https://github.com/Kozea/Pyphen
16
+
17
+ This module is a fork of python-hyphenator, written by Wilbert Berendsen.
18
+
19
+ https://code.google.com/p/python-hyphenator/
20
+
21
+ Many dictionaries are included in pyphen, they come from the LibreOffice git
22
+ repository and are distributed under various licenses, including the LGPL
23
+ version 2.1 also used for pyphen.
24
+
25
+ See: http://cgit.freedesktop.org/libreoffice/dictionaries/tree/
26
+
27
+ Usage:
28
+
29
+ >>> import pyphen
30
+ >>> 'nl_NL' in pyphen.LANGUAGES
31
+ True
32
+ >>> dic = pyphen.Pyphen(lang='nl_NL')
33
+ >>> dic.inserted('lettergrepen')
34
+ 'let-ter-gre-pen'
35
+ >>> dic.wrap('autobandventieldopje', 11)
36
+ ('autoband-', 'ventieldopje')
37
+ >>> for pair in dic.iterate('Amsterdam'):
38
+ ... print(pair)
39
+ ...
40
+ ('Amster', 'dam')
41
+ ('Am', 'sterdam')
42
+ >>>
43
+
44
+ Features:
45
+
46
+ * 100% pure Python with no dependencies
47
+ * a lot of included dictionaries
48
+ * caches dict files and hyphenated words
49
+ * supports nonstandard hyphenation patterns
50
+
51
+ License:
52
+
53
+ This library is free software; you can redistribute it and/or
54
+ modify it under the terms of the GNU Lesser General Public
55
+ License as published by the Free Software Foundation; either
56
+ version 2.1 of the License, or (at your option) any later version.
57
+
58
+ This library is distributed in the hope that it will be useful,
59
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
60
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
61
+ Lesser General Public License for more details.
62
+
63
+ You should have received a copy of the GNU Lesser General Public
64
+ License along with this library; if not, write to the Free Software
65
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
66
+
67
+ Platform: UNKNOWN
68
+ Classifier: Development Status :: 4 - Beta
69
+ Classifier: Intended Audience :: Developers
70
+ Classifier: License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)
71
+ Classifier: Programming Language :: Python
72
+ Classifier: Programming Language :: Python :: 2
73
+ Classifier: Programming Language :: Python :: 2.6
74
+ Classifier: Programming Language :: Python :: 2.7
75
+ Classifier: Programming Language :: Python :: 3
76
+ Classifier: Programming Language :: Python :: 3.1
77
+ Classifier: Programming Language :: Python :: 3.2
78
+ Classifier: Programming Language :: Python :: 3.3
79
+ Classifier: Programming Language :: Python :: Implementation :: CPython
80
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
81
+ Classifier: Topic :: Text Processing
82
+ Classifier: Topic :: Text Processing :: Linguistic
83
+ Provides: pyphen
Pyphen-0.6/README ADDED
@@ -0,0 +1,57 @@
1
+ Pyphen
2
+ ======
3
+
4
+ Pyphen is a pure Python module to hyphenate text using existing Hunspell
5
+ hyphenation dictionaries.
6
+
7
+ https://github.com/Kozea/Pyphen
8
+
9
+ This module is a fork of python-hyphenator, written by Wilbert Berendsen.
10
+
11
+ https://code.google.com/p/python-hyphenator/
12
+
13
+ Many dictionaries are included in pyphen, they come from the LibreOffice git
14
+ repository and are distributed under various licenses, including the LGPL
15
+ version 2.1 also used for pyphen.
16
+
17
+ See: http://cgit.freedesktop.org/libreoffice/dictionaries/tree/
18
+
19
+ Usage:
20
+
21
+ >>> import pyphen
22
+ >>> 'nl_NL' in pyphen.LANGUAGES
23
+ True
24
+ >>> dic = pyphen.Pyphen(lang='nl_NL')
25
+ >>> dic.inserted('lettergrepen')
26
+ 'let-ter-gre-pen'
27
+ >>> dic.wrap('autobandventieldopje', 11)
28
+ ('autoband-', 'ventieldopje')
29
+ >>> for pair in dic.iterate('Amsterdam'):
30
+ ... print(pair)
31
+ ...
32
+ ('Amster', 'dam')
33
+ ('Am', 'sterdam')
34
+ >>>
35
+
36
+ Features:
37
+
38
+ * 100% pure Python with no dependencies
39
+ * a lot of included dictionaries
40
+ * caches dict files and hyphenated words
41
+ * supports nonstandard hyphenation patterns
42
+
43
+ License:
44
+
45
+ This library is free software; you can redistribute it and/or
46
+ modify it under the terms of the GNU Lesser General Public
47
+ License as published by the Free Software Foundation; either
48
+ version 2.1 of the License, or (at your option) any later version.
49
+
50
+ This library is distributed in the hope that it will be useful,
51
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
52
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
53
+ Lesser General Public License for more details.
54
+
55
+ You should have received a copy of the GNU Lesser General Public
56
+ License along with this library; if not, write to the Free Software
57
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@@ -0,0 +1,288 @@
1
+ # This file is part of Pyphen
2
+ #
3
+ # Copyright 2008 - Wilbert Berendsen <info@wilbertberendsen.nl>
4
+ # Copyright 2012 - Guillaume Ayoub <guillaume.ayoub@kozea.fr>
5
+ #
6
+ # This library is free software: you can redistribute it and/or modify it under
7
+ # the terms of the GNU Lesser General Public License as published by the Free
8
+ # Software Foundation, either version 2.1 of the License, or (at your option)
9
+ # any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful, but WITHOUT
12
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
+ # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
+ # details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public License
17
+ # along with Pyphen. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ """
20
+
21
+ Pyphen
22
+ ======
23
+
24
+ Pure Python module to hyphenate text, inspired by Ruby's Text::Hyphen.
25
+
26
+ """
27
+
28
+ from __future__ import unicode_literals
29
+
30
+ import os
31
+ import re
32
+
33
+
34
+ __all__ = ('Pyphen', 'LANGUAGES')
35
+
36
+ # cache of per-file HyphDict objects
37
+ hdcache = {}
38
+
39
+ # precompile some stuff
40
+ parse_hex = re.compile(r'\^{2}([0-9a-f]{2})').sub
41
+ parse = re.compile(r'(\d?)(\D?)').findall
42
+
43
+ # included dictionaries
44
+ dictionaries_root = os.path.join(os.path.dirname(__file__), 'dictionaries')
45
+ LANGUAGES = dict(
46
+ (filename[5:-4], os.path.join(dictionaries_root, filename))
47
+ for filename in os.listdir(dictionaries_root)
48
+ if filename.endswith('.dic'))
49
+
50
+
51
+ class AlternativeParser(object):
52
+ """Parser of nonstandard hyphen pattern alternative.
53
+
54
+ The instance returns a special int with data about the current position in
55
+ the pattern when called with an odd value.
56
+
57
+ """
58
+ def __init__(self, pattern, alternative):
59
+ alternative = alternative.split(',')
60
+ self.change = alternative[0]
61
+ if len(alternative) > 2:
62
+ self.index = int(alternative[1])
63
+ self.cut = int(alternative[2]) + 1
64
+ else:
65
+ self.index = 1
66
+ self.cut = len(re.sub(r'[\d\.]', '', pattern)) + 1
67
+ if pattern.startswith('.'):
68
+ self.index += 1
69
+
70
+ def __call__(self, value):
71
+ self.index -= 1
72
+ value = int(value)
73
+ if value % 2:
74
+ return value
75
+ else:
76
+ return DataInt(value, (self.change, self.index, self.cut))
77
+
78
+
79
+ class DataInt(int):
80
+ """``int`` with some other data can be stuck to in a ``data`` attribute."""
81
+ def __new__(cls, value, data=None, reference=None):
82
+ """Create a new ``DataInt``.
83
+
84
+ Call with ``reference=dataint_object`` to use the data from another
85
+ ``DataInt``.
86
+
87
+ """
88
+ obj = int.__new__(cls, value)
89
+ obj.data = reference.data if isinstance(reference, DataInt) else None
90
+ return obj
91
+
92
+
93
+ class HyphDict(object):
94
+ """Hyphenation patterns."""
95
+
96
+ def __init__(self, filename):
97
+ """Read a ``hyph_*.dic`` and parse its patterns.
98
+
99
+ :param filename: filename of hyph_*.dic to read
100
+
101
+ """
102
+ self.patterns = {}
103
+
104
+ with open(filename, 'rb') as stream:
105
+ charset = stream.readline().strip().decode('ascii')
106
+ if charset.startswith('charset '):
107
+ charset = charset[8:].strip()
108
+
109
+ for pattern in stream:
110
+ pattern = pattern.decode(charset).strip()
111
+ if not pattern or pattern[0] == '%':
112
+ continue
113
+
114
+ # replace ^^hh with the real character
115
+ pattern = parse_hex(
116
+ lambda match: unichr(int(match.group(1), 16)), pattern)
117
+
118
+ # read nonstandard hyphen alternatives
119
+ if '/' in pattern:
120
+ pattern, alternative = pattern.split('/', 1)
121
+ factory = AlternativeParser(pattern, alternative)
122
+ else:
123
+ factory = int
124
+
125
+ tags, values = zip(*[
126
+ (string, factory(i or '0'))
127
+ for i, string in parse(pattern)])
128
+
129
+ # if only zeros, skip this pattern
130
+ if max(values) == 0:
131
+ continue
132
+
133
+ # chop zeros from beginning and end, and store start offset
134
+ start, end = 0, len(values)
135
+ while not values[start]:
136
+ start += 1
137
+ while not values[end - 1]:
138
+ end -= 1
139
+
140
+ self.patterns[''.join(tags)] = start, values[start:end]
141
+
142
+ self.cache = {}
143
+ self.maxlen = max(map(len, self.patterns.keys()))
144
+
145
+ def positions(self, word):
146
+ """Get a list of positions where the word can be hyphenated.
147
+
148
+ :param word: unicode string of the word to hyphenate
149
+
150
+ E.g. for the dutch word 'lettergrepen' this method returns ``[3, 6,
151
+ 9]``.
152
+
153
+ Each position is a ``DataInt`` with a data attribute.
154
+
155
+ If the data attribute is not ``None``, it contains a tuple with
156
+ information about nonstandard hyphenation at that point: ``(change,
157
+ index, cut)``.
158
+
159
+ change
160
+ a string like ``'ff=f'``, that describes how hyphenation should
161
+ take place.
162
+
163
+ index
164
+ where to substitute the change, counting from the current point
165
+
166
+ cut
167
+ how many characters to remove while substituting the nonstandard
168
+ hyphenation
169
+
170
+ """
171
+ word = word.lower()
172
+ points = self.cache.get(word)
173
+ if points is None:
174
+ pointed_word = '.%s.' % word
175
+ references = [0] * (len(pointed_word) + 1)
176
+
177
+ for i in range(len(pointed_word) - 1):
178
+ for j in range(
179
+ i + 1, min(i + self.maxlen, len(pointed_word)) + 1):
180
+ pattern = self.patterns.get(pointed_word[i:j])
181
+ if pattern:
182
+ offset, value = pattern
183
+ slice_ = slice(i + offset, i + offset + len(value))
184
+ references[slice_] = map(
185
+ max, value, references[slice_])
186
+
187
+ points = [
188
+ DataInt(i - 1, reference=reference)
189
+ for i, reference in enumerate(references) if reference % 2]
190
+ self.cache[word] = points
191
+ return points
192
+
193
+
194
+ class Pyphen(object):
195
+ """Hyphenation class, with methods to hyphenate strings in various ways."""
196
+
197
+ def __init__(self, filename=None, lang=None, left=2, right=2, cache=True):
198
+ """Create an hyphenation instance for given lang or filename.
199
+
200
+ :param filename: filename of hyph_*.dic to read
201
+ :param lang: lang of the included dict to use if no filename is given
202
+ :param left: minimum number of characters of the first syllabe
203
+ :param right: minimum number of characters of the last syllabe
204
+ :param cache: if ``True``, use cached copy of the hyphenation patterns
205
+
206
+ """
207
+ if not filename:
208
+ filename = LANGUAGES[lang]
209
+ self.left = left
210
+ self.right = right
211
+ if not cache or filename not in hdcache:
212
+ hdcache[filename] = HyphDict(filename)
213
+ self.hd = hdcache[filename]
214
+
215
+ def positions(self, word):
216
+ """Get a list of positions where the word can be hyphenated.
217
+
218
+ :param word: unicode string of the word to hyphenate
219
+
220
+ See also ``HyphDict.positions``. The points that are too far to the
221
+ left or right are removed.
222
+
223
+ """
224
+ right = len(word) - self.right
225
+ return [i for i in self.hd.positions(word) if self.left <= i <= right]
226
+
227
+ def iterate(self, word):
228
+ """Iterate over all hyphenation possibilities, the longest first.
229
+
230
+ :param word: unicode string of the word to hyphenate
231
+
232
+ """
233
+ for position in reversed(self.positions(word)):
234
+ if position.data:
235
+ # get the nonstandard hyphenation data
236
+ change, index, cut = position.data
237
+ index += position
238
+ if word.isupper():
239
+ change = change.upper()
240
+ c1, c2 = change.split('=')
241
+ yield word[:index] + c1, c2 + word[index + cut:]
242
+ else:
243
+ yield word[:position], word[position:]
244
+
245
+ def wrap(self, word, width, hyphen='-'):
246
+ """Get the longest possible first part and the last part of a word.
247
+
248
+ :param word: unicode string of the word to hyphenate
249
+ :param width: maximum length of the first part
250
+ :param hyphen: unicode string used as hyphen character
251
+
252
+ The first part has the hyphen already attached.
253
+
254
+ Returns ``None`` if there is no hyphenation point before ``width``, or
255
+ if the word could not be hyphenated.
256
+
257
+ """
258
+ width -= len(hyphen)
259
+ for w1, w2 in self.iterate(word):
260
+ if len(w1) <= width:
261
+ return w1 + hyphen, w2
262
+
263
+ def inserted(self, word, hyphen='-'):
264
+ """Get the word as a string with all the possible hyphens inserted.
265
+
266
+ :param word: unicode string of the word to hyphenate
267
+ :param hyphen: unicode string used as hyphen character
268
+
269
+ E.g. for the dutch word ``'lettergrepen'``, this method returns the
270
+ unicode string ``'let-ter-gre-pen'``. The hyphen string to use can be
271
+ given as the second parameter, that defaults to ``'-'``.
272
+
273
+ """
274
+ word_list = list(word)
275
+ for position in reversed(self.positions(word)):
276
+ if position.data:
277
+ # get the nonstandard hyphenation data
278
+ change, index, cut = position.data
279
+ index += position
280
+ if word.isupper():
281
+ change = change.upper()
282
+ word_list[index:index + cut] = change.replace('=', hyphen)
283
+ else:
284
+ word_list.insert(position, hyphen)
285
+
286
+ return ''.join(word_list)
287
+
288
+ __call__ = iterate
@@ -0,0 +1 @@
1
+ hyph_af_ZA.dic