1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
/*!
A reimplementation of Mark Rosenfelder's [pronunciation algorithm][spell] for English.
Mostly an example for rust-soundchange, but also serves as an approximate algorithm.

[spell]: http://zompist.com/spell.html
*/

#![feature(core)]

#[macro_use] extern crate soundchange;
#[macro_use] extern crate log;

use std::char;
use std::str;
use std::fmt;
use std::num::FromPrimitive;

use soundchange::{CharOf, CharTo};

/// A phoneme for English.
///
/// While variants are named after their common respelling
/// (slightly adjusted to fit in the ASCII and to be unique)
/// they do not directly represent an unique sound (say, voiceless bilabial stop /p/).
/// A phoneme rather represents an (conceptual) equivalence class for related sounds,
/// so that it is a minimal unit that can give the difference in meaning.
/// Different dialects of English commonly have different sounds for the same phoneme.
//
// Mark Rosenfelder's scheme doesn't distinguish alphabets and phonemes, so we need to be careful.
// we reuse most consonants, and then remap many vowels into UPPERCASED letters or
// digits or punctuations (ugh). for convenience, "long" vowels [1] are always assigned UPPERCASE.
//
// [1] they are actually not "long", but they have matching "short" vowels.
//     this is a direct result of the Great Vowel Shift, and they were indeed differentiated
//     only by the longness before the GVS, hence the name.
#[derive(PartialEq, Eq, FromPrimitive, Copy, Debug)]
pub enum Phoneme {
    // consonants
    P  = 'p' as isize, // [p]    paper PAYP@R
    B  = 'b' as isize, // [b]    book BUUK
    T  = 't' as isize, // [t]    take TAYK
    D  = 'd' as isize, // [d]    dead DED
    G  = 'g' as isize, // [g]    get GET
    K  = 'k' as isize, // [k]    talk TAWK
    M  = 'm' as isize, // [m]    moon MOON
    N  = 'n' as isize, // [n]    new NOO
    NG = 'ñ' as isize, // [n`]   sing SING
    F  = 'f' as isize, // [f]    four FOHR
    V  = 'v' as isize, // [v]    vine VAIN
    TH = '+' as isize, // [T]    thin THIN
//  DH                 // [D]    this DHIS (not distinguished from TH in the computer rules)
    S  = 's' as isize, // [s]    so SOH
    Z  = 'z' as isize, // [z]    zoo ZOO
    SH = '$' as isize, // [S]    shake SAYK
//  ZH                 // [Z]    measure MEJEWR (only appears as a part of J in the computer rules)
    CH = 'ç' as isize, // [tS]   chew CHOO
    J  = 'j' as isize, // [dZ]   judge JUJ
    R  = 'r' as isize, // [r]    ran RAN
    L  = 'l' as isize, // [l]    late LAYT
    H  = 'h' as isize, // [h]    hang HAYNG
    Y  = 'y' as isize, // [j]    you JOO
    W  = 'w' as isize, // [w]    cow KAW

    // untranslated consonants (should not appear in the final result)
    _C = 'c' as isize,
    _Q = 'q' as isize,
    _X = 'x' as isize,

    // vowels
    AY = 'ä' as isize, // [e(I)] rate RAYT
    A  = 'â' as isize, // [{]    rat RAT
    EE = 'ë' as isize, // [i:]   meet MEET
    E  = 'ê' as isize, // [E]    met MET
    AI = 'ï' as isize, // [aI]   bite BAIT
    I  = 'î' as isize, // [I]    bit BIT
    OH = 'ö' as isize, // [oU]   note NOHT
    O  = 'ô' as isize, // [A]    not NOT
    EW = 'ü' as isize, // [ju:]  cute KEWT
    U  = 'û' as isize, // [V]    cut KUT
    OO = 'u' as isize, // [u:]   coot KOOT
    AW = 'ù' as isize, // [O:]   dog DAWG
    UU = 'ò' as isize, // [U]    cook KUUK
    UH = '@' as isize, // [@]    above UHBOV

