|
12 | 12 |
|
13 | 13 | from __future__ import annotations |
14 | 14 |
|
| 15 | +from typing import Optional |
| 16 | + |
15 | 17 | import nltk |
16 | 18 |
|
17 | 19 | try: |
|
27 | 29 | from nltk.corpus import wordnet |
28 | 30 |
|
29 | 31 |
|
30 | | -def synsets(word: str, pos: str | None = None, lang: str = "tha"): |
| 32 | +def synsets(word: str, pos: Optional[str] = None, lang: str = "tha"): |
31 | 33 | """This function returns the synonym set for all lemmas of the given word |
32 | 34 | with an optional argument to constrain the part of speech of the word. |
33 | 35 |
|
34 | 36 | :param str word: word to find synsets of |
35 | | - :param str | None pos: constraint of the part of speech (i.e. *n* for Noun, *v* |
| 37 | + :param Optional[str] pos: constraint of the part of speech (i.e. *n* for Noun, *v* |
36 | 38 | for Verb, *a* for Adjective, *s* for Adjective |
37 | 39 | satellites, and *r* for Adverb). Default is None. |
38 | 40 | :param str lang: abbreviation of language (i.e. *eng*, *tha*). |
@@ -98,12 +100,12 @@ def synset(name_synsets): |
98 | 100 | return wordnet.synset(name_synsets) |
99 | 101 |
|
100 | 102 |
|
101 | | -def all_lemma_names(pos: str | None = None, lang: str = "tha"): |
| 103 | +def all_lemma_names(pos: Optional[str] = None, lang: str = "tha"): |
102 | 104 | """This function returns all lemma names for all synsets of the given |
103 | 105 | part of speech tag and language. If part of speech tag is not |
104 | 106 | specified, all synsets of all parts of speech will be used. |
105 | 107 |
|
106 | | - :param str | None pos: constraint of the part of speech (i.e. *n* for Noun, |
| 108 | + :param Optional[str] pos: constraint of the part of speech (i.e. *n* for Noun, |
107 | 109 | *v* for Verb, *a* for Adjective, *s* for |
108 | 110 | Adjective satellites, and *r* for Adverb). |
109 | 111 | By default, *pos* is **None**. |
@@ -140,11 +142,11 @@ def all_lemma_names(pos: str | None = None, lang: str = "tha"): |
140 | 142 | return wordnet.all_lemma_names(pos=pos, lang=lang) |
141 | 143 |
|
142 | 144 |
|
143 | | -def all_synsets(pos: str | None = None): |
| 145 | +def all_synsets(pos: Optional[str] = None): |
144 | 146 | """This function iterates over all synsets constrained by the given |
145 | 147 | part of speech tag. |
146 | 148 |
|
147 | | - :param str | None pos: part of speech tag. Default is None. |
| 149 | + :param Optional[str] pos: part of speech tag. Default is None. |
148 | 150 |
|
149 | 151 | :return: list of synsets constrained by the given part of speech tag. |
150 | 152 | :rtype: Iterable[:class:`Synset`] |
@@ -188,12 +190,12 @@ def langs(): |
188 | 190 | return wordnet.langs() |
189 | 191 |
|
190 | 192 |
|
191 | | -def lemmas(word: str, pos: str | None = None, lang: str = "tha"): |
| 193 | +def lemmas(word: str, pos: Optional[str] = None, lang: str = "tha"): |
192 | 194 | """This function returns all lemmas given the word with an optional |
193 | 195 | argument to constrain the part of speech of the word. |
194 | 196 |
|
195 | 197 | :param str word: word to find lemmas of |
196 | | - :param str | None pos: constraint of the part of speech (i.e. *n* for Noun, |
| 198 | + :param Optional[str] pos: constraint of the part of speech (i.e. *n* for Noun, |
197 | 199 | *v* for Verb, *a* for Adjective, *s* for |
198 | 200 | Adjective satellites, and *r* for Adverb). Default is None. |
199 | 201 | :param str lang: abbreviation of language (i.e. *eng*, *tha*). |
@@ -391,12 +393,12 @@ def wup_similarity(synsets1, synsets2): |
391 | 393 | return wordnet.wup_similarity(synsets1, synsets2) |
392 | 394 |
|
393 | 395 |
|
394 | | -def morphy(form, pos: str | None = None): |
| 396 | +def morphy(form, pos: Optional[str] = None): |
395 | 397 | """This function finds a possible base form for the given form, |
396 | 398 | with the given part of speech. |
397 | 399 |
|
398 | 400 | :param str form: the form to finds the base form of |
399 | | - :param str | None pos: part of speech tag of words to be searched. |
| 401 | + :param Optional[str] pos: part of speech tag of words to be searched. |
400 | 402 | Default is None. |
401 | 403 |
|
402 | 404 | :return: base form of the given form |
|
0 commit comments