new Dictionary()
- Description:
Dictionary using a Directed Acyclic Word Graph (DAWG) in the format generated by compress.js
Note that the DAWG uses letter indices, and not actual characters, to represent code points. To use this dictionary you also need an alphabet of code points sorted in the same order as that used to generate the DAWG.
- Source:
Members
name :string
- Description:
List of valid start points, such that at least one start point must match() for any sequence of chars, or there can't possibly be a word.
- Source:
List of valid start points, such that at least one start point must match() for any sequence of chars, or there can't possibly be a word.
Type:
- string
(nullable) root :LetterNode
- Description:
First node in the dictionary.
- Source:
First node in the dictionary.
Type:
Methods
addWord() → {boolean}
- Description:
Add a word to the dictionary. No attempt is made at compression. Note that previously retrieved sequence roots will no longer be valid after the word is added and will need to be recomputed. Note that we support single character words here, but word games are limited to 2 letter or more. It's up to the caller to enforce such constraints.
- Source:
Returns:
true if the word needed to be added, false if it was empty or already there.
- Type
- boolean
eachWord(callback)
- Description:
Apply the callback to each of the words represented in the DAWG (potentially huge!)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
callback |
Dictionary~wordCallback | function |
findAnagrams(theChars) → {Object.<string, string>}
- Description:
Find anagrams of a set of letters. An anagram is defined as any complete (2 or more characters) word that uses all or some of the letters passed in.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
theChars |
string | the letters, ' ' for an any-letter wildcard. |
Returns:
a map of actual words to the letter sequence (using ' ' for blanks) that matched.
- Type
- Object.<string, string>
findHangmen(theChars) → {Array.<string>}
- Description:
Find hangman matches for a set of letters. A hangman match is any word(s) that match against an ordered set of letters, using a space for an any-letter wildcard. For example, "EXAMPLE" is a hangman match for "E AM LE".
- Source:
Parameters:
Name | Type | Description |
---|---|---|
theChars |
string | the letters, ' ' for an any-letter wildcard. |
Returns:
the list of words that matched.
- Type
- Array.<string>
getSequenceRoots(ch) → {Array.<LetterNode>}
- Description:
Get a list of the sequence roots for ch. The sequence roots are all those nodes that represent the character in any word. From a sequence root we can follow post or pre to extend the word in either direction.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
ch |
string | character to find roots for |
Returns:
list of the roots
- Type
- Array.<LetterNode>
hasSequence(seq) → {boolean}
- Description:
Return true if a start node for the character sequence is found in the sequence index i.e. it forms a valid sub-part of a word in the dictionary. This way we can quickly eliminate sequences such as "QX" which are never found in the dictionary. Note that we don't have any way to reproduce the words that the sequence is a valid part of; that's not the point, this is intended to help eliminate invalid sequences when extending a word backwards from a seed letter.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
seq |
string | letter sequence |
Returns:
if a start node exists
- Type
- boolean
hasWord(chars) → {boolean}
- Description:
Check if a word is in the dictionary
- Source:
Parameters:
Name | Type | Description |
---|---|---|
chars |
string | a word to check |
Returns:
true if the word is found, false otherwise
- Type
- boolean
loadDAWG(datanullable) → {Dictionary}
- Description:
Load a DAG, as generated by dictionary_compressor.js. This is destructive; anything already in the dictionary will be discarded.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
data |
Buffer | Array |
<nullable> |
the DAWG data. |
Returns:
this
- Type
- Dictionary
match(chars) → {LetterNode}
- Description:
Return the LetterNode that matches the last character in chars, starting from the root / first character.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
chars |
string | characters that may be the root of a word |
Returns:
node found, or undefined
- Type
- LetterNode
Type Definitions
wordCallback(word, node)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
word |
string | Word found |
node |
LetterNode | Node where word was terminated |