| 987 | return dict_character |
| 988 | |
| 989 | def encode(self, text): |
| 990 | if len(text) == 0 or len(text) >= self.max_text_len: |
| 991 | return None |
| 992 | if self.lower: |
| 993 | text = text.lower() |
| 994 | text_list = [] |
| 995 | for char in text: |
| 996 | if char not in self.dict: |
| 997 | text_list.append(self.unknown_idx) |
| 998 | else: |
| 999 | text_list.append(self.dict[char]) |
| 1000 | text_list.append(self.end_idx) |
| 1001 | if len(text_list) < self.max_text_len: |
| 1002 | text_list += [self.padding_idx] * (self.max_text_len - len(text_list)) |
| 1003 | return text_list |
| 1004 | |
| 1005 | def __call__(self, data): |
| 1006 | text = data["label"] |