class WordMage::RomanizationMap

Overview

Maps phonemes to their written/romanized representations.

RomanizationMap handles the conversion from internal phoneme representations to their final written form. This allows using IPA or custom phoneme symbols internally while outputting readable text.

Example

romanizer = RomanizationMap.new({
  "p" => "p",
  "θ" => "th",    # IPA theta -> "th"
  "ʃ" => "sh",    # IPA esh -> "sh"
  "a" => "a"
})
word = romanizer.romanize(["p", "θ", "a"])  # "ptha"

Defined in:

romanization_map.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(mappings : Hash(String, String) = Hash(String, String).new) #

Creates a new romanization map.

Parameters

  • #mappings: Hash mapping phonemes to their written form (optional)

[View source]

Instance Method Detail

def add_mapping(phoneme : String, romanization : String) #

Adds or updates a phoneme-to-romanization mapping.

Parameters

  • phoneme: The internal phoneme representation
  • romanization: The written form to output

[View source]
def mappings : Hash(String, String) #

[View source]
def mappings=(mappings : Hash(String, String)) #

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

Converts an array of phonemes to written text.

Parameters

  • phonemes: Array of phoneme strings to convert

Returns

String with phonemes converted to their romanized form. Unmapped phonemes are left as-is.

Example

romanizer.romanize(["p", "θ", "a"])  # "ptha" (if θ -> "th")

[View source]