class
WordMage::WordSpec
- WordMage::WordSpec
- Reference
- Object
Overview
Specifies requirements for word generation.
WordSpec combines all the rules and constraints for generating words: syllable count, starting phoneme type, available templates, and constraints.
Example
syllable_count = SyllableCountSpec.range(2, 4)
templates = [SyllableTemplate.new("CV"), SyllableTemplate.new("CVC")]
spec = WordSpec.new(
syllable_count: syllable_count,
syllable_templates: templates,
starting_type: :vowel,
word_constraints: ["rr", "ss"] # No double consonants
)
Defined in:
word_spec.crConstructors
Instance Method Summary
- #ends_with : String | Nil
- #ends_with=(ends_with : String | Nil)
-
#generate_syllable_count : Int32
Generates the number of syllables for a word.
-
#get_required_prefix(romanizer : RomanizationMap) : Array(String)
Gets the required starting phonemes for the starts_with constraint.
-
#get_required_suffix(romanizer : RomanizationMap) : Array(String)
Gets the required ending phonemes for the ends_with constraint.
-
#select_template(position : Symbol, cluster_cost : Float32 = 0.0_f32, coda_cost : Float32 = 0.0_f32) : SyllableTemplate
Selects a syllable template for the given position.
- #starting_type : Symbol | Nil
- #starting_type=(starting_type : Symbol | Nil)
- #starts_with : String | Nil
- #starts_with=(starts_with : String | Nil)
- #syllable_count : SyllableCountSpec
- #syllable_count=(syllable_count : SyllableCountSpec)
- #syllable_templates : Array(SyllableTemplate)
- #syllable_templates=(syllable_templates : Array(SyllableTemplate))
-
#template_cluster_cost_factor : Float32
Cost settings for template selection
-
#template_cluster_cost_factor=(template_cluster_cost_factor : Float32)
Cost settings for template selection
- #template_coda_cost_factor : Float32
- #template_coda_cost_factor=(template_coda_cost_factor : Float32)
- #thematic_vowel : String | Nil
- #thematic_vowel=(thematic_vowel : String | Nil)
-
#validate_word(phonemes : Array(String), romanizer : RomanizationMap | Nil = nil) : Bool
Validates a word against constraints.
- #word_constraints : Array(String)
- #word_constraints=(word_constraints : Array(String))
Constructor Detail
Creates a new WordSpec.
Parameters
#syllable_count
: How many syllables to generate#syllable_templates
: Available syllable patterns#starting_type
: Optional constraint on first phoneme (:vowel
or:consonant
)#word_constraints
: Regex patterns that words must NOT match#thematic_vowel
: Optional constraint forcing the last vowel to be this specific vowel#starts_with
: Optional constraint forcing words to start with this exact sequence#ends_with
: Optional constraint forcing words to end with this exact sequence#template_cluster_cost_factor
: Cost factor for templates with consonant clusters (default: 1.0)#template_coda_cost_factor
: Cost factor for templates with complex codas (default: 1.0)
Instance Method Detail
Generates the number of syllables for a word.
Returns
Number of syllables according to the syllable count spec
Gets the required starting phonemes for the starts_with constraint.
Parameters
romanizer
: RomanizationMap to convert romanization to phonemes
Returns
Array of phonemes that must start the word, or empty array if no constraint
Gets the required ending phonemes for the ends_with constraint.
Returns
Array of phonemes that must end the word, or empty array if no constraint
Selects a syllable template for the given position.
Parameters
position
: Syllable position (:initial
,:medial
,:final
)cluster_cost
: Optional cost for consonant clusters (default: 0)coda_cost
: Optional cost for complex codas (default: 0)
Returns
A syllable template, respecting probability, position weights, and costs
Cost settings for template selection