Generator

index~ Generator

new Generator(markovLenopt, configopt)

Source:
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
Name Type Attributes Default Description
wordStart String <optional>
"!" The default character at the beginning of a word when analyzing/generating. Use one that is not in any word of the original list. This character is used internally, please do not add it in the original word list that you pass in (good word: "doctor", NOT good: "!doctor?"). It's just meant to mark the starting point of a word. Note: If this character ("!") may appear in you original list, change it to something that don't. Ex.: "£" or "$".
wordEnd String <optional>
"?" The default character at the end of a word when analyzing/generating. Use one that is not in any word of the original list (as above).
minLength number <optional>
1 The minimum length of a word.
maxLength number <optional>
20 The maximum length of a word.
timeout number <optional>
1000 The timeout (in ms) of the genWord and genSet methods, just in case of huge list generation. Tune it when you generate huge lists, or if you use "Infinity" as a parameter in the genSet method.
allowExist boolean <optional>
false Allow to add existing words (from the original word list).

Methods

analyze(words)

Source:
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}

Source:
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}

Source:
Generate a word.
Example
Generator.genWord();
// returns: "generator"
Returns:
The word generated.
Type
String

loadStats(path, cb)

Source:
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)

Source:
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).