3030 nltk .download ("wordnet" )
3131
3232from nltk .corpus import wordnet
33+ from nltk .corpus .reader .wordnet import Lemma , Synset
3334
3435
3536def synsets (
3637 word : str , pos : Optional [str ] = None , lang : str = "tha"
37- ) -> list [wordnet . Synset ]:
38+ ) -> list [Synset ]:
3839 """This function returns the synonym set for all lemmas of the given word
3940 with an optional argument to constrain the part of speech of the word.
4041
@@ -78,12 +79,10 @@ def synsets(
7879 >>> synsets("แรง", pos="a", lang="tha")
7980 [Synset('hard.s.10'), Synset('strong.s.02')]
8081 """
81- return cast (
82- list [wordnet .Synset ], wordnet .synsets (lemma = word , pos = pos , lang = lang )
83- )
82+ return cast (list [Synset ], wordnet .synsets (lemma = word , pos = pos , lang = lang ))
8483
8584
86- def synset (name_synsets : str ) -> wordnet . Synset :
85+ def synset (name_synsets : str ) -> Synset :
8786 """This function returns the synonym set (synset) given the name of the synset
8887 (i.e. 'dog.n.01', 'chase.v.01').
8988
@@ -149,7 +148,7 @@ def all_lemma_names(pos: Optional[str] = None, lang: str = "tha") -> list[str]:
149148 return cast (list [str ], wordnet .all_lemma_names (pos = pos , lang = lang ))
150149
151150
152- def all_synsets (pos : Optional [str ] = None ) -> Iterable [wordnet . Synset ]:
151+ def all_synsets (pos : Optional [str ] = None ) -> Iterable [Synset ]:
153152 """This function iterates over all synsets constrained by the given
154153 part of speech tag.
155154
@@ -176,7 +175,7 @@ def all_synsets(pos: Optional[str] = None) -> Iterable[wordnet.Synset]:
176175 >>> next(generator)
177176 Synset('unable.a.01')
178177 """
179- return cast (Iterable [wordnet . Synset ], wordnet .all_synsets (pos = pos ))
178+ return cast (Iterable [Synset ], wordnet .all_synsets (pos = pos ))
180179
181180
182181def langs () -> list [str ]:
@@ -199,7 +198,7 @@ def langs() -> list[str]:
199198
200199def lemmas (
201200 word : str , pos : Optional [str ] = None , lang : str = "tha"
202- ) -> list [wordnet . Lemma ]:
201+ ) -> list [Lemma ]:
203202 """This function returns all lemmas given the word with an optional
204203 argument to constrain the part of speech of the word.
205204
@@ -239,10 +238,10 @@ def lemmas(
239238 >>> lemmas("ม้วน", pos="n")
240239 [Lemma('roll.n.11.ม้วน')]
241240 """
242- return cast (list [wordnet . Lemma ], wordnet .lemmas (word , pos = pos , lang = lang ))
241+ return cast (list [Lemma ], wordnet .lemmas (word , pos = pos , lang = lang ))
243242
244243
245- def lemma (name_synsets : str ) -> wordnet . Lemma :
244+ def lemma (name_synsets : str ) -> Lemma :
246245 """This function returns lemma object given the name.
247246
248247 .. note::
@@ -269,7 +268,7 @@ def lemma(name_synsets: str) -> wordnet.Lemma:
269268 return wordnet .lemma (name_synsets )
270269
271270
272- def lemma_from_key (key : str ) -> wordnet . Lemma :
271+ def lemma_from_key (key : str ) -> Lemma :
273272 """This function returns lemma object given the lemma key.
274273 This is similar to :func:`lemma` but it needs to be given the key
275274 of lemma instead of the name of lemma.
@@ -295,9 +294,7 @@ def lemma_from_key(key: str) -> wordnet.Lemma:
295294 return wordnet .lemma_from_key (key )
296295
297296
298- def path_similarity (
299- synsets1 : wordnet .Synset , synsets2 : wordnet .Synset
300- ) -> float :
297+ def path_similarity (synsets1 : Synset , synsets2 : Synset ) -> float :
301298 """This function returns similarity between two synsets based on the
302299 shortest path distance calculated using the equation below.
303300
@@ -336,9 +333,7 @@ def path_similarity(
336333 return cast (float , wordnet .path_similarity (synsets1 , synsets2 ))
337334
338335
339- def lch_similarity (
340- synsets1 : wordnet .Synset , synsets2 : wordnet .Synset
341- ) -> float :
336+ def lch_similarity (synsets1 : Synset , synsets2 : Synset ) -> float :
342337 """This function returns Leacock Chodorow similarity (LCH)
343338 between two synsets, based on the shortest path distance
344339 and the maximum depth of the taxonomy. The equation to
@@ -375,9 +370,7 @@ def lch_similarity(
375370 return cast (float , wordnet .lch_similarity (synsets1 , synsets2 ))
376371
377372
378- def wup_similarity (
379- synsets1 : wordnet .Synset , synsets2 : wordnet .Synset
380- ) -> float :
373+ def wup_similarity (synsets1 : Synset , synsets2 : Synset ) -> float :
381374 """This function returns Wu-Palmer similarity (WUP) between two synsets,
382375 based on the depth of the two senses in the taxonomy and their
383376 Least Common Subsumer (most specific ancestor node).
0 commit comments