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) #

Creates a new WordSpec.

Parameters


[View source]

Instance Method Detail

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 select_template(position : Symbol) : SyllableTemplate #

Selects a syllable template for the given position.

Parameters

  • position: Syllable position (:initial, :medial, :final)

Returns

A syllable template, respecting position weights if present


[View source]
def starting_type : Symbol | Nil #

[View source]
def starting_type=(starting_type : Symbol | 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 validate_word(phonemes : Array(String)) : Bool #

Validates a word against constraints.

Parameters

  • phonemes: Array of phonemes forming the word

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]