Data Structures
Last updated
Last updated
Custom data structures.
These are only used internally, meaning an end-user shouldn’t need to access anything here.
static
⇒ boolean
⇒ any
⇒ number
⇒ number
⇒ any
⇒ *
⇒ Array.<TokenLatticeNode>
⇒ string
⇒ Array
⇒ Array
inner
⇒ CharTrieNode
⇒ TokenLatticeNode
Efficient 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:
Create a new PriorityQueue.
comparator
function
Comparator function to determine priority. Defaults to a MaxHeap.
The size of the queue
Check if the queue is empty.
Return the element with the highest priority in the queue.
Add one or more elements to the queue.
...values
any
The values to push into the queue.
Add multiple elements to the queue.
values
Array.<any>
The values to push into the queue.
Remove and return the element with the highest priority in the queue.
Replace the element with the highest priority in the queue with a new value.
value
*
The new value.
A trie structure to efficiently store and search for strings.
Adds one or more texts
to the trie.
texts
Array.<string>
The strings to add to the trie.
Adds text to the trie.
text
string
The string to add to the trie.
Searches the trie for all strings with a common prefix of text
.
text
string
The common prefix to search for.
A lattice data structure to be used for tokenization.
Creates a new TokenLattice instance.
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.
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.
node
TokenLatticeNode
Represents a node in a character trie.
Create a new CharTrieNode.
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 CharTrieNode
.
Returns a new CharTrieNode
instance with default values.
Represents a node in a token lattice for a given sentence.
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.
(original)
(minor improvements)
Kind: static class of
⇒ boolean
⇒ any
⇒ number
⇒ number
⇒ any
⇒ *
Kind: instance property of
Kind: instance method of
Returns: boolean
- true
if the queue is empty, false
otherwise.
Kind: instance method of
Returns: any
- The highest priority element in the queue.
Kind: instance method of
Returns: number
- The new size of the queue.
Kind: instance method of
Returns: number
- The new size of the queue.
Kind: instance method of
Returns: any
- The element with the highest priority in the queue.
Kind: instance method of
Returns: *
- The replaced value.
Kind: static class of
Kind: instance method of
Kind: instance method of
Kind: instance method of
Kind: static class of
⇒ Array.<TokenLatticeNode>
⇒ string
⇒ Array
⇒ Array
Kind: instance method of
Kind: instance method of
Returns: Array.<TokenLatticeNode>
- The array of nodes representing the most likely sequence of tokens.
Kind: instance method of
Returns: string
- The array of nodes representing the most likely sequence of tokens.
Kind: instance method of
Returns: Array
- The array of nodes representing the most likely sequence of tokens.
Kind: instance method of
Returns: Array
- The array of nodes representing the most likely sequence of tokens.
Kind: inner class of
⇒ CharTrieNode
Kind: static method of
Returns: CharTrieNode
- A new CharTrieNode
instance with isLeaf
set to false
and an empty children
map.
Kind: inner class of
⇒ TokenLatticeNode
Kind: instance method of
Returns: TokenLatticeNode
- A clone of this node.