class WordMage::WordAnalyzer

Overview

Analyzes individual words to extract phonological patterns and structure.

WordAnalyzer takes romanized words and uses a romanization map to reverse-engineer the phonemic structure, detecting syllables, clusters, hiatus sequences, and calculating complexity scores.

Example

romanization = RomanizationMap.new({
  "th" => "θ", "dr" => "dr", "a" => "ɑ", "e" => "ɛ", "o" => "ɔ"
})
analyzer = WordAnalyzer.new(romanization)
analysis = analyzer.analyze("thadrae")
puts analysis.syllable_count  # 2
puts analysis.clusters        # ["θ", "dr"]

Defined in:

word_analyzer.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(romanization_map : RomanizationMap) #

Creates a new WordAnalyzer.

Parameters

  • romanization_map: RomanizationMap for converting romanized text to phonemes

[View source]

Instance Method Detail

def analyze(word : String, syllable_templates : Array(SyllableTemplate)) : WordAnalysis #

Analyzes a romanized word using provided SyllableTemplate objects.

This method allows analysis to work with user-defined templates while still detecting all phonological patterns. The templates are used for context but don't modify the core analysis.

Parameters

  • word: The romanized word to analyze
  • syllable_templates: Array of SyllableTemplate objects (used for context)

Returns

WordAnalysis containing detailed structural information

Example

templates = [SyllableTemplate.new("CV"), SyllableTemplate.new("CVC")]
analysis = analyzer.analyze("nazagon", templates)
puts analysis.syllable_count     # 3
puts analysis.consonant_count    # 4

[View source]
def analyze(word : String) : WordAnalysis #

Analyzes a romanized word to extract phonological structure.

Parameters

  • word: The romanized word to analyze

Returns

WordAnalysis containing detailed structural information

Example

analysis = analyzer.analyze("nazagon")
puts analysis.syllable_count     # 3
puts analysis.consonant_count    # 4
puts analysis.vowel_count        # 3

[View source]
def detect_syllables(phonemes : Array(String)) : Array(Array(String)) #

Detects syllable boundaries in phoneme array.

Parameters

  • phonemes: Array of phonemes

Returns

Array of syllables, where each syllable is an array of phonemes


[View source]