pyests 0.1.0__py3-none-any.whl
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.
- ests/__init__.py +56 -0
- ests/basic_stats.py +329 -0
- ests/constants.py +383 -0
- ests/diversity_stats.py +1582 -0
- ests/exceptions.py +83 -0
- ests/extractors.py +377 -0
- ests/py.typed +0 -0
- ests/readability_stats.py +749 -0
- ests/syllables.py +343 -0
- ests/utils.py +266 -0
- pyests-0.1.0.dist-info/METADATA +395 -0
- pyests-0.1.0.dist-info/RECORD +14 -0
- pyests-0.1.0.dist-info/WHEEL +4 -0
- pyests-0.1.0.dist-info/licenses/LICENSE.txt +17 -0
ests/constants.py
ADDED
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
import string
|
|
2
|
+
|
|
3
|
+
# Punctuation marks and symbols, including the Spanish inverted marks,
|
|
4
|
+
# dashes, ellipsis, guillemets, curly quotes and the middle dot
|
|
5
|
+
PUNCTUATIONS = string.punctuation + "¿¡—–…«»“”‘’·"
|
|
6
|
+
|
|
7
|
+
# Characters that may open a sentence besides an upper-case letter or a digit:
|
|
8
|
+
# inverted question and exclamation marks, opening quotes and brackets,
|
|
9
|
+
# dashes of a dialogue line
|
|
10
|
+
SENTENCE_OPENERS = "¿¡«“\"'([—–-"
|
|
11
|
+
|
|
12
|
+
# Dashes that open a line of dialogue; one followed by a lower-case word opens
|
|
13
|
+
# the remark of the narrator inside the same sentence (-¿Vienes? -preguntó ella)
|
|
14
|
+
DASHES = "—–-"
|
|
15
|
+
|
|
16
|
+
# Abbreviations after which a sentence does not end even before an upper-case
|
|
17
|
+
# word or a number: forms of address, references, times and eras; compared in
|
|
18
|
+
# lower case with the last one or two space-separated tokens before the period.
|
|
19
|
+
# Single capital initials (J. L. Borges) are recognized separately.
|
|
20
|
+
# Abbreviations that usually do end a sentence (etc.) or coincide with
|
|
21
|
+
# a word (mar., no.) are not listed
|
|
22
|
+
ABBREVIATIONS = frozenset(
|
|
23
|
+
{
|
|
24
|
+
# Forms of address and titles
|
|
25
|
+
"sr.",
|
|
26
|
+
"sra.",
|
|
27
|
+
"srta.",
|
|
28
|
+
"sres.",
|
|
29
|
+
"sras.",
|
|
30
|
+
"d.",
|
|
31
|
+
"dña.",
|
|
32
|
+
"dr.",
|
|
33
|
+
"dra.",
|
|
34
|
+
"dres.",
|
|
35
|
+
"prof.",
|
|
36
|
+
"profa.",
|
|
37
|
+
"lic.",
|
|
38
|
+
"lcdo.",
|
|
39
|
+
"lcda.",
|
|
40
|
+
"ing.",
|
|
41
|
+
"arq.",
|
|
42
|
+
"gral.",
|
|
43
|
+
"cnel.",
|
|
44
|
+
"cap.",
|
|
45
|
+
"pdte.",
|
|
46
|
+
"pdta.",
|
|
47
|
+
"pbro.",
|
|
48
|
+
"mons.",
|
|
49
|
+
"fr.",
|
|
50
|
+
"sto.",
|
|
51
|
+
"sta.",
|
|
52
|
+
"st.",
|
|
53
|
+
"excmo.",
|
|
54
|
+
"excma.",
|
|
55
|
+
"ilmo.",
|
|
56
|
+
"ilma.",
|
|
57
|
+
"rvdo.",
|
|
58
|
+
"rvda.",
|
|
59
|
+
"ud.",
|
|
60
|
+
"uds.",
|
|
61
|
+
"vd.",
|
|
62
|
+
"vds.",
|
|
63
|
+
"ss.",
|
|
64
|
+
"ee.",
|
|
65
|
+
"ee. uu.",
|
|
66
|
+
"ss. mm.",
|
|
67
|
+
"s. m.",
|
|
68
|
+
"s. a.",
|
|
69
|
+
"s. l.",
|
|
70
|
+
"cía.",
|
|
71
|
+
"ltda.",
|
|
72
|
+
"admón.",
|
|
73
|
+
# References and text apparatus
|
|
74
|
+
"p.",
|
|
75
|
+
"pp.",
|
|
76
|
+
"pág.",
|
|
77
|
+
"págs.",
|
|
78
|
+
"núm.",
|
|
79
|
+
"núms.",
|
|
80
|
+
"nro.",
|
|
81
|
+
"n.",
|
|
82
|
+
"vol.",
|
|
83
|
+
"vols.",
|
|
84
|
+
"t.",
|
|
85
|
+
"caps.",
|
|
86
|
+
"art.",
|
|
87
|
+
"arts.",
|
|
88
|
+
"fig.",
|
|
89
|
+
"figs.",
|
|
90
|
+
"ed.",
|
|
91
|
+
"eds.",
|
|
92
|
+
"col.",
|
|
93
|
+
"ej.",
|
|
94
|
+
"p. ej.",
|
|
95
|
+
"v. gr.",
|
|
96
|
+
"cf.",
|
|
97
|
+
"cfr.",
|
|
98
|
+
"vid.",
|
|
99
|
+
"op.",
|
|
100
|
+
"cit.",
|
|
101
|
+
"op. cit.",
|
|
102
|
+
"loc.",
|
|
103
|
+
"loc. cit.",
|
|
104
|
+
"ibíd.",
|
|
105
|
+
"ibid.",
|
|
106
|
+
"íd.",
|
|
107
|
+
"id.",
|
|
108
|
+
"trad.",
|
|
109
|
+
"coord.",
|
|
110
|
+
"comp.",
|
|
111
|
+
"dir.",
|
|
112
|
+
"s.",
|
|
113
|
+
"sig.",
|
|
114
|
+
"sigs.",
|
|
115
|
+
"aprox.",
|
|
116
|
+
"máx.",
|
|
117
|
+
"mín.",
|
|
118
|
+
"tel.",
|
|
119
|
+
"tfno.",
|
|
120
|
+
"av.",
|
|
121
|
+
"avda.",
|
|
122
|
+
"c.",
|
|
123
|
+
"dpto.",
|
|
124
|
+
"depto.",
|
|
125
|
+
"izq.",
|
|
126
|
+
"izqda.",
|
|
127
|
+
"dcha.",
|
|
128
|
+
"dcho.",
|
|
129
|
+
# Times and eras
|
|
130
|
+
"a.",
|
|
131
|
+
"a. m.",
|
|
132
|
+
"p. m.",
|
|
133
|
+
"a. c.",
|
|
134
|
+
"d. c.",
|
|
135
|
+
"a. j. c.",
|
|
136
|
+
"d. j. c.",
|
|
137
|
+
}
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
# Vowels: every accented vowel is strong, an unaccented i, u, ü and a vocalic y
|
|
141
|
+
# are weak; a weak vowel next to another vowel forms a diphthong, two strong
|
|
142
|
+
# vowels a hiatus. Vowels with a grave, a circumflex, a tilde or a diaeresis
|
|
143
|
+
# other than ü come from Catalan, French, Portuguese and German names
|
|
144
|
+
# (Lluïsa, Citroën, São, Björk); they count as accented, so they are strong
|
|
145
|
+
# and take the stress. A diaeresis marks a hiatus in Catalan and French
|
|
146
|
+
# (Llu-ï-sa, Ci-tro-ën); the Portuguese nasal ã and õ join a following
|
|
147
|
+
# o or e into a diphthong (São, Ca-mões)
|
|
148
|
+
VOWELS = "aeiouáéíóúüàèìòùâêîôûãõäëïöå"
|
|
149
|
+
WEAK_VOWELS = "iuü"
|
|
150
|
+
ACCENTED_VOWELS = "áéíóúàèìòùâêîôûãõäëïöå"
|
|
151
|
+
HIATUS_VOWELS = "ïë"
|
|
152
|
+
NASAL_VOWELS = "ãõ"
|
|
153
|
+
|
|
154
|
+
# Two-letter consonant units that are never split (digraphs and the silent u)
|
|
155
|
+
DIGRAPHS = ("ch", "ll", "rr", "qu", "gu")
|
|
156
|
+
|
|
157
|
+
# Consonant pairs that open a syllable together: an obstruent with l or r
|
|
158
|
+
ONSET_CLUSTERS = frozenset(
|
|
159
|
+
{"bl", "br", "cl", "cr", "dr", "fl", "fr", "gl", "gr", "kl", "kr", "pl", "pr", "tr"}
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
# Words in -mente that look like adverbs but are not, so they carry a single
|
|
163
|
+
# stress: adjectives and nouns, and subjunctives of verbs in -mentar whose stem
|
|
164
|
+
# ends like an adjective
|
|
165
|
+
NON_ADVERBS_MENTE = frozenset(
|
|
166
|
+
{
|
|
167
|
+
"clemente",
|
|
168
|
+
"demente",
|
|
169
|
+
"inclemente",
|
|
170
|
+
"vehemente",
|
|
171
|
+
"atormente",
|
|
172
|
+
"cemente",
|
|
173
|
+
"complemente",
|
|
174
|
+
"fermente",
|
|
175
|
+
"fundamente",
|
|
176
|
+
"implemente",
|
|
177
|
+
"incremente",
|
|
178
|
+
"juramente",
|
|
179
|
+
"lamente",
|
|
180
|
+
"medicamente",
|
|
181
|
+
"ornamente",
|
|
182
|
+
"parlamente",
|
|
183
|
+
"reglamente",
|
|
184
|
+
"sacramente",
|
|
185
|
+
"suplemente",
|
|
186
|
+
}
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
# Whitespace counted as spaces by the basic statistics
|
|
190
|
+
SPACES = [" ", "\t"]
|
|
191
|
+
|
|
192
|
+
# Thresholds of the basic statistics: a complex word has three or more syllables,
|
|
193
|
+
# as in the Spanish readability formulas, a long word seven or more letters,
|
|
194
|
+
# as in LIX and RIX
|
|
195
|
+
COMPLEX_SYL_FACTOR = 3
|
|
196
|
+
LONG_WORD_LETTER_FACTOR = 7
|
|
197
|
+
|
|
198
|
+
# Types of punctuation marks; the inverted marks ¿ and ¡ count as question
|
|
199
|
+
# and exclamation marks, so a Spanish question carries two of them
|
|
200
|
+
PUNCTUATION_TYPES = {
|
|
201
|
+
"comma": "Commas",
|
|
202
|
+
"period": "Periods",
|
|
203
|
+
"question": "Question marks",
|
|
204
|
+
"exclamation": "Exclamation marks",
|
|
205
|
+
"ellipsis": "Ellipses",
|
|
206
|
+
"colon": "Colons",
|
|
207
|
+
"semicolon": "Semicolons",
|
|
208
|
+
"dash": "Dashes",
|
|
209
|
+
"hyphen": "Hyphens",
|
|
210
|
+
"angle_quotes": "Guillemets",
|
|
211
|
+
"straight_quotes": "Straight and curly quotes",
|
|
212
|
+
"parentheses": "Parentheses",
|
|
213
|
+
"other": "Other marks",
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
BASIC_STATS_DESC = {
|
|
217
|
+
"n_sents": "Sentences",
|
|
218
|
+
"n_words": "Words",
|
|
219
|
+
"n_unique_words": "Unique words",
|
|
220
|
+
"n_long_words": "Long words",
|
|
221
|
+
"n_complex_words": "Complex words",
|
|
222
|
+
"n_simple_words": "Simple words",
|
|
223
|
+
"n_monosyllable_words": "Monosyllabic words",
|
|
224
|
+
"n_polysyllable_words": "Polysyllabic words",
|
|
225
|
+
"n_chars": "Characters",
|
|
226
|
+
"n_letters": "Letters",
|
|
227
|
+
"n_spaces": "Spaces",
|
|
228
|
+
"n_syllables": "Syllables",
|
|
229
|
+
"n_punctuations": "Punctuation marks",
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
# Readability: thresholds of the formulas that differ from the basic statistics
|
|
233
|
+
LIX_LONG_WORD_LETTER_FACTOR = 7
|
|
234
|
+
SMOG_COMPLEX_SYL_FACTOR = 3
|
|
235
|
+
|
|
236
|
+
READABILITY_STATS_DESC = {
|
|
237
|
+
"flesch_reading_easy": "Flesch reading ease (Szigriszt-Pazos)",
|
|
238
|
+
"gutierrez_polini_index": "Gutiérrez de Polini comprehensibility",
|
|
239
|
+
"crawford_grade": "Crawford grade",
|
|
240
|
+
"mu_index": "Legibilidad µ",
|
|
241
|
+
"sol_grade": "SOL grade (SMOG for Spanish)",
|
|
242
|
+
"lix": "LIX readability index",
|
|
243
|
+
"rix": "RIX readability index",
|
|
244
|
+
"consensus_grade": "Consensus grade",
|
|
245
|
+
"reading_time": "Reading time (min)",
|
|
246
|
+
}
|
|
247
|
+
READABILITY_GRADE_STATS = ("crawford_grade", "sol_grade")
|
|
248
|
+
|
|
249
|
+
# Coefficients (a, b, c) of the Flesch reading ease c - a * ASL - b * ASW for Spanish:
|
|
250
|
+
# general - Szigriszt-Pazos (1993), classic - Fernández Huerta (1959)
|
|
251
|
+
READABILITY_PRESETS: dict[str, dict[str, tuple[float, float, float]]] = {
|
|
252
|
+
"general": {"flesch_reading_easy": (1.0, 62.3, 206.835)},
|
|
253
|
+
"classic": {"flesch_reading_easy": (1.02, 60.0, 206.84)},
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
# Interpretation of each preset: the scale of describe_level and the thresholds
|
|
257
|
+
# that convert the reading ease into years of schooling for the consensus grade.
|
|
258
|
+
# The INFLESZ bands are read through their text types and the school stages of
|
|
259
|
+
# Spain; the bands of Fernández Huerta are those of Flesch, so his own
|
|
260
|
+
# interpretation table gives the grades
|
|
261
|
+
PRESET_SCALES: dict[str, str] = {"general": "inflesz", "classic": "fernandez_huerta"}
|
|
262
|
+
READING_EASE_GRADES: dict[str, tuple[tuple[float, float], ...]] = {
|
|
263
|
+
"general": ((80, 3), (65, 5), (55, 8), (40, 11)),
|
|
264
|
+
"classic": ((90, 5), (80, 6), (70, 7), (60, 8.5), (50, 10), (40, 11), (30, 12)),
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
# Interpretation scales of the Flesch reading ease: lower bound of each band
|
|
268
|
+
READING_EASE_SCALES: dict[str, tuple[tuple[float, str], ...]] = {
|
|
269
|
+
# Barrio-Cantalejo et al. (2008), for the Szigriszt-Pazos formula
|
|
270
|
+
"inflesz": (
|
|
271
|
+
(80, "muy fácil"),
|
|
272
|
+
(65, "bastante fácil"),
|
|
273
|
+
(55, "normal"),
|
|
274
|
+
(40, "algo difícil"),
|
|
275
|
+
(0, "muy difícil"),
|
|
276
|
+
),
|
|
277
|
+
# Szigriszt-Pazos (1993): 0-15, 16-35, 36-50, 51-65, 66-75, 76-85, 86-100
|
|
278
|
+
"szigriszt": (
|
|
279
|
+
(86, "muy fácil"),
|
|
280
|
+
(76, "fácil"),
|
|
281
|
+
(66, "bastante fácil"),
|
|
282
|
+
(51, "normal"),
|
|
283
|
+
(36, "bastante difícil"),
|
|
284
|
+
(16, "árido"),
|
|
285
|
+
(0, "muy difícil"),
|
|
286
|
+
),
|
|
287
|
+
# Fernández Huerta (1959)
|
|
288
|
+
"fernandez_huerta": (
|
|
289
|
+
(90, "muy fácil"),
|
|
290
|
+
(80, "fácil"),
|
|
291
|
+
(70, "bastante fácil"),
|
|
292
|
+
(60, "normal"),
|
|
293
|
+
(50, "bastante difícil"),
|
|
294
|
+
(30, "difícil"),
|
|
295
|
+
(0, "muy difícil"),
|
|
296
|
+
),
|
|
297
|
+
}
|
|
298
|
+
# Muñoz Baquedano and Muñoz Urra (2006): lower bound of each band of Legibilidad µ
|
|
299
|
+
MU_SCALE: tuple[tuple[float, str], ...] = (
|
|
300
|
+
(91, "muy fácil"),
|
|
301
|
+
(81, "fácil"),
|
|
302
|
+
(71, "un poco fácil"),
|
|
303
|
+
(61, "adecuado"),
|
|
304
|
+
(51, "un poco difícil"),
|
|
305
|
+
(31, "difícil"),
|
|
306
|
+
(0, "muy difícil"),
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
# School stages of Spain by years of schooling from the first year of primary school
|
|
310
|
+
GRADE_AGE_LEVELS: tuple[tuple[int, int, str, str], ...] = (
|
|
311
|
+
(1, 3, "primary school, grades 1-3", "6-9 years"),
|
|
312
|
+
(4, 6, "primary school, grades 4-6", "9-12 years"),
|
|
313
|
+
(7, 10, "ESO", "12-16 years"),
|
|
314
|
+
(11, 12, "bachillerato", "16-18 years"),
|
|
315
|
+
(13, 16, "university", "18-22 years"),
|
|
316
|
+
)
|
|
317
|
+
POSTGRADUATE_LEVEL = ("postgraduate", "over 22 years")
|
|
318
|
+
|
|
319
|
+
# Silent reading speed of adults in Spanish, words per minute: Brysbaert (2019),
|
|
320
|
+
# mean of six studies; reading aloud - 191
|
|
321
|
+
READING_SPEED_WPM = 278
|
|
322
|
+
# Reading speed norms (aloud, silent) in words per minute: means by school year
|
|
323
|
+
# from the meta-analysis of Ripoll, Tapia and Aguado (2020), grades 1-6 primary
|
|
324
|
+
# school, 7-10 ESO, 11 bachillerato; adults - Brysbaert (2019)
|
|
325
|
+
READING_SPEED_NORMS: dict[str, tuple[int, int]] = {
|
|
326
|
+
"grade_1": (49, 30),
|
|
327
|
+
"grade_2": (73, 79),
|
|
328
|
+
"grade_3": (85, 95),
|
|
329
|
+
"grade_4": (104, 125),
|
|
330
|
+
"grade_5": (114, 137),
|
|
331
|
+
"grade_6": (124, 155),
|
|
332
|
+
"grade_7": (134, 180),
|
|
333
|
+
"grade_8": (136, 176),
|
|
334
|
+
"grade_9": (143, 180),
|
|
335
|
+
"grade_10": (164, 200),
|
|
336
|
+
"grade_11": (161, 186),
|
|
337
|
+
"adult": (191, 278),
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
# Lexical diversity: the conventions of koRpus and lexical-diversity
|
|
341
|
+
MATTR_WINDOW_LEN = 50
|
|
342
|
+
MTLD_TTR_THRESHOLD = 0.72
|
|
343
|
+
MTLD_MIN_LEN = 10
|
|
344
|
+
# Block of factor starts and window of offsets in the MA-MTLD and MTLD-W computation
|
|
345
|
+
MTLD_BLOCK_SIZE = 4096
|
|
346
|
+
MTLD_WINDOW_LEN = 32
|
|
347
|
+
HDD_SAMPLE_SIZE = 42
|
|
348
|
+
DIVERSITY_LOG_BASE = 10
|
|
349
|
+
BRUNET_W_EXPONENT = 0.172
|
|
350
|
+
DIVERSITY_STATS_DESC = {
|
|
351
|
+
"ttr": "Type-Token Ratio (TTR)",
|
|
352
|
+
"rttr": "Root Type-Token Ratio (RTTR)",
|
|
353
|
+
"cttr": "Corrected Type-Token Ratio (CTTR)",
|
|
354
|
+
"httr": "Herdan Type-Token Ratio (HTTR)",
|
|
355
|
+
"sttr": "Summer Type-Token Ratio (STTR)",
|
|
356
|
+
"mttr": "Maas Type-Token Ratio (MTTR)",
|
|
357
|
+
"dttr": "Dugast Type-Token Ratio (DTTR)",
|
|
358
|
+
"mattr": "Moving Average Type-Token Ratio (MATTR)",
|
|
359
|
+
"msttr": "Mean Segmental Type-Token Ratio (MSTTR)",
|
|
360
|
+
"mtld": "Measure of Textual Lexical Diversity (MTLD)",
|
|
361
|
+
"mamtld": "Moving Average Measure of Textual Lexical Diversity (MA-MTLD)",
|
|
362
|
+
"mtldw": "Moving Average Measure of Textual Lexical Diversity with Wrap (MTLD-W)",
|
|
363
|
+
"hdd": "Hypergeometric Distribution D (HD-D)",
|
|
364
|
+
"simpson_index": "Simpson's index (D)",
|
|
365
|
+
"inverse_simpson_index": "Inverse Simpson's index (1/D)",
|
|
366
|
+
"gini_simpson_index": "Gini-Simpson index (1-D)",
|
|
367
|
+
"hapax_index": "Hapax index (Honoré's R)",
|
|
368
|
+
"yule_k": "Yule's characteristic K",
|
|
369
|
+
"yule_i": "Yule's inverse characteristic I",
|
|
370
|
+
"herdan_vm": "Herdan's Vm",
|
|
371
|
+
"sichel_s": "Sichel's S",
|
|
372
|
+
"michea_m": "Michéa's M",
|
|
373
|
+
"brunet_w": "Brunet's W",
|
|
374
|
+
"dugast_k": "Dugast's k",
|
|
375
|
+
"baayen_p": "Baayen's P",
|
|
376
|
+
"hapax_ratio": "Hapax ratio",
|
|
377
|
+
"alpha2": "Exponent α₂",
|
|
378
|
+
"entropy": "Shannon entropy (bits)",
|
|
379
|
+
"evenness": "Evenness",
|
|
380
|
+
"perplexity": "Perplexity",
|
|
381
|
+
"zipf_alpha": "Zipf's law slope (α)",
|
|
382
|
+
"heaps_beta": "Heaps' law exponent (β)",
|
|
383
|
+
}
|