class
WordMage::RomanizationMap
- WordMage::RomanizationMap
- Reference
- Object
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.crConstructors
-
.new(mappings : Hash(String, String) = Hash(String, String).new)
Creates a new romanization map.
Instance Method Summary
-
#add_mapping(phoneme : String, romanization : String)
Adds or updates a phoneme-to-romanization mapping.
- #mappings : Hash(String, String)
- #mappings=(mappings : Hash(String, String))
-
#romanize(phonemes : Array(String)) : String
Converts an array of phonemes to written text.
Constructor Detail
Creates a new romanization map.
Parameters
#mappings
: Hash mapping phonemes to their written form (optional)
Instance Method Detail
def add_mapping(phoneme : String, romanization : String)
#
Adds or updates a phoneme-to-romanization mapping.
Parameters
phoneme
: The internal phoneme representationromanization
: The written form to output
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")