    // untranslated vowels (should not appear in the final result)
    _A = 'a' as isize,
    _E = 'e' as isize,
    _I = 'i' as isize,
    _O = 'o' as isize,
}

impl Phoneme {
    #[inline]
    pub fn to_char(&self) -> char {
        char::from_u32(*self as u32).unwrap()
    }

    #[inline]
    pub fn from_char(c: char) -> Option<Phoneme> {
        FromPrimitive::from_u32(c as u32)
    }

    #[inline]
    pub fn is_vowel(&self) -> bool {
        match *self {
            Phoneme::AY | Phoneme::A  | Phoneme::EE | Phoneme::E  |
            Phoneme::AI | Phoneme::I  | Phoneme::OH | Phoneme::O  |
            Phoneme::EW | Phoneme::U  | Phoneme::OO | Phoneme::AW |
            Phoneme::UU | Phoneme::UH | Phoneme::_A | Phoneme::_E |
            Phoneme::_I | Phoneme::_O => true,
            _ => false,
        }
    }

    #[inline]
    pub fn is_consonant(&self) -> bool {
        match *self {
            Phoneme::P  | Phoneme::B  | Phoneme::T  | Phoneme::D  |
            Phoneme::G  | Phoneme::K  | Phoneme::M  | Phoneme::N  |
            Phoneme::NG | Phoneme::F  | Phoneme::V  | Phoneme::TH |
            Phoneme::S  | Phoneme::Z  | Phoneme::SH | Phoneme::CH |
            Phoneme::J  | Phoneme::R  | Phoneme::L  | Phoneme::H  |
            Phoneme::Y  | Phoneme::W  | Phoneme::_C | Phoneme::_Q |
            Phoneme::_X => true,
            _ => false,
        }
    }

    #[inline]
    pub fn is_untranslated(&self) -> bool {
        match *self {
            Phoneme::_C | Phoneme::_Q | Phoneme::_X | Phoneme::_A |
            Phoneme::_E | Phoneme::_I | Phoneme::_O => true,
            _ => false,
        }
    }

    #[inline]
    pub fn is_short_vowel(&self) -> bool {
        // AW `ù`, UU `ò` and UH `@` are neutral
        match *self {
            Phoneme::A  | Phoneme::E  | Phoneme::I  | Phoneme::O  |
            Phoneme::U  | Phoneme::AW | Phoneme::UU | Phoneme::UH => true,
            _ => false,
        }
    }

    #[inline]
    pub fn is_long_vowel(&self) -> bool {
        // AW `ù`, UU `ò` and UH `@` are neutral
        match *self {
            Phoneme::AY | Phoneme::EE | Phoneme::AI | Phoneme::OH |
            Phoneme::EW | Phoneme::AW | Phoneme::UU | Phoneme::UH => true,
            _ => false,
        }
    }

    #[inline]
    pub fn to_short_vowel(&self) -> Phoneme {
        match *self {
            Phoneme::AY | Phoneme::_A => Phoneme::A,
            Phoneme::EE | Phoneme::_E => Phoneme::E,
            Phoneme::AI | Phoneme::_I => Phoneme::I,
            Phoneme::OH | Phoneme::_O => Phoneme::O,
            Phoneme::EW | Phoneme::OO => Phoneme::U,
            p => p,
        }
    }

    #[inline]
    pub fn to_long_vowel(&self) -> Phoneme {
        match *self {
            Phoneme::A | Phoneme::_A => Phoneme::AY,
            Phoneme::E | Phoneme::_E => Phoneme::EE,
            Phoneme::I | Phoneme::_I => Phoneme::AI,
            Phoneme::O | Phoneme::_O => Phoneme::OH,
            Phoneme::U | Phoneme::OO => Phoneme::EW,
            p => p,
        }
    }
}

impl fmt::Display for Phoneme {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        fmt::Display::fmt(&self.to_char(), f)
    }
}

