1212
1313from __future__ import annotations
1414
15+ from collections .abc import Iterable
1516from typing import Optional
1617
1718import nltk
2930from nltk .corpus import wordnet
3031
3132
32- def synsets (word : str , pos : Optional [str ] = None , lang : str = "tha" ):
33+ def synsets (word : str , pos : Optional [str ] = None , lang : str = "tha" ) -> list [ wordnet . Synset ] :
3334 """This function returns the synonym set for all lemmas of the given word
3435 with an optional argument to constrain the part of speech of the word.
3536
@@ -76,7 +77,7 @@ def synsets(word: str, pos: Optional[str] = None, lang: str = "tha"):
7677 return wordnet .synsets (lemma = word , pos = pos , lang = lang )
7778
7879
79- def synset (name_synsets ) :
80+ def synset (name_synsets : str ) -> wordnet . Synset :
8081 """This function returns the synonym set (synset) given the name of the synset
8182 (i.e. 'dog.n.01', 'chase.v.01').
8283
@@ -100,7 +101,7 @@ def synset(name_synsets):
100101 return wordnet .synset (name_synsets )
101102
102103
103- def all_lemma_names (pos : Optional [str ] = None , lang : str = "tha" ):
104+ def all_lemma_names (pos : Optional [str ] = None , lang : str = "tha" ) -> list [ str ] :
104105 """This function returns all lemma names for all synsets of the given
105106 part of speech tag and language. If part of speech tag is not
106107 specified, all synsets of all parts of speech will be used.
@@ -142,7 +143,7 @@ def all_lemma_names(pos: Optional[str] = None, lang: str = "tha"):
142143 return wordnet .all_lemma_names (pos = pos , lang = lang )
143144
144145
145- def all_synsets (pos : Optional [str ] = None ):
146+ def all_synsets (pos : Optional [str ] = None ) -> Iterable [ wordnet . Synset ] :
146147 """This function iterates over all synsets constrained by the given
147148 part of speech tag.
148149
@@ -172,7 +173,7 @@ def all_synsets(pos: Optional[str] = None):
172173 return wordnet .all_synsets (pos = pos )
173174
174175
175- def langs ():
176+ def langs () -> list [ str ] :
176177 """This function returns a set of ISO-639 language codes.
177178
178179 :return: ISO-639 language codes
@@ -190,7 +191,7 @@ def langs():
190191 return wordnet .langs ()
191192
192193
193- def lemmas (word : str , pos : Optional [str ] = None , lang : str = "tha" ):
194+ def lemmas (word : str , pos : Optional [str ] = None , lang : str = "tha" ) -> list [ wordnet . Lemma ] :
194195 """This function returns all lemmas given the word with an optional
195196 argument to constrain the part of speech of the word.
196197
@@ -233,7 +234,7 @@ def lemmas(word: str, pos: Optional[str] = None, lang: str = "tha"):
233234 return wordnet .lemmas (word , pos = pos , lang = lang )
234235
235236
236- def lemma (name_synsets ) :
237+ def lemma (name_synsets : str ) -> wordnet . Lemma :
237238 """This function returns lemma object given the name.
238239
239240 .. note::
@@ -260,7 +261,7 @@ def lemma(name_synsets):
260261 return wordnet .lemma (name_synsets )
261262
262263
263- def lemma_from_key (key ) :
264+ def lemma_from_key (key : str ) -> wordnet . Lemma :
264265 """This function returns lemma object given the lemma key.
265266 This is similar to :func:`lemma` but it needs to be given the key
266267 of lemma instead of the name of lemma.
@@ -286,7 +287,7 @@ def lemma_from_key(key):
286287 return wordnet .lemma_from_key (key )
287288
288289
289- def path_similarity (synsets1 , synsets2 ) :
290+ def path_similarity (synsets1 : wordnet . Synset , synsets2 : wordnet . Synset ) -> float :
290291 """This function returns similarity between two synsets based on the
291292 shortest path distance calculated using the equation below.
292293
@@ -325,7 +326,7 @@ def path_similarity(synsets1, synsets2):
325326 return wordnet .path_similarity (synsets1 , synsets2 )
326327
327328
328- def lch_similarity (synsets1 , synsets2 ) :
329+ def lch_similarity (synsets1 : wordnet . Synset , synsets2 : wordnet . Synset ) -> float :
329330 """This function returns Leacock Chodorow similarity (LCH)
330331 between two synsets, based on the shortest path distance
331332 and the maximum depth of the taxonomy. The equation to
@@ -362,7 +363,7 @@ def lch_similarity(synsets1, synsets2):
362363 return wordnet .lch_similarity (synsets1 , synsets2 )
363364
364365
365- def wup_similarity (synsets1 , synsets2 ) :
366+ def wup_similarity (synsets1 : wordnet . Synset , synsets2 : wordnet . Synset ) -> float :
366367 """This function returns Wu-Palmer similarity (WUP) between two synsets,
367368 based on the depth of the two senses in the taxonomy and their
368369 Least Common Subsumer (most specific ancestor node).
@@ -393,7 +394,7 @@ def wup_similarity(synsets1, synsets2):
393394 return wordnet .wup_similarity (synsets1 , synsets2 )
394395
395396
396- def morphy (form , pos : Optional [str ] = None ):
397+ def morphy (form : str , pos : Optional [str ] = None ) -> str :
397398 """This function finds a possible base form for the given form,
398399 with the given part of speech.
399400
@@ -423,7 +424,7 @@ def morphy(form, pos: Optional[str] = None):
423424 return wordnet .morphy (form , pos = None )
424425
425426
426- def custom_lemmas (tab_file , lang : str ):
427+ def custom_lemmas (tab_file , lang : str ) -> None :
427428 """This function reads a custom tab file
428429 (see: http://compling.hss.ntu.edu.sg/omw/)
429430 containing mappings of lemmas in the given language.
0 commit comments