class WordMage::WordSpec

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

Constructors

Instance Method Summary

Constructor Detail

def self.new(syllable_count : SyllableCountSpec, syllable_templates : Array(SyllableTemplate), starting_type : Symbol | Nil = nil, word_constraints : Array(String) = [] of String, thematic_vowel : String | Nil = nil, starts_with : String | Nil = nil, ends_with : String | Nil = nil, template_cluster_cost_factor : Float32 = 1.0_f32, template_coda_cost_factor : Float32 = 1.0_f32) #

Creates a new WordSpec.

Parameters


[View source]

Instance Method Detail

def ends_with : String | Nil #

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

[View source]
def generate_syllable_count : Int32 #

Generates the number of syllables for a word.

Returns

Number of syllables according to the syllable count spec


[View source]
def get_required_prefix(romanizer : RomanizationMap) : Array(String) #

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


[View source]
def get_required_suffix(romanizer : RomanizationMap) : Array(String) #

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


[View source]
def 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.

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


[View source]
def starting_type : Symbol | Nil #

[View source]
def starting_type=(starting_type : Symbol | Nil) #

[View source]
def starts_with : String | Nil #

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

[View source]
def syllable_count : SyllableCountSpec #

[View source]
def syllable_count=(syllable_count : SyllableCountSpec) #

[View source]
def syllable_templates : Array(SyllableTemplate) #

[View source]
def syllable_templates=(syllable_templates : Array(SyllableTemplate)) #

[View source]
def template_cluster_cost_factor : Float32 #

Cost settings for template selection


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

Cost settings for template selection


[View source]
def template_coda_cost_factor : Float32 #

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

[View source]
def thematic_vowel : String | Nil #

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

[View source]
def validate_word(phonemes : Array(String), romanizer : RomanizationMap | Nil = nil) : Bool #

Validates a word against constraints.

Parameters

  • phonemes: Array of phonemes forming the word
  • romanizer: Optional romanizer for thematic vowel validation and sequence constraints

Returns

true if word passes all constraints, false otherwise


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

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

[View source]