1212
1313import itertools
1414from collections import OrderedDict
15- from typing import Callable , Optional
15+ from typing import Any , Callable , Optional
1616
1717from nltk .corpus import wordnet as wn
1818
@@ -112,12 +112,24 @@ def postype2wordnet(pos: str, corpus: str) -> Optional[str]:
112112 """
113113 if corpus not in ["orchid" ]:
114114 return None
115- return orchid [pos ] # type: ignore[no-any-return]
115+ return orchid [pos ]
116116
117117
118118class WordNetAug :
119119 """Text Augment using wordnet"""
120120
121+ synonyms : list [str ]
122+ list_synsets : list
123+ p2w_pos : Optional [str ]
124+ synset : Any
125+ syn : str
126+ synonyms_without_duplicates : list [str ]
127+ list_words : list [str ]
128+ list_synonym : list
129+ p_all : int
130+ list_pos : list [tuple [str , str ]]
131+ temp : list [str ]
132+
121133 def __init__ (self ) -> None :
122134 pass
123135
@@ -137,13 +149,13 @@ def find_synonyms(
137149 """
138150 self .synonyms : list [str ] = []
139151 if pos is None :
140- self .list_synsets = wordnet .synsets (word )
152+ self .list_synsets : list = wordnet .synsets (word )
141153 else :
142- self .p2w_pos = postype2wordnet (pos , postag_corpus )
154+ self .p2w_pos : Optional [ str ] = postype2wordnet (pos , postag_corpus )
143155 if self .p2w_pos != "" :
144- self .list_synsets = wordnet .synsets (word , pos = self .p2w_pos )
156+ self .list_synsets : list = wordnet .synsets (word , pos = self .p2w_pos )
145157 else :
146- self .list_synsets = wordnet .synsets (word )
158+ self .list_synsets : list = wordnet .synsets (word )
147159
148160 for self .synset in wordnet .synsets (word ):
149161 for self .syn in self .synset .lemma_names (lang = "tha" ):
@@ -189,7 +201,7 @@ def augment(
189201 """
190202 new_sentences = []
191203 self .list_words : list [str ] = tokenize (sentence )
192- self .list_synonym : list [ list [ str ]] = []
204+ self .list_synonym : list = []
193205 self .p_all : int = 1
194206 if postag :
195207 self .list_pos : list [tuple [str , str ]] = pos_tag (
@@ -206,7 +218,7 @@ def augment(
206218 self .p_all *= len (self .temp )
207219 else :
208220 for word in self .list_words :
209- self .temp = self .find_synonyms (word )
221+ self .temp : list [ str ] = self .find_synonyms (word )
210222 if not self .temp :
211223 self .list_synonym .append ([word ])
212224 else :
0 commit comments