Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pythainlp/augment/lm/wangchanberta.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ def augment(self, sentence: str, num_replace_tokens: int = 3) -> list[str]:
'ช้างมีทั้งหมด 50 ตัว บนหัว']
"""
sent2 = self.generate(sentence, num_replace_tokens)
return sent2
return sent2 # type: ignore[no-any-return]
2 changes: 1 addition & 1 deletion pythainlp/augment/word2vec/bpemb_wv.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def tokenizer(self, text: str) -> list[str]:
""":param str text: Thai text
:rtype: List[str]
"""
return self.bpemb_temp.encode(text)
return self.bpemb_temp.encode(text) # type: ignore[no-any-return]

def load_w2v(self):
"""Load BPEmb model
Expand Down
14 changes: 7 additions & 7 deletions pythainlp/benchmarks/word_tokenization.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ def compute_stats(ref_sample: str, raw_sample: str) -> dict:
c_pos_pred = c_pos_pred[c_pos_pred < ref_sample_arr.shape[0]]
c_neg_pred = c_neg_pred[c_neg_pred < ref_sample_arr.shape[0]]

c_tp = np.sum(ref_sample_arr[c_pos_pred] == 1)
c_fp = np.sum(ref_sample_arr[c_pos_pred] == 0)
c_tp: np.intp = np.sum(ref_sample_arr[c_pos_pred] == 1)
c_fp: np.intp = np.sum(ref_sample_arr[c_pos_pred] == 0)

c_tn = np.sum(ref_sample_arr[c_neg_pred] == 0)
c_fn = np.sum(ref_sample_arr[c_neg_pred] == 1)
c_tn: np.intp = np.sum(ref_sample_arr[c_neg_pred] == 0)
c_fn: np.intp = np.sum(ref_sample_arr[c_neg_pred] == 1)

# Compute word-level statistics

Expand All @@ -174,7 +174,7 @@ def compute_stats(ref_sample: str, raw_sample: str) -> dict:
word_boundaries, ss_boundaries
)

correctly_tokenised_words = np.sum(tokenization_indicators)
correctly_tokenised_words: np.intp = np.sum(tokenization_indicators)

tokenization_indicators_str = list(map(str, tokenization_indicators))

Expand Down Expand Up @@ -206,14 +206,14 @@ def _binary_representation(txt: str, verbose: bool = False) -> np.ndarray:
:param bool verbose: for debugging purposes

:return: {0, 1} sequence
:rtype: str
:rtype: np.ndarray
"""
chars = np.array(list(txt))

boundary = np.argwhere(chars == SEPARATOR).reshape(-1)
boundary = boundary - np.array(range(boundary.shape[0]))

bin_rept = np.zeros(len(txt) - boundary.shape[0])
bin_rept: np.ndarray = np.zeros(len(txt) - boundary.shape[0])
bin_rept[list(boundary) + [0]] = 1

sample_wo_seps = list(txt.replace(SEPARATOR, ""))
Expand Down
20 changes: 10 additions & 10 deletions pythainlp/corpus/wordnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def synsets(word: str, pos: Optional[str] = None, lang: str = "tha") -> list[wor
>>> synsets("แรง", pos="a", lang="tha")
[Synset('hard.s.10'), Synset('strong.s.02')]
"""
return wordnet.synsets(lemma=word, pos=pos, lang=lang)
return wordnet.synsets(lemma=word, pos=pos, lang=lang) # type: ignore[no-any-return]


def synset(name_synsets: str) -> wordnet.Synset:
Expand Down Expand Up @@ -140,7 +140,7 @@ def all_lemma_names(pos: Optional[str] = None, lang: str = "tha") -> list[str]:
>>> len(all_lemma_names(pos="a"))
5277
"""
return wordnet.all_lemma_names(pos=pos, lang=lang)
return wordnet.all_lemma_names(pos=pos, lang=lang) # type: ignore[no-any-return]


def all_synsets(pos: Optional[str] = None) -> Iterable[wordnet.Synset]:
Expand Down Expand Up @@ -170,7 +170,7 @@ def all_synsets(pos: Optional[str] = None) -> Iterable[wordnet.Synset]:
>>> next(generator)
Synset('unable.a.01')
"""
return wordnet.all_synsets(pos=pos)
return wordnet.all_synsets(pos=pos) # type: ignore[no-any-return]


