class WordMage::SyllableTemplate

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

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.cr

Constructors

Instance Method Summary

Constructor Detail

def self.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.

Parameters


[View source]

Instance Method Detail

def allowed_clusters : Array(String) | Nil #

[View source]
def allowed_clusters=(allowed_clusters : Array(String) | Nil) #

[View source]
def allowed_coda_clusters : Array(String) | Nil #

[View source]
def allowed_coda_clusters=(allowed_coda_clusters : Array(String) | Nil) #

[View source]
def allows_hiatus? : Bool #

Checks if this template can generate hiatus (vowel sequences).

Returns

true if hiatus_probability > 0, false otherwise


[View source]
def constraints : Array(String) #

[View source]
def constraints=(constraints : Array(String)) #

[View source]
def generate(phonemes : PhonemeSet, position : Symbol) : Array(String) #

Generates a syllable using this template.

Parameters

  • phonemes: PhonemeSet to sample from
  • position: Syllable position (:initial, :medial, :final)

Returns

Array of phoneme strings forming the syllable

Note

Automatically retries if constraints are violated


[View source]
def hiatus_probability : Float32 #

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

[View source]
def pattern : String #

[View source]
def pattern=(pattern : String) #

[View source]
def position_weights : Hash(Symbol, Float32) #

[View source]
def position_weights=(position_weights : Hash(Symbol, Float32)) #

[View source]
def validate(syllable : Array(String)) : Bool #

Validates a syllable against constraints.

Parameters

  • syllable: Array of phonemes to validate

Returns

true if syllable passes all constraints, false otherwise


[View source]