Custom data structures.
These are only used internally, meaning an end-user shouldn’t need to access anything here.
new PriorityQueue(comparator).size.isEmpty() ⇒ boolean.peek() ⇒ any.push(...values) ⇒ number.extend(values) ⇒ number.pop() ⇒ any.replace(value) ⇒ *._siftUpFrom(node)new TokenLattice(sentence, bosTokenId, eosTokenId).insert(pos, length, score, tokenId).viterbi() ⇒ Array.<TokenLatticeNode>.piece(node) ⇒ string.tokens() ⇒ Array.<string>.tokenIds() ⇒ Array.<number>new CharTrieNode(isLeaf, children).default() ⇒ CharTrieNodenew TokenLatticeNode(tokenId, nodeId, pos, length, score).clone() ⇒ TokenLatticeNodeEfficient Heap-based Implementation of a Priority Queue.
It uses an array-based binary heap, where the root is at index 0, and the
children of node i are located at indices 2i + 1 and 2i + 2, respectively.
Adapted from the following sources:
Kind: static class of utils/data-structures
new PriorityQueue(comparator).size.isEmpty() ⇒ boolean.peek() ⇒ any.push(...values) ⇒ number.extend(values) ⇒ number.pop() ⇒ any.replace(value) ⇒ *._siftUpFrom(node)Create a new PriorityQueue.
| Param | Type | Description |
|---|---|---|
| comparator | function | Comparator function to determine priority. Defaults to a MaxHeap. |
The size of the queue
Kind: instance property of PriorityQueue
Check if the queue is empty.
Kind: instance method of PriorityQueue
Returns: boolean - true if the queue is empty, false otherwise.
Return the element with the highest priority in the queue.
Kind: instance method of PriorityQueue
Returns: any - The highest priority element in the queue.
Add one or more elements to the queue.
Kind: instance method of PriorityQueue
Returns: number - The new size of the queue.
| Param | Type | Description |
|---|---|---|
| ...values | any | The values to push into the queue. |
Add multiple elements to the queue.
Kind: instance method of PriorityQueue
Returns: number - The new size of the queue.
| Param | Type | Description |
|---|---|---|
| values | Array.<any> | The values to push into the queue. |
Remove and return the element with the highest priority in the queue.
Kind: instance method of PriorityQueue
Returns: any - The element with the highest priority in the queue.
Replace the element with the highest priority in the queue with a new value.
Kind: instance method of PriorityQueue
Returns: * - The replaced value.
| Param | Type | Description |
|---|---|---|
| value | * | The new value. |
Helper function to sift up from a given node.
Kind: instance method of PriorityQueue
| Param | Type | Description |
|---|---|---|
| node | number | The index of the node to start sifting up from. |
A trie structure to efficiently store and search for strings.
Kind: static class of utils/data-structures
Adds one or more texts to the trie.
Kind: instance method of CharTrie
| Param | Type | Description |
|---|---|---|
| texts | Array.<string> | The strings to add to the trie. |
Adds text to the trie.
Kind: instance method of CharTrie
| Param | Type | Description |
|---|---|---|
| text | string | The string to add to the trie. |
Searches the trie for all strings with a common prefix of text.
Kind: instance method of CharTrie
| Param | Type | Description |
|---|---|---|
| text | string | The common prefix to search for. |
A lattice data structure to be used for tokenization.
Kind: static class of utils/data-structures
new TokenLattice(sentence, bosTokenId, eosTokenId).insert(pos, length, score, tokenId).viterbi() ⇒ Array.<TokenLatticeNode>.piece(node) ⇒ string.tokens() ⇒ Array.<string>.tokenIds() ⇒ Array.<number>Creates a new TokenLattice instance.
| Param | Type | Description |
|---|---|---|
| sentence | string | The input sentence to be tokenized. |
| bosTokenId | number | The beginning-of-sequence token ID. |
| eosTokenId | number | The end-of-sequence token ID. |
Inserts a new token node into the token lattice.
Kind: instance method of TokenLattice
| Param | Type | Description |
|---|---|---|
| pos | number | The starting position of the token. |
| length | number | The length of the token. |
| score | number | The score of the token. |
| tokenId | number | The token ID of the token. |
Implements the Viterbi algorithm to compute the most likely sequence of tokens.
Kind: instance method of TokenLattice
Returns: Array.<TokenLatticeNode> - The most likely sequence of tokens.
Kind: instance method of TokenLattice
Returns: string - The array of nodes representing the most likely sequence of tokens.
| Param | Type |
|---|---|
| node | TokenLatticeNode |
Kind: instance method of TokenLattice
Returns: Array.<string> - The most likely sequence of tokens.
Kind: instance method of TokenLattice
Returns: Array.<number> - The most likely sequence of token ids.
Represents a node in a character trie.
Kind: inner class of utils/data-structures
new CharTrieNode(isLeaf, children).default() ⇒ CharTrieNodeCreate a new CharTrieNode.
| Param | Type | Description |
|---|---|---|
| isLeaf | boolean | Whether the node is a leaf node or not. |
| children | Map.<string, CharTrieNode> | A map containing the node's children, where the key is a character and the value is a |
Returns a new CharTrieNode instance with default values.
Kind: static method of CharTrieNode
Returns: CharTrieNode - A new CharTrieNode instance with isLeaf set to false and an empty children map.
Kind: inner class of utils/data-structures
new TokenLatticeNode(tokenId, nodeId, pos, length, score).clone() ⇒ TokenLatticeNodeRepresents a node in a token lattice for a given sentence.
| Param | Type | Description |
|---|---|---|
| tokenId | number | The ID of the token associated with this node. |
| nodeId | number | The ID of this node. |
| pos | number | The starting position of the token in the sentence. |
| length | number | The length of the token. |
| score | number | The score associated with the token. |
Returns a clone of this node.
Kind: instance method of TokenLatticeNode
Returns: TokenLatticeNode - A clone of this node.