class WordMage::Generator

Overview

Main word generation engine that combines all components.

Generator is the central class that orchestrates word creation using PhonemeSet, WordSpec, SyllableTemplates, and RomanizationMap. It supports multiple generation modes and handles constraint validation.

Example

generator = Generator.new(
  phoneme_set: phonemes,
  word_spec: word_spec,
  romanizer: romanizer,
  mode: GenerationMode::Random
)
word = generator.generate
batch = generator.generate_batch(10)

Defined in:

generator.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(phoneme_set : PhonemeSet, word_spec : WordSpec, romanizer : RomanizationMap, mode : GenerationMode, max_words : Int32 = 1000, complexity_budget : Int32 | Nil = nil, hiatus_escalation_factor : Float32 = 1.5_f32, vowel_harmony : VowelHarmony | Nil = nil) #

Creates a new Generator.

Parameters


[View source]

Instance Method Detail

def complexity_budget : Int32 | Nil #

[View source]
def complexity_budget=(complexity_budget : Int32 | Nil) #

[View source]
def generate(min_syllables : Int32, max_syllables : Int32) : String #

Generates a word with syllable count from a range.

Parameters

  • min_syllables: Minimum syllable count
  • max_syllables: Maximum syllable count

Returns

A romanized word string with syllables in the specified range


[View source]
def generate(syllable_count : Int32, starting_type : Symbol) : String #

Generates a word with both syllable count and starting type.

Parameters

  • syllable_count: Exact number of syllables
  • starting_type: Either :vowel or :consonant

Returns

A romanized word string with specified syllables and starting type


[View source]
def generate(syllable_count : Int32) : String #

Generates a word with a specific syllable count.

Parameters

  • syllable_count: Exact number of syllables to generate

Returns

A romanized word string with the specified syllable count


[View source]
def generate(starting_type : Symbol) : String #

Generates a word with a specific starting type.

Parameters

  • starting_type: Either :vowel or :consonant

Returns

A romanized word string starting with the specified phoneme type


[View source]
def generate : String #

Generates a single word according to the current mode.

Returns

A romanized word string

Raises

Raises if sequential mode has no more words available


[View source]
def generate_batch(count : Int32) : Array(String) #

Generates multiple words.

Parameters

  • count: Number of words to generate

Returns

Array of romanized word strings


[View source]
def hiatus_escalation_factor : Float32 #

[View source]
def hiatus_escalation_factor=(hiatus_escalation_factor : Float32) #

[View source]
def max_words : Int32 #

[View source]
def max_words=(max_words : Int32) #

[View source]
def mode : GenerationMode #

[View source]
def mode=(mode : GenerationMode) #

[View source]
def next_sequential : String | Nil #

Gets the next word in sequential mode.

Returns

Next word string, or nil if no more words available

Note

Only works in Sequential mode. Call #reset_sequential to start over.


[View source]
def phoneme_set : PhonemeSet #

[View source]
def phoneme_set=(phoneme_set : PhonemeSet) #

[View source]
def reset_sequential #

Resets sequential generation to start from the beginning.

Note

Only affects Sequential mode. Has no effect in other modes.


[View source]
def romanizer : RomanizationMap #

[View source]
def romanizer=(romanizer : RomanizationMap) #

[View source]
def vowel_harmony : VowelHarmony | Nil #

[View source]
def vowel_harmony=(vowel_harmony : VowelHarmony | Nil) #

[View source]
def word_spec : WordSpec #

[View source]
def word_spec=(word_spec : WordSpec) #

[View source]