class NameGenerator
package markov.namegen
An example name generator that builds upon the Generator class. This should be sufficient for most simple name generation scenarios.
For complex name generators, modifying the Generator class to your specifications may be more appropriate or performant than extending this approach.
Constructor
new (data:Array<String>, order:Int, prior:Float, backoff:Bool = false)
Creates a new procedural name generator.
Parameters:
data | Training data for the generator, an array of words. |
---|---|
order | Highest order of model to use - models 1 to order will be generated. |
prior | The dirichlet prior/additive smoothing "randomness" factor. |
backoff | Whether to fall back to lower order models when the highest order model fails to generate a letter (defaults to false). |
Methods
generateName (minLength:Int, maxLength:Int, startsWith:String, endsWith:String, includes:String, excludes:String, ?regexMatch:EReg):String
Creates a word within the given constraints. If the generated word does not meet the constraints, this returns null.
Parameters:
minLength | The minimum length of the word. |
---|---|
maxLength | The maximum length of the word. |
startsWith | The text the word must start with. |
endsWith | The text the word must end with. |
includes | The text the word must include. |
excludes | The text the word must exclude. |
Returns:
A word that meets the specified constraints, or null if the generated word did not meet the constraints.
generateNames (n:Int, minLength:Int, maxLength:Int, startsWith:String, endsWith:String, includes:String, excludes:String, maxTimePerName:Float = 0.02, ?regexMatch:EReg):Array<String>
Attempts to generate "n" names that meet the given constraints within an alotted time.
Parameters:
n | The number of names to generate. |
---|---|
minLength | The minimum length of the word. |
maxLength | The maximum length of the word. |
startsWith | The text the word must start with. |
endsWith | The text the word must end with. |
includes | The text the word must include. |
excludes | The text the word must exclude. |
maxTimePerName | The maximum time in seconds to spend generating each name. |
Returns:
A word that meets the specified constraints, or null if no word that met the constraints was generated in the time alotted.