Grammalecte  Diff

Differences From Artifact [e20bd3ea84]:

To Artifact [3443a1d35d]:


183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244

245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261




    ## missing apostrophes
    "ma_word":                  [("(?i)(qu|lorsqu|puisqu|quoiqu|presqu|jusqu|aujourd|entr|quelqu|prud) ", "\\1’")],
    "ma_1letter_lowercase":     [("\\b([ldjnmtscç]) (?=[aàeéêiîoôuyhAÀEÉÊIÎOÔUYH])", "\\1’")],
    "ma_1letter_uppercase":     [("\\b([LDJNMTSCÇ]) (?=[aàeéêiîoôuyhAÀEÉÊIÎOÔUYH])", "\\1’")]
}


lOptRepl = [
    ("ts_units", True),
    ("start_of_paragraph", True),
    ("end_of_paragraph", True),
    ("between_words", True),
    ("before_punctuation", True),
    ("within_parenthesis", True),
    ("within_square_brackets", True),
    ("within_quotation_marks", True),
    ("nbsp_before_punctuation", True),
    ("nbsp_within_quotation_marks", True),
    ("nbsp_within_numbers", True),
    ("nnbsp_before_punctuation", False),
    ("nnbsp_within_quotation_marks", False),
    ("nnbsp_within_numbers", False),
    ("nbsp_titles", False),
    ("nbsp_before_symbol", True),
    ("nbsp_before_units", True),
    ("nbsp_repair", True),
    ("add_space_after_punctuation", True),
    ("add_space_around_hyphens", True),
    ("add_space_repair", True),
    ("erase_non_breaking_hyphens", False),
    ("ts_apostrophe", True),
    ("ts_ellipsis", True),
    ("ts_n_dash_middle", True),
    ("ts_m_dash_middle", False),
    ("ts_n_dash_start", False),
    ("ts_m_dash_start", True),
    ("ts_quotation_marks", True),
    ("ts_spell", True),
    ("ts_ligature_ffi_on", False),
    ("ts_ligature_ffl_on", False),
    ("ts_ligature_fi_on", False),
    ("ts_ligature_fl_on", False),
    ("ts_ligature_ff_on", False),
    ("ts_ligature_ft_on", False),
    ("ts_ligature_st_on", False),
    ("ts_ligature_fi_off", False),
    ("ts_ligature_fl_off", False),
    ("ts_ligature_ff_off", False),
    ("ts_ligature_ffi_off", False),
    ("ts_ligature_ffl_off", False),
    ("ts_ligature_ft_off", False),
    ("ts_ligature_st_off", False),
    ("ordinals_exponant", False),
    ("ordinals_no_exponant", True),
    ("etc", True),
    ("mh_interrogatives", True),
    ("mh_numbers", True),
    ("mh_frequent_words", True),
    ("ma_word", True),
    ("ma_1letter_lowercase", False),
    ("ma_1letter_uppercase", False),
]



class TextFormatter:
    "Text Formatter: purge typographic mistakes from text"

    def __init__ (self):
        for sOpt, lTup in dReplTable.items():
            for i, t in enumerate(lTup):
                lTup[i] = (re.compile(t[0]), t[1])

    def formatText (self, sText):
        "returns formatted text"
        for sOptName, bVal in lOptRepl:
            if bVal:
                for zRgx, sRep in dReplTable[sOptName]:
                    sText = zRgx.sub(sRep, sText)
        return sText











|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
>






|





|




>
>
>
>
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243

244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
    ## missing apostrophes
    "ma_word":                  [("(?i)(qu|lorsqu|puisqu|quoiqu|presqu|jusqu|aujourd|entr|quelqu|prud) ", "\\1’")],
    "ma_1letter_lowercase":     [("\\b([ldjnmtscç]) (?=[aàeéêiîoôuyhAÀEÉÊIÎOÔUYH])", "\\1’")],
    "ma_1letter_uppercase":     [("\\b([LDJNMTSCÇ]) (?=[aàeéêiîoôuyhAÀEÉÊIÎOÔUYH])", "\\1’")]
}


dDefaultOptions = {
    "ts_units": True,
    "start_of_paragraph": True,
    "end_of_paragraph": True,
    "between_words": True,
    "before_punctuation": True,
    "within_parenthesis": True,
    "within_square_brackets": True,
    "within_quotation_marks": True,
    "nbsp_before_punctuation": True,
    "nbsp_within_quotation_marks": True,
    "nbsp_within_numbers": True,
    "nnbsp_before_punctuation": False,
    "nnbsp_within_quotation_marks": False,
    "nnbsp_within_numbers": False,
    "nbsp_titles": False,
    "nbsp_before_symbol": True,
    "nbsp_before_units": True,
    "nbsp_repair": True,
    "add_space_after_punctuation": True,
    "add_space_around_hyphens": True,
    "add_space_repair": True,
    "erase_non_breaking_hyphens": False,
    "ts_apostrophe": True,
    "ts_ellipsis": True,
    "ts_n_dash_middle": True,
    "ts_m_dash_middle": False,
    "ts_n_dash_start": False,
    "ts_m_dash_start": True,
    "ts_quotation_marks": True,
    "ts_spell": True,
    "ts_ligature_ffi_on": False,
    "ts_ligature_ffl_on": False,
    "ts_ligature_fi_on": False,
    "ts_ligature_fl_on": False,
    "ts_ligature_ff_on": False,
    "ts_ligature_ft_on": False,
    "ts_ligature_st_on": False,
    "ts_ligature_fi_off": False,
    "ts_ligature_fl_off": False,
    "ts_ligature_ff_off": False,
    "ts_ligature_ffi_off": False,
    "ts_ligature_ffl_off": False,
    "ts_ligature_ft_off": False,
    "ts_ligature_st_off": False,
    "ordinals_exponant": False,
    "ordinals_no_exponant": True,
    "etc": True,
    "mh_interrogatives": True,
    "mh_numbers": True,
    "mh_frequent_words": True,
    "ma_word": True,
    "ma_1letter_lowercase": False,
    "ma_1letter_uppercase": False

}


class TextFormatter:
    "Text Formatter: purge typographic mistakes from text"

    def __init__ (self):
        for _, lTup in dReplTable.items():
            for i, t in enumerate(lTup):
                lTup[i] = (re.compile(t[0]), t[1])

    def formatText (self, sText):
        "returns formatted text"
        for sOptName, bVal in dDefaultOptions.items():
            if bVal:
                for zRgx, sRep in dReplTable[sOptName]:
                    sText = zRgx.sub(sRep, sText)
        return sText

    def getDefaultOptions (self):
        "returns default options"
        return dDefaultOptions.copy()