new Generator(markovLenopt, configopt)
Create a generator instance.
Parameters:
Name | Type | Attributes | Default | Description | |||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
markovLen |
number |
<optional> |
2
|
The length of the Markov chain. This parameter defines the depth of the probability chain (2 would mean that a character will be chosen depending on the 2 preceding characters). 2 to 3 are usually fine values. Highest values will give you less variety in the generated words since they would look just like in the original word list. Avoid high values unless you turn config.allowExist back on. | |||||||||||||||||||||||||||||||||||
config |
object |
<optional> |
The configuration of the generator.
Properties
|
Methods
analyze(words)
Analyse the word list passed in.
The use of this method is mandatory before using the genWord or genSet methods since you have to compute the probabilities of each character to appear before being able to generate words.
Example
Generator.analyze(Set { "home", "coding", "generator" });
Parameters:
Name | Type | Description |
---|---|---|
words |
Set | The word list. |
genSet(nbopt) → {Set}
Generate a word list.
Example
Generator.generate(3);
// returns: Set { "home", "coding", "generator" }
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
nb |
number | Infinity |
<optional> |
10
|
Length of the word list to generate. |
Returns:
The word list.
- Type
- Set
genWord() → {String}
Generate a word.
Example
Generator.genWord();
// returns: "generator"
Returns:
The word generated.
- Type
- String
loadStats(path, cb)
Load the map of probabilities.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
path |
String | Path of the savefile to load. | |
cb |
function |
null
|
Callback after savefile has been loaded. |
saveStats(path, cb)
Save the map of probabilities.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
path |
String | Path of the savefile to write. | |
cb |
function |
null
|
Callback after save. "data" is the json result of the probabilities map (the content of the savefile). |