Skip to content

Commit e17da34

Browse files
committed
feat(extractor): docstring some methods from extract.py
1 parent 1d50a85 commit e17da34

File tree

1 file changed

+70
-22
lines changed

1 file changed

+70
-22
lines changed

extractor/extract.py

Lines changed: 70 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,18 @@ def _get_forms_with_variant(
4343
lemma_subdict: dict, postag: str, prefix: str = ""
4444
) -> list[Form]:
4545
"""
46-
TODO: Docstring this.
46+
Returns all forms of a lemma matching a given base POS tag, including
47+
all variant and diacritic variants.
48+
49+
Args:
50+
lemma_subdict (dict): A lemma-specific submapping from fully specified
51+
POS tags to surface word forms.
52+
postag (str): The base POS tag identifying a grammatical slot without the
53+
variant code.
54+
prefix (str): Prefix associated with the resulting Forms.
55+
56+
Returns:
57+
list[Form]: All matching Forms or an empty list if None are found.
4758
"""
4859
result = []
4960

@@ -79,16 +90,27 @@ def _get_forms_with_variant(
7990

8091
def _get_verb_mode(postag: str) -> str:
8192
"""
82-
TODO: Docstring this.
93+
Gets the verb mode (Infinitive, Subjuntive, Imperative) from the pos tag
94+
representation.
95+
96+
Args:
97+
postag (str): The postag representation.
98+
99+
Returns:
100+
str: The character representing the verb mode.
83101
"""
84102
return postag[2]
85103

86104

87105
def _set_plurals_singulars(tense: Tense, lemma_subdict: dict) -> None:
88106
"""
89-
TODO: Docstring this.
107+
Sets the plural and singular forms of a verb tense.
108+
109+
Args:
110+
tense (Tense): The verb tense without the forms.
111+
lemma_subdict (dict): A lemma-specific submapping from fully specified postags.
90112
91-
BEWARE: This function modifies tense in place, like a C function of
113+
NOTE: This function modifies tense in place, like a C function of
92114
void _set_plurals_singulars(&tense);
93115
"""
94116
if _get_verb_mode(tense.postag) not in ["I", "S", "M"]:
@@ -118,9 +140,13 @@ def _set_plurals_singulars_participi(
118140
tense: Tense, lemma_subdict: dict
119141
) -> None:
120142
"""
121-
TODO: Docstring this.
143+
Sets the plurals and singulars of a tense for the participi.
144+
145+
Args:
146+
tense (Tense): The verb tense without the forms.
147+
lemma_subdict (dict): A lemma-specific submapping from fully specified postags.
122148
123-
BEWARE: This function modifies tense in place, like a C function of
149+
NOTE: This function modifies tense in place, like a C function of
124150
void _set_plurals_singulars_participi(&tense);
125151
"""
126152
if _get_verb_mode(tense.postag) != "P":
@@ -143,7 +169,7 @@ def _set_plurals_singulars0(tense: Tense, lemma_subdict: dict) -> None:
143169
"""
144170
TODO: Docstring this.
145171
146-
BEWARE: This function modifies tense in place, like a C function of
172+
NOTE: This function modifies tense in place, like a C function of
147173
void _set_plurals_singulars_participi(&tense);
148174
"""
149175
tense.singular1 = _get_forms_with_variant(
@@ -155,7 +181,7 @@ def _set_infinitiu_compost(tense: Tense, lemma_subdict: dict) -> None:
155181
"""
156182
TODO: Docstring this.
157183
158-
BEWARE: This function modifies tense in place, like a C function of
184+
NOTE: This function modifies tense in place, like a C function of
159185
void _set_infinitiu_compost(&tense);
160186
"""
161187
if _get_verb_mode(tense.postag) != "P":
@@ -184,7 +210,7 @@ def _set_gerundi_compost(tense: Tense, lemma_subdict: dict) -> None:
184210
"""
185211
TODO: Docstring this.
186212
187-
BEWARE: This function modifies tense in place, like a C function of
213+
NOTE: This function modifies tense in place, like a C function of
188214
void _set_gerundi_compost(&tense);
189215
"""
190216
if _get_verb_mode(tense.postag) != "P":
@@ -198,7 +224,7 @@ def _set_perfet_indicatiu(tense: Tense, lemma_subdict: dict) -> None:
198224
"""
199225
TODO: Docstring this.
200226
201-
BEWARE: This function modifies tense in place, like a C function of
227+
NOTE: This function modifies tense in place, like a C function of
202228
void _set_perfet_indicatiu(&tense);
203229
"""
204230
if _get_verb_mode(tense.postag) != "P":
@@ -228,7 +254,7 @@ def _set_plusquamperfet_indicatiu(tense: Tense, lemma_subdict: dict) -> None:
228254
"""
229255
TODO: Docstring this.
230256
231-
BEWARE: This function modifies tense in place, like a C function of
257+
NOTE: This function modifies tense in place, like a C function of
232258
void _set_plusquamperfet_indicatiu(&tense);
233259
"""
234260
if _get_verb_mode(tense.postag) != "P":
@@ -260,7 +286,7 @@ def _set_passatperifrastic_indicatiu(
260286
"""
261287
TODO: Docstring this.
262288
263-
BEWARE: This function modifies tense in place, like a C function of
289+
NOTE: This function modifies tense in place, like a C function of
264290
void _set_passatperifrastic_indicatiu(&tense);
265291
"""
266292
if _get_verb_mode(tense.postag) != "N":
@@ -290,7 +316,7 @@ def _set_passatanterior_indicatiu(tense: Tense, lemma_subdict: dict) -> None:
290316
"""
291317
TODO: Docstring this.
292318
293-
BEWARE: This function modifies tense in place, like a C function of
319+
NOTE: This function modifies tense in place, like a C function of
294320
void _set_passatanterior_indicatiu(&tense);
295321
"""
296322
if _get_verb_mode(tense.postag) != "P":
@@ -322,7 +348,7 @@ def _set_passatanteriorperifrastic_indicatiu(
322348
"""
323349
TODO: Docstring this.
324350
325-
BEWARE: This function modifies tense in place, like a C function of
351+
NOTE: This function modifies tense in place, like a C function of
326352
void _set_passatanteriorperifrastic_indicatiu(&tense);
327353
"""
328354
if _get_verb_mode(tense.postag) != "P":
@@ -352,7 +378,7 @@ def _set_futurperfet_indicatiu(tense: Tense, lemma_subdict: dict) -> None:
352378
"""
353379
TODO: Docstring this.
354380
355-
BEWARE: This function modifies tense in place, like a C function of
381+
NOTE: This function modifies tense in place, like a C function of
356382
void _set_futurperfet_indicatiu(&tense);
357383
"""
358384
if _get_verb_mode(tense.postag) != "P":
@@ -384,7 +410,7 @@ def _set_condicionalperfet_indicatiu(
384410
"""
385411
TODO: Docstring this.
386412
387-
BEWARE: This function modifies tense in place, like a C function of
413+
NOTE: This function modifies tense in place, like a C function of
388414
void _set_condicionalperfet_indicatiu(&tense);
389415
"""
390416
if _get_verb_mode(tense.postag) != "P":
@@ -414,7 +440,7 @@ def _set_perfet_subjuntiu(tense: Tense, lemma_subdict: dict) -> None:
414440
"""
415441
TODO: Docstring this.
416442
417-
BEWARE: This function modifies tense in place, like a C function of
443+
NOTE: This function modifies tense in place, like a C function of
418444
void _set_perfet_subjuntiu(&tense);
419445
"""
420446
if _get_verb_mode(tense.postag) != "P":
@@ -444,7 +470,7 @@ def _set_plusquamperfet_subjuntiu(tense: Tense, lemma_subdict: dict) -> None:
444470
"""
445471
TODO: Docstring this.
446472
447-
BEWARE: This function modifies tense in place, like a C function of
473+
NOTE: This function modifies tense in place, like a C function of
448474
void _set_plusquamperfet_subjuntiu(&tense);
449475
"""
450476
if _get_verb_mode(tense.postag) != "P":
@@ -602,7 +628,12 @@ def _get_tenses(input_dict: dict, lemma: str) -> list[Tense]:
602628

603629
def _serialize_to_file(file_dir: str, lemma: str, tenses: list[Tense]) -> None:
604630
"""
605-
TODO: Docstring this.
631+
Serializes the tenses information of a lema into a file in disk.
632+
633+
Args:
634+
file_dir (str): The directory where to store the file at.
635+
lemma (str): The lemma of which we want to store information.
636+
tenses (list[Tense]): The list of tenses and information of the lemma.
606637
"""
607638
d = {}
608639
d[lemma] = tenses
@@ -675,7 +706,14 @@ def _get_dictionary(
675706
dictionary_file: str, exclusions_file: str
676707
) -> DictionaryFile:
677708
"""
678-
TODO: Docstring this.
709+
Gets a dictionary object with some selected lemmas excluded.
710+
711+
Args:
712+
dictionary_file (str): The path to the dictionary.
713+
exclusions_file (str): The path to the file with the exclusions
714+
715+
Returns:
716+
DictionaryFile: A dictionary containing entries with 'form lemma postag'.
679717
"""
680718
dictionary = DictionaryFile(dictionary_file)
681719
exclusions = ExclusionsFile(exclusions_file)
@@ -690,7 +728,14 @@ def extract_from_dictfile(
690728
output_dir: str,
691729
) -> int:
692730
"""
693-
TODO: Docstring this.
731+
Creates a file for every lemma contained in the dictionary and populates it
732+
with all the tenses, forms and definitions.
733+
734+
Args:
735+
dictionary_file (str): The path to the dictionary file to load.
736+
exclusions_file (str): The path to the file containing lemmas to exclude.
737+
definitions_file (str): The path to the file containing definitions.
738+
output_dir (str): The directory where to store the final lemma files.
694739
"""
695740
dictionary = _get_dictionary(dictionary_file, exclusions_file)
696741
lemmas = dictionary.get_lemmas_for_infinitives()
@@ -741,7 +786,10 @@ def extract_infinitives(
741786

742787
def read_parameters() -> bool:
743788
"""
744-
TODO: Docstring this.
789+
Returns whether the application was launched with infinitives only mode.
790+
791+
Returns:
792+
bool: True if infinitives only, else, False.
745793
"""
746794
parser = OptionParser()
747795

0 commit comments

Comments
 (0)