* Constructor of CharacterTable. * @param chars A string that contains the characters that can appear * in the input.
(chars)
| 32 | * in the input. |
| 33 | */ |
| 34 | constructor(chars) { |
| 35 | this.chars = chars; |
| 36 | this.charIndices = {}; |
| 37 | this.indicesChar = {}; |
| 38 | this.size = this.chars.length; |
| 39 | for (let i = 0; i < this.size; ++i) { |
| 40 | const char = this.chars[i]; |
| 41 | if (this.charIndices[char] != null) { |
| 42 | throw new Error(`Duplicate character '${char}'`); |
| 43 | } |
| 44 | this.charIndices[this.chars[i]] = i; |
| 45 | this.indicesChar[i] = this.chars[i]; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Convert a string into a one-hot encoded tensor. |
nothing calls this directly
no outgoing calls
no test coverage detected