class
WordMage::WordSpec
- WordMage::WordSpec
- Reference
- Object
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.crConstructors
-
.new(syllable_count : SyllableCountSpec, syllable_templates : Array(SyllableTemplate), starting_type : Symbol | Nil = nil, word_constraints : Array(String) = [] of String)
Creates a new WordSpec.
Instance Method Summary
-
#generate_syllable_count : Int32
Generates the number of syllables for a word.
-
#select_template(position : Symbol) : SyllableTemplate
Selects a syllable template for the given position.
- #starting_type : Symbol | Nil
- #starting_type=(starting_type : Symbol | Nil)
- #syllable_count : SyllableCountSpec
- #syllable_count=(syllable_count : SyllableCountSpec)
- #syllable_templates : Array(SyllableTemplate)
- #syllable_templates=(syllable_templates : Array(SyllableTemplate))
-
#validate_word(phonemes : Array(String)) : Bool
Validates a word against constraints.
- #word_constraints : Array(String)
- #word_constraints=(word_constraints : Array(String))
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
#syllable_count
: How many syllables to generate#syllable_templates
: Available syllable patterns#starting_type
: Optional constraint on first phoneme (:vowel
or:consonant
)#word_constraints
: Regex patterns that words must NOT match
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
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
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