| 1717 | return dict_character |
| 1718 | |
| 1719 | def encode(self, text): |
| 1720 | """ """ |
| 1721 | if len(text) == 0 or len(text) > self.max_text_len: |
| 1722 | return None, None, None |
| 1723 | if self.lower: |
| 1724 | text = text.lower() |
| 1725 | text_node = [0 for _ in range(self.num_character)] |
| 1726 | text_node[0] = 1 |
| 1727 | text_list = [] |
| 1728 | ch_order = [] |
| 1729 | order = 1 |
| 1730 | for char in text: |
| 1731 | if char not in self.dict: |
| 1732 | continue |
| 1733 | text_list.append(self.dict[char]) |
| 1734 | text_node[self.dict[char]] += 1 |
| 1735 | ch_order.append([self.dict[char], text_node[self.dict[char]], order]) |
| 1736 | order += 1 |
| 1737 | |
| 1738 | no_ch_order = [] |
| 1739 | for char in self.character: |
| 1740 | if char not in text: |
| 1741 | no_ch_order.append([self.dict[char], 1, 0]) |
| 1742 | random.shuffle(no_ch_order) |
| 1743 | ch_order = ch_order + no_ch_order |
| 1744 | ch_order = ch_order[: self.max_text_len + 1] |
| 1745 | |
| 1746 | if len(text_list) == 0: |
| 1747 | return None, None, None |
| 1748 | return text_list, text_node, ch_order.sort() |
| 1749 | |
| 1750 | def encodech(self, text): |
| 1751 | """ """ |