def langs() -> list[str]:
Expand All @@ -188,7 +188,7 @@ def langs() -> list[str]:
'pol', 'por', 'qcn', 'slv', 'spa', 'swe', 'tha',
'zsm']
"""
return wordnet.langs()
return wordnet.langs() # type: ignore[no-any-return]


def lemmas(word: str, pos: Optional[str] = None, lang: str = "tha") -> list[wordnet.Lemma]:
Expand Down Expand Up @@ -231,7 +231,7 @@ def lemmas(word: str, pos: Optional[str] = None, lang: str = "tha") -> list[word
>>> lemmas("ม้วน", pos="n")
[Lemma('roll.n.11.ม้วน')]
"""
return wordnet.lemmas(word, pos=pos, lang=lang)
return wordnet.lemmas(word, pos=pos, lang=lang) # type: ignore[no-any-return]


def lemma(name_synsets: str) -> wordnet.Lemma:
Expand Down Expand Up @@ -323,7 +323,7 @@ def path_similarity(synsets1: wordnet.Synset, synsets2: wordnet.Synset) -> float
>>> path_similarity(obj, cat)
0.08333333333333333
"""
return wordnet.path_similarity(synsets1, synsets2)
return wordnet.path_similarity(synsets1, synsets2) # type: ignore[no-any-return]


def lch_similarity(synsets1: wordnet.Synset, synsets2: wordnet.Synset) -> float:
Expand Down Expand Up @@ -360,7 +360,7 @@ def lch_similarity(synsets1: wordnet.Synset, synsets2: wordnet.Synset) -> float:
>>> lch_similarity(obj, cat)
1.1526795099383855
"""
return wordnet.lch_similarity(synsets1, synsets2)
return wordnet.lch_similarity(synsets1, synsets2) # type: ignore[no-any-return]


def wup_similarity(synsets1: wordnet.Synset, synsets2: wordnet.Synset) -> float:
Expand Down Expand Up @@ -391,7 +391,7 @@ def wup_similarity(synsets1: wordnet.Synset, synsets2: wordnet.Synset) -> float:
>>> wup_similarity(obj, cat)
0.35294117647058826
"""
return wordnet.wup_similarity(synsets1, synsets2)
return wordnet.wup_similarity(synsets1, synsets2) # type: ignore[no-any-return]


def morphy(form: str, pos: Optional[str] = None) -> str:
Expand Down Expand Up @@ -421,7 +421,7 @@ def morphy(form: str, pos: Optional[str] = None) -> str:
>>> morphy("calculated")
'calculate'
"""
return wordnet.morphy(form, pos=None)
return wordnet.morphy(form, pos=None) # type: ignore[no-any-return]


def custom_lemmas(tab_file, lang: str) -> None:
Expand All @@ -432,4 +432,4 @@ def custom_lemmas(tab_file, lang: str) -> None:
:param tab_file: Tab file as a file or file-like object
:param str lang: abbreviation of language (i.e. *eng*, *tha*).
"""
return wordnet.custom_lemmas(tab_file, lang)
return wordnet.custom_lemmas(tab_file, lang) # type: ignore[no-any-return]
2 changes: 1 addition & 1 deletion pythainlp/spell/phunspell.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ def spell(text: str) -> list[str]:


def correct(text: str) -> str:
return list(pspell.suggest(text))[0]
return list(pspell.suggest(text))[0] # type: ignore[no-any-return]
2 changes: 1 addition & 1 deletion pythainlp/spell/tltk.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@


def spell(text: str) -> list[str]:
return spell_candidates(text)
return spell_candidates(text) # type: ignore[no-any-return]
2 changes: 1 addition & 1 deletion pythainlp/tag/tltk.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
def pos_tag(words: list[str], corpus: str = "tnc") -> list[tuple[str, str]]:
if corpus != "tnc":
raise ValueError(f"tltk not support {0} corpus.")
return nlp.pos_tag_wordlist(words)
return nlp.pos_tag_wordlist(words) # type: ignore[no-any-return]


def _post_process(text: str) -> str:
Expand Down
6 changes: 3 additions & 3 deletions pythainlp/transliterate/ipa.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@


def transliterate(text: str) -> str:
return _EPI_THA.transliterate(text)
return _EPI_THA.transliterate(text) # type: ignore[no-any-return]


def trans_list(text: str) -> list[str]:
return _EPI_THA.trans_list(text)
return _EPI_THA.trans_list(text) # type: ignore[no-any-return]


def xsampa_list(text: str) -> list[str]:
return _EPI_THA.xsampa_list(text)
return _EPI_THA.xsampa_list(text) # type: ignore[no-any-return]
6 changes: 3 additions & 3 deletions pythainlp/transliterate/tltk.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ def romanize(text: str) -> str:
# Replace ฅ with ค to avoid KeyError in tltk (out-of-vocabulary issue)
text = text.replace("ฅ", "ค")
_temp = th2roman(text)
return _temp[: _temp.rfind(" <s/>")].replace("<s/>", "")
return _temp[: _temp.rfind(" <s/>")].replace("<s/>", "") # type: ignore[no-any-return]


def tltk_g2p(text: str) -> str:
# Replace ฅ with ค to avoid KeyError in tltk (out-of-vocabulary issue)
text = text.replace("ฅ", "ค")
_temp = g2p(text).split("<tr/>")[1].replace("|<s/>", "").replace("|", " ")
return _temp.replace("<s/>", "")
return _temp.replace("<s/>", "") # type: ignore[no-any-return]


def tltk_ipa(text: str) -> str:
# Replace ฅ with ค to avoid KeyError in tltk (out-of-vocabulary issue)
text = text.replace("ฅ", "ค")
_temp = th2ipa(text)
return _temp[: _temp.rfind(" <s/>")].replace("<s/>", "")
return _temp[: _temp.rfind(" <s/>")].replace("<s/>", "") # type: ignore[no-any-return]
10 changes: 5 additions & 5 deletions pythainlp/word_vector/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def doesnt_match(self, words: list[str]) -> str:
>>> wv.doesnt_match(words)
'เรือ'
"""
return self.model.doesnt_match(words)
return self.model.doesnt_match(words) # type: ignore[no-any-return]

def most_similar_cosmul(
self, positive: list[str], negative: list[str]
Expand Down Expand Up @@ -209,7 +209,7 @@ def most_similar_cosmul(
>>> wv.most_similar_cosmul(list_positive, list_negative)
KeyError: "word 'เมนูอาหารไทย' not in vocabulary"
"""
return self.model.most_similar_cosmul(
return self.model.most_similar_cosmul( # type: ignore[no-any-return]
positive=positive, negative=negative
)

Expand Down Expand Up @@ -249,7 +249,7 @@ def similarity(self, word1: str, word2: str) -> float:
0.04300258

"""
return self.model.similarity(word1, word2)
return self.model.similarity(word1, word2) # type: ignore[no-any-return]

def sentence_vectorizer(self, text: str, use_mean: bool = True) -> ndarray:
"""Converts a Thai sentence into a vector.
Expand Down Expand Up @@ -302,7 +302,7 @@ def sentence_vectorizer(self, text: str, use_mean: bool = True) -> ndarray:
len_words = len(words)

if not len_words:
return vec
return vec # type: ignore[no-any-return]

for word in words:
if word == " " and self.model_name == "thai2fit_wv":
Expand All @@ -316,4 +316,4 @@ def sentence_vectorizer(self, text: str, use_mean: bool = True) -> ndarray:
if use_mean:
vec /= len_words

return vec
return vec # type: ignore[no-any-return]
Loading