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