1010
1111import threading
1212from importlib .resources import as_file , files
13- from typing import Optional , Union
13+ from typing import Optional , Union , cast
1414
1515try :
1616 import pycrfsuite
@@ -101,9 +101,9 @@ def featurize(
101101 if indiv_char :
102102 left_key = "|" .join ([str (relative_index_left ), char_left ])
103103 if return_type == "dict" :
104- features [left_key ] = 1
104+ cast ( dict [ str , int ], features ) [left_key ] = 1
105105 else :
106- features .append (left_key )
106+ cast ( list [ str ], features ) .append (left_key )
107107
108108 abs_index_right += (
109109 1 # สมมุติคือตำแหน่งที่ 0 จะได้ 0, 1, 2, 3, 4 (radius = 5)
@@ -119,9 +119,9 @@ def featurize(
119119 [str (relative_index_right ), char_right ]
120120 )
121121 if return_type == "dict" :
122- features [right_key ] = 1
122+ cast ( dict [ str , int ], features ) [right_key ] = 1
123123 else :
124- features .append (right_key )
124+ cast ( list [ str ], features ) .append (right_key )
125125
126126 counter += 1
127127
@@ -130,13 +130,14 @@ def featurize(
130130 ngram = chars [i : i + self .N ]
131131 ngram_key = "|" .join ([str (i - self .radius ), ngram ])
132132 if return_type == "dict" :
133- features [ngram_key ] = 1
133+ cast ( dict [ str , int ], features ) [ngram_key ] = 1
134134 else :
135- features .append (ngram_key )
135+ cast ( list [ str ], features ) .append (ngram_key )
136136 all_features .append (features )
137137 if return_type == "list" :
138- cut = str (cut )
139- all_labels .append (cut )
138+ all_labels .append (str (cut ))
139+ else :
140+ all_labels .append (cut )
140141
141142 return {"X" : all_features , "Y" : all_labels }
142143
0 commit comments