Skip to content

Commit 8939ecb

Browse files
committed
another pronunciation test fix
1 parent 5f59c43 commit 8939ecb

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

arda/pron.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import re
22

33

4-
def is_vowel(ch):
4+
def is_vowel(ch, ipa):
55
return ch.lower() in "aeiouyäëïöüÿáéíóúý"
66

77

8-
def is_short_vowel(ch):
8+
def is_short_vowel(ch, ipa):
99
return ch.lower() in "aeiouyäëïöüÿ"
1010

1111

12-
def is_diphthong(s):
12+
def is_diphthong(s, ipa):
1313
return s.lower() in [
1414
# Both
1515
"ai",
@@ -27,34 +27,35 @@ def is_diphthong(s):
2727
]
2828

2929

30-
def is_valid_consonant_cluster(s):
30+
def is_valid_consonant_cluster(s, ipa):
3131
return s.lower().startswith(("gl",)) # @@@ INCOMPLETE!
3232

3333

3434
def display_word(w):
3535
return ".".join(w)
3636

3737

38-
def syllabify(word, debug=False):
38+
def syllabify(word, ipa=False, debug=False):
3939
word = word.lower()
40-
word = re.sub("dh", "ð", word)
41-
word = re.sub("th", "θ", word)
42-
word = re.sub("ch", "χ", word)
43-
word = re.sub("ng(?=.)", "ŋg", word)
44-
word = re.sub("ng", "ŋ", word)
40+
if not ipa:
41+
word = re.sub("dh", "ð", word)
42+
word = re.sub("th", "θ", word)
43+
word = re.sub("ch", "χ", word)
44+
word = re.sub("ng(?=.)", "ŋg", word)
45+
word = re.sub("ng", "ŋ", word)
4546
state = 0
4647
result = []
4748
current_syllable = []
4849
for ch in word[::-1]:
4950
if state == 0:
5051
current_syllable.insert(0, ch)
51-
if is_vowel(ch):
52+
if is_vowel(ch, ipa):
5253
state = 1
5354
if debug:
5455
print("c", state, current_syllable) # pragma: no cover
5556
elif state == 1:
56-
if is_vowel(ch):
57-
if is_diphthong(ch + current_syllable[0]):
57+
if is_vowel(ch, ipa):
58+
if is_diphthong(ch + current_syllable[0], ipa):
5859
current_syllable.insert(0, ch)
5960
if debug:
6061
print("c", state, current_syllable) # pragma: no cover
@@ -71,7 +72,7 @@ def syllabify(word, debug=False):
7172
if debug:
7273
print("c", state, current_syllable) # pragma: no cover
7374
elif state == 2:
74-
if is_vowel(ch):
75+
if is_vowel(ch, ipa):
7576
result.insert(0, current_syllable)
7677
if debug:
7778
print("r", result) # pragma: no cover
@@ -80,7 +81,7 @@ def syllabify(word, debug=False):
8081
print("c", state, current_syllable) # pragma: no cover
8182
state = 1
8283
else:
83-
if is_valid_consonant_cluster(ch + "".join(current_syllable)):
84+
if is_valid_consonant_cluster(ch + "".join(current_syllable), ipa):
8485
current_syllable.insert(0, ch)
8586
if debug:
8687
print("c", state, current_syllable) # pragma: no cover
@@ -102,7 +103,7 @@ def syllabify(word, debug=False):
102103
result[-1] = result[-1].upper()
103104
elif len(result) == 2:
104105
result[-2] = result[-2].upper()
105-
elif not is_short_vowel(result[-2][-1]):
106+
elif not is_short_vowel(result[-2][-1], ipa):
106107
result[-2] = result[-2].upper()
107108
else:
108109
result[-3] = result[-3].upper()

pron_test.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ Ancalima ɑnkɑlimɑ
122122
Elentári elentɑːri
123123
Denethor deneθor
124124
Periannath periɑnnɑθ
125-
Ecthelion ekθeliοn
125+
Ecthelion ekθelion
126126
Pelargir pelɑrgir
127127
silivren silivren
128128
andúne ɑnduːne

0 commit comments

Comments
 (0)