class
WordMage::SyllableTemplate
- WordMage::SyllableTemplate
- Reference
- Object
Overview
Defines syllable structure patterns with constraints and hiatus generation.
SyllableTemplate specifies how syllables should be constructed using pattern strings like "CV" (consonant-vowel), "CVC" (consonant-vowel-consonant), etc. Supports hiatus (vowel sequences) and validation constraints.
Pattern Symbols
C
: ConsonantV
: Vowel (may become VV with hiatus)
Example
template = SyllableTemplate.new("CCV", ["rr"], hiatus_probability: 0.3_f32)
syllable = template.generate(phoneme_set, :initial) # ["p", "r", "a", "e"]
Defined in:
syllable_template.crConstructors
-
.new(pattern : String, constraints : Array(String) = [] of String, hiatus_probability : Float32 = 0.0_f32, position_weights : Hash(Symbol, Float32) = Hash(Symbol, Float32).new, allowed_clusters : Array(String) | Nil = nil, allowed_coda_clusters : Array(String) | Nil = nil)
Creates a new syllable template.
Instance Method Summary
- #allowed_clusters : Array(String) | Nil
- #allowed_clusters=(allowed_clusters : Array(String) | Nil)
- #allowed_coda_clusters : Array(String) | Nil
- #allowed_coda_clusters=(allowed_coda_clusters : Array(String) | Nil)
-
#allows_hiatus? : Bool
Checks if this template can generate hiatus (vowel sequences).
- #constraints : Array(String)
- #constraints=(constraints : Array(String))
-
#generate(phonemes : PhonemeSet, position : Symbol) : Array(String)
Generates a syllable using this template.
- #hiatus_probability : Float32
- #hiatus_probability=(hiatus_probability : Float32)
- #pattern : String
- #pattern=(pattern : String)
- #position_weights : Hash(Symbol, Float32)
- #position_weights=(position_weights : Hash(Symbol, Float32))
-
#validate(syllable : Array(String)) : Bool
Validates a syllable against constraints.
Constructor Detail
Creates a new syllable template.
Parameters
#pattern
: Pattern string (e.g., "CV", "CVC", "CCV", "CVCC")#constraints
: Regex patterns that syllables must NOT match#hiatus_probability
: Chance (0.0-1.0) that V becomes VV#position_weights
: Weights for using this template at different positions#allowed_clusters
: Specific onset clusters allowed for CC patterns (optional)#allowed_coda_clusters
: Specific coda clusters allowed for CC at end (optional)
Instance Method Detail
Checks if this template can generate hiatus (vowel sequences).
Returns
true
if hiatus_probability > 0, false
otherwise
Generates a syllable using this template.
Parameters
phonemes
: PhonemeSet to sample fromposition
: Syllable position (:initial
,:medial
,:final
)
Returns
Array of phoneme strings forming the syllable
Note
Automatically retries if constraints are violated
Validates a syllable against constraints.
Parameters
syllable
: Array of phonemes to validate
Returns
true
if syllable passes all constraints, false
otherwise