/// A sequence of phonemes.
pub struct Word { s: String }

impl Word {
    /// Creates a word from given phonemes.
    pub fn from_phonemes(ps: &[Phoneme]) -> Word {
        Word { s: ps.iter().map(|p| p.to_char()).collect() }
    }

    /// Generates a pronunciation of given English word.
    pub fn from_english(s: &str) -> Word {
        Word { s: spell_to_sound(s) }
    }

    /// Iterates through phonemes.
    pub fn phonemes<'a>(&'a self) -> WordPhonemes<'a> {
        WordPhonemes { base: self.s.chars() }
    }

    /// Returns a string notation of phonemes.
    pub fn as_str<'a>(&'a self) -> &'a str {
        &self.s
    }
}

impl fmt::Display for Word {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(&self.s, f) }
}

impl fmt::Debug for Word {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Debug::fmt(&self.s, f) }
}

/// An iterator for every phoneme inside given word.
#[derive(Clone)]
pub struct WordPhonemes<'a> { base: str::Chars<'a> }

impl<'a> Iterator for WordPhonemes<'a> {
    type Item = Phoneme;
    fn next(&mut self) -> Option<Phoneme> {
        self.base.next().map(|c| Phoneme::from_char(c).unwrap())
    }
    fn size_hint(&self) -> (usize, Option<usize>) {
        self.base.size_hint()
    }
}

impl<'a> DoubleEndedIterator for WordPhonemes<'a> {
    fn next_back(&mut self) -> Option<Phoneme> {
        self.base.next_back().map(|c| Phoneme::from_char(c).unwrap())
    }
}

/// The actual alphabet-to-phoneme algorithm.
fn spell_to_sound(s: &str) -> String {
    // filter out any non-latin characters
    fn to_ascii_lower_or_none(c: char) -> Option<char> {
        match c {
            'a'...'z' => Some(c),
            'A'...'Z' => Some(char::from_u32(c as u32 + 32).unwrap()),
            _ => None,
        }
    }
    let buf: String = s.chars().filter_map(to_ascii_lower_or_none).collect();
    let s = &buf;

    // predicates
    let is_vowel = |c: Option<char>| {
        c.and_then(Phoneme::from_char).map_or(false, |c| c.is_vowel())
    };
    let is_consonant = |c: Option<char>| {
        c.and_then(Phoneme::from_char).map_or(false, |c| c.is_consonant())
    };
    let is_not_vowel = |c: Option<char>| !is_vowel(c);
    let is_unknown_vowel = |c: Option<char>| {
        match c.and_then(Phoneme::from_char) {
            Some(Phoneme::_A) |
            Some(Phoneme::_E) |
            Some(Phoneme::_I) |
            Some(Phoneme::_O) |
            // any untranslated `u` is automatically a phoneme, but it is unknown before that
            Some(Phoneme::OO) => true,
            _ => false
        }
    };
    let is_long_vowel = |c: Option<char>| {
        c.and_then(Phoneme::from_char).map_or(false, |c| c.is_long_vowel())
    };
    let is_boundary = |c: Option<char>| c.is_none();
    let is_not_boundary = |c: Option<char>| c.is_some();

    // transformers
    let make_short_vowel = |c: char| {
        Phoneme::from_char(c).map_or(c, |c| c.to_short_vowel().to_char())
    };
    let make_long_vowel = |c: char| {
        Phoneme::from_char(c).map_or(c, |c| c.to_long_vowel().to_char())
    };

    let vowel = CharOf(&is_vowel);
    let consonant = CharOf(&is_consonant);
    let no_vowel = CharOf(&is_not_vowel);
    let unknown_vowel = CharOf(&is_unknown_vowel);
    let long_vowel = CharOf(&is_long_vowel);
    let boundary = CharOf(&is_boundary);
    let no_boundary = CharOf(&is_not_boundary);
    let to_short_vowel = CharTo(&make_short_vowel);
    let to_long_vowel = CharTo(&make_long_vowel);

    // we need to split rules to work with the recursion limit
    let s = subst_rules! { s =>
        // digraphs
        "ch" => "ç";
        "sh" => "$";
        "ph" => "f";
        "th" => "+";
        "qu" => "kw";

        // spelling-level changes
        "w" ["r"] => "";
        "w" ["ho"] => "";
        ["w"] "h" => "";
        [boundary "r"] "h" => "";
        ["x"] "h" => "";
        [vowel] "h" [boundary] => "";
        [boundary "e"] "x" [vowel] => "gz";
        "x" => "ks";

        // gh
        "gh" [vowel] => "g";
        [consonant] vowel ["gh"] => to_long_vowel;
        "ough" ["t"] => "ò";
        "augh" ["t"] => "ò";
        "ough" => "ö";
        "gh" => "";

        // unpronouncable combinations
        [boundary] "g" ["n"] => "";
        [boundary] "k" ["n"] => "";
        [boundary] "m" ["n"] => "";
        [boundary] "p" ["t"] => "";
        [boundary] "p" ["s"] => "";
        [boundary] "t" ["m"] => "";

        // medial y = i
        [boundary consonant] "y" [boundary] => "ï";
        [boundary consonant consonant] "y" [boundary] => "ï";
        [boundary consonant consonant consonant] "y" [boundary] => "ï";
        "ey" => "ë";
        "ay" => "ä";
        "oy" => "öy";
        [consonant] "y" [no_vowel] => "i";
        [consonant] "y" ["e" boundary] => "i";
        [no_vowel consonant] "ie" [boundary] => "ï";
    };

    // XXX I don't know why but this split is required for rustdoc but not for rustc.
    let s = subst_rules! { s =>
        // sSl simplification
        ["s"] "t" ["l" vowel boundary] => "";

        // affrication of t + front vowel
        [no_boundary] "ci" [vowel] => "$";
        [no_boundary] "ti" [vowel] => "$";
        [no_boundary] "tu" [vowel] => "çu";
        [no_boundary] "tu" ["r" vowel] => "çu";
        [no_boundary] "tu" ["l" vowel] => "çu";
        [consonant] "si" ["o"] => "$";
        [vowel] "si" ["o"] => "j";
        [consonant] "s" ["ur"] => "$";
        [vowel] "s" ["ur"] => "j";
        ["k"] "s" ["u" vowel] => "$";
        ["k"] "s" ["ur"] => "$";
        ["k"] "s" ["ul"] => "$";

        // intervocalic s
        ["e"] "s" [vowel] => "z";
        ["i"] "s" [vowel] => "z";
        ["o"] "s" [vowel] => "z";
        ["u"] "s" [vowel] => "z";
    };

    let s = subst_rules! { s =>
        // al to ol
        "a" ["ls"] => "ò";
        "a" ["lr"] => "ò";
        "a" ["ll" boundary] => "ò";
        "a" ["lm" boundary] => "ò";
        "a" ["lm" vowel boundary] => "ò";
        [no_vowel] "a" ["lt"] => "ò";
        [no_vowel] "a" ["ld"] => "ò";
        [no_vowel] "a" ["l+"] => "ò";
        [no_boundary] "al" ["k"] => "ò";

        // soft c and g
        "c" ["e"] => "s";
        "c" ["i"] => "s";
        "c" ["ê"] => "s";
        "c" ["î"] => "s";
        "c" ["y"] => "s";
        "c" => "k";
        [no_boundary] "ge" ["a"] => "j";
        [no_boundary] "ge" ["o"] => "j";
        "g" ["e"] => "j";
        "g" ["i"] => "j";
        "g" ["ê"] => "j";
        "g" ["î"] => "j";
        "g" ["y"] => "j";

        // g-hardening guF
        [boundary] "gu" ["e"] => "g";
        [boundary] "gu" ["i"] => "g";
        [boundary] "gu" ["ê"] => "g";
        [boundary] "gu" ["î"] => "g";
        [boundary] "gu" ["y"] => "g";
        "gu" ["e" boundary] => "g";

        // reverse-written final liquids
        [consonant] "re" [boundary] => "@r";
        [consonant] "le" [boundary] => "@l";
    };

    let s = subst_rules! { s =>
        // vowels are long medially and short before 2 consonants or a final one
        [no_vowel] unknown_vowel [consonant vowel] => to_long_vowel;
        [no_vowel] unknown_vowel [consonant no_vowel] => to_short_vowel;

        // special but general rules
        "î" ["nd" boundary] => "ï";
        "ô" ["ss" boundary] => "ò";
        "ô" ["g" boundary] => "ò";
        "ô" ["f" consonant] => "ò";
        "ô" ["lt"] => "ö";
        "ô" ["ld"] => "ö";
        "ô" ["l+"] => "ö";
        ["w"] "â" ["$"] => "ò";
        ["w"] "â" ["ç"] => "ò";
        ["w"] "â" ["tç"] => "ò";
        ["w"] "â" ["t"] => "ô";
        ["w"] "â" ["d"] => "ô";
        ["w"] "â" ["n"] => "ô";
        ["w"] "â" ["s"] => "ô";
        ["w"] "â" ["+"] => "ô";

        // soft gn
        "îg" ["m" no_vowel] => "ï";
        "îg" ["n" no_vowel] => "ï";
        "îg" ["ñ" no_vowel] => "ï";
        ["ei"] "g" ["n"] => "";

        // handle ous
        "ou" ["s" no_vowel] => "@";

        // remove silent -e
        [vowel consonant] "e" [boundary] => "";
        [vowel consonant consonant] "e" [boundary] => "";
        [vowel consonant consonant consonant] "e" [boundary] => "";
    };

    let s = subst_rules! { s =>
        // common affixes
        [no_boundary no_boundary no_boundary] "ë" ["mênt" boundary] => "";
        [no_boundary no_boundary no_boundary] "ë" ["nêss" boundary] => "";
        [no_boundary no_boundary no_boundary] "ë" ["li" boundary] => "";
        [no_boundary no_boundary no_boundary] "ë" ["fûl" boundary] => "";
        [no_boundary no_boundary no_boundary] "ï" ["nêss" boundary] => "ë";

        // shorten (1-char) weak penults after a long
        [long_vowel consonant] long_vowel [consonant vowel boundary] => to_short_vowel;
        [long_vowel consonant consonant] long_vowel [consonant vowel boundary] => to_short_vowel;
        [long_vowel consonant consonant consonant] long_vowel [consonant vowel boundary] =>
            to_short_vowel;

        // double vowels
        "eau" => "ö";
        "ai" => "ä";
        "au" => "ò";
        "âw" => "ò";
        "ee" => "ë";
        "ea" => "ë";
        ["s"] "ei" => "ë";
        "ei" => "ä";
        "eo" => "ë@";
        "êw" => "ü";
        "eu" => "ü";
        "ie" => "ë";
        ["i"] vowel => "@";
        [boundary consonant] "i" => "ï";
        [boundary consonant consonant] "i" => "ï";
        "i" ["@"] => "ë";
        "oa" => "ö";
        "oe" [boundary] => "ö";
        "oo" ["k"] => "ù";
        "oo" => "u";
        "oul" ["d" boundary] => "ù";
        "ou" => "ôw";
        "oi" => "öy";
        "ua" => "ü@";
        "ue" => "u";
        "ui" => "u";
        "ôw" [boundary] => "ö";
    };

    let s = subst_rules! { s =>
        // pesky final syllables
        // XXX the original `english.tc` is incorrect: `V/@/VC(V)_l#` should be `U/@/VC(V)_l#`
        [vowel consonant] unknown_vowel ["l" boundary] => "@";
        [vowel consonant] "ê" ["n" boundary] => "@";
        [vowel consonant] "î" ["n" boundary] => "@";
        [vowel consonant] "â" ["n" boundary] => "@";
        [vowel consonant] "ô" ["n" boundary] => "@";
        [vowel consonant vowel] unknown_vowel ["l" boundary] => "@";
        [vowel consonant consonant] "ê" ["n" boundary] => "@";
        [vowel consonant consonant] "î" ["n" boundary] => "@";
        [vowel consonant consonant] "â" ["n" boundary] => "@";
        [vowel consonant consonant] "ô" ["n" boundary] => "@";

        // suffix simplifications
        [no_boundary no_boundary no_boundary] "a" ["b@l" boundary] => "@";
        [no_boundary no_boundary no_boundary] "ä" ["b@l" boundary] => "@";
        [no_boundary no_boundary no_boundary] "â" ["b@l" boundary] => "@";
        [no_boundary "l"] "ë" ["@n" boundary] => "y";
        [no_boundary "n"] "ë" ["@n" boundary] => "y";

        // unpronounceable finals
        ["m"] "b" [boundary] => "";
        ["m"] "n" [boundary] => "";

        // color the final vowels
        "a" [boundary] => "@";
        "e" [boundary] => "ë";
        "i" [boundary] => "ë";
        "o" [boundary] => "ö";

        // vowels before r
        "ôw" ["r" no_boundary] => "ö";
        "ô" ["r"] => "ö";
        "ò" ["r"] => "ö";
        ["w"] "â" ["r" no_vowel] => "ö";
        "ê" ["rr"] => "ä";
        "ë" ["ri" consonant] => "ä";
        "ë" ["rï" consonant] => "ä";
        "ë" ["rî" consonant] => "ä";
        "â" ["rr"] => "ä";
        "â" ["r" no_vowel] => "ô";
        "â" ["r"] => "ä";
        "ê" ["r"] => "@";
        "î" ["r"] => "@";
        "û" ["r"] => "@";
        "ù" ["r"] => "@";
    };

    let s = subst_rules! { s =>
        // handle ng
        "ng" ["p"] => "ñ";
        "ng" ["t"] => "ñ";
        "ng" ["k"] => "ñ";
        "ng" ["b"] => "ñ";
        "ng" ["d"] => "ñ";
        "ng" ["g"] => "ñ";
        "ng" ["f"] => "ñ";
        "ng" ["s"] => "ñ";
        "ng" ["$"] => "ñ";
        "ng" ["+"] => "ñ";
        "ng" [boundary] => "ñ";
        "n" ["g"] => "ñ";
        "n" ["k"] => "ñ";
        "ô" ["ñ"] => "ò";
        "â" ["ñ"] => "ä";

        // more morphophonological rules
        ["b"] "s" [boundary] => "z";
        ["d"] "s" [boundary] => "z";
        ["g"] "s" [boundary] => "z";
        "s" ["m" boundary] => "z";

        // double consonants
        "s" ["s"] => "";
        "s" ["$"] => "";
        "t" ["t"] => "";
        "t" ["ç"] => "";
        "p" ["p"] => "";
        "k" ["k"] => "";
        "b" ["b"] => "";
        "d" ["d"] => "";
        "d" ["j"] => "";
        "g" ["g"] => "";
        "n" ["n"] => "";
        "m" ["m"] => "";
        "r" ["r"] => "";
        "l" ["l"] => "";
        "f" ["f"] => "";
        "z" ["z"] => "";

    };

    s
}

#[test]
fn test_spell_to_sound() {
    assert_eq!(spell_to_sound("coffee"), "kòfë");
    assert_eq!(spell_to_sound("market"), "môrkêt");
    assert_eq!(spell_to_sound("ugly"), "ûglë");
    assert_eq!(spell_to_sound("high"), "hï");
    assert_eq!(spell_to_sound("canal"), "känâl");
    assert_eq!(spell_to_sound("although"), "òl+ö");
    assert_eq!(spell_to_sound("assure"), "â$ür");
    assert_eq!(spell_to_sound("fish"), "fî$");
}