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), custom phoneme groups, and validation constraints.
Pattern Symbols
C
: ConsonantV
: Vowel (may become VV with hiatus)- Custom symbols: Any character defined in PhonemeSet custom groups (e.g., 'F' for fricatives)
Example
# Basic patterns
template = SyllableTemplate.new("CCV", ["rr"], hiatus_probability: 0.3_f32)
syllable = template.generate(phoneme_set, :initial) # ["p", "r", "a", "e"]
# Custom patterns (after defining custom groups in PhonemeSet)
template = SyllableTemplate.new("FVC") # Fricative-Vowel-Consonant
syllable = template.generate(phoneme_set, :initial) # ["f", "a", "k"]
Defined in:
syllable_template.crConstructors
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))
- #gemination_probability : Float32
- #gemination_probability=(gemination_probability : Float32)
-
#generate(phonemes : PhonemeSet, position : Symbol, romanizer : RomanizationMap | Nil = nil, retry_count : Int32 = 0) : 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))
- #probability : Float32
- #probability=(probability : Float32)
-
#validate(syllable : Array(String)) : Bool
Validates a syllable against constraints.
- #vowel_lengthening_probability : Float32
- #vowel_lengthening_probability=(vowel_lengthening_probability : Float32)
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#gemination_probability
: Chance (0.0-1.0) for consonant doubling in this template#vowel_lengthening_probability
: Chance (0.0-1.0) for vowel doubling in this template#position_weights
: Weights for using this template at different positions#allowed_clusters
: Specific onset clusters allowed for CC patterns (optional, in romanized form)#allowed_coda_clusters
: Specific coda clusters allowed for CC at end (optional, in romanized form)#probability
: Relative weight for selecting this template (default 1.0)
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
)romanizer
: Optional romanization map for parsing romanized clustersretry_count
: Internal parameter to limit recursion depth
Returns
Array of phoneme strings forming the syllable
Note
Automatically retries if constraints are violated, up to a maximum retry limit
Validates a syllable against constraints.
Parameters
syllable
: Array of phonemes to validate
Returns
true
if syllable passes all constraints, false
otherwise