|
4 | 4 |
|
5 | 5 | import pickle |
6 | 6 | import unittest |
| 7 | +from typing import cast |
7 | 8 |
|
8 | 9 | import fastai |
9 | 10 | import pandas as pd |
|
19 | 20 | untar_data, |
20 | 21 | ) |
21 | 22 |
|
22 | | -from pythainlp.tokenize import THAI2FIT_TOKENIZER |
| 23 | +from pythainlp.tokenize import thai2fit_tokenizer |
23 | 24 | from pythainlp.ulmfit import ( |
24 | 25 | THWIKI_LSTM, |
25 | 26 | ThaiTokenizer, |
@@ -53,12 +54,14 @@ class UlmfitTestCaseX(unittest.TestCase): |
53 | 54 | def test_ThaiTokenizer(self): |
54 | 55 | self.thai = ThaiTokenizer() |
55 | 56 | self.assertIsNotNone(self.thai.tokenizer("ทดสอบการตัดคำ")) |
56 | | - self.assertIsNone(self.thai.add_special_cases(["แมว"])) |
| 57 | + result = self.thai.add_special_cases(["แมว"]) |
| 58 | + self.assertIsNone(result) |
57 | 59 |
|
58 | 60 | def test_BaseTokenizer(self): |
59 | 61 | self.base = base_tokenizer(lang="th") |
60 | 62 | self.assertIsNotNone(self.base.tokenizer("ทดสอบ การ ตัด คำ")) |
61 | | - self.assertIsNone(self.base.add_special_cases(["แมว"])) |
| 63 | + result = self.base.add_special_cases(["แมว"]) |
| 64 | + self.assertIsNone(result) |
62 | 65 |
|
63 | 66 | def test_load_pretrained(self): |
64 | 67 | self.assertIsNotNone(THWIKI_LSTM) |
@@ -179,7 +182,7 @@ def test_process_thai_dense(self): |
179 | 182 | text, |
180 | 183 | pre_rules=pre_rules_th, |
181 | 184 | post_rules=post_rules_th, |
182 | | - tok_func=THAI2FIT_TOKENIZER.word_tokenize, |
| 185 | + tok_func=thai2fit_tokenizer().word_tokenize, |
183 | 186 | ) |
184 | 187 |
|
185 | 188 | # after pre_rules_th |
@@ -225,7 +228,7 @@ def test_document_vector(self): |
225 | 228 | thwiki = THWIKI_LSTM |
226 | 229 | # Security note: pickle.load() executes arbitrary code if file is malicious. |
227 | 230 | # These corpus files come from a trusted source with MD5 verification. |
228 | | - with open(thwiki["itos_fname"], "rb") as f: |
| 231 | + with open(cast(str, thwiki["itos_fname"]), "rb") as f: |
229 | 232 | thwiki_itos = pickle.load(f) |
230 | 233 | thwiki_vocab = fastai.text.transform.Vocab(thwiki_itos) |
231 | 234 | tt = Tokenizer( |
|
0 commit comments