Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deal with 'o', double 'u' #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions ipa-uk.py
Original file line number Diff line number Diff line change
@@ -134,6 +134,8 @@ def ipa(text: str, check_accent: bool) -> str:
r"([йклмнпрстфхцчшщ])\1": r"\1ː",
r"дждж": r"джː",
r"дздз": r"дзː",
# double vowels:
r"уу": r"уː",
}

phonetic: str = text
@@ -153,7 +155,7 @@ def ipa(text: str, check_accent: bool) -> str:
# including stress mark for single-syllable words if check_accent is set to true
number_of_vowels = len(re.findall(r"[ɑɛiɪuɔ]", phonetic))
if number_of_vowels == 1 and check_accent:
phonetic = re.sub(r"([ɑɛiɪuɔ])", r"ˈ\1", phonetic)
phonetic = re.sub(r"([ɑɛiɪuo])", r"ˈ\1", phonetic)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two lines above we are counting vowels and using this list of characters: ɑɛiɪuɔ
And here we are using o instead of ɔ. As far as I can understand from the code, there is no chance, that the word at this point of the processing will have any o's, as they are unconditionally replaced with ɔ.

Copy link
Collaborator Author

@AnastasiaKuliak AnastasiaKuliak Jun 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to rewrite this. We need to add 'o' to the 'number_of_vowels' because otherwise stressing of 'o's works pretty randomly.


# palatalizable consonants before /i/ or /j/ become palatalized
phonetic = re.sub(r"(" + palatalizable + ")([ː]?)([ˈ]?)i", r"\1ʲ\2\3i", phonetic)
@@ -222,11 +224,12 @@ def ipa(text: str, check_accent: bool) -> str:
# unstressed /ɑ/ has an allophone [ɐ]
phonetic = re.sub(r"([^ˈ])ɑ", r"\1ɐ", phonetic)
phonetic = re.sub(r"^ɑ", r"ɐ", phonetic)
# unstressed /u/ has an allophone [ʊ]
phonetic = re.sub(r"([^ˈ])u", r"\1ʊ", phonetic)
phonetic = re.sub(r"^u", r"ʊ", phonetic)
# unstressed /ɔ/ has a stressed allophone [o]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I believe the comment should say stressed /ɔ/

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yeah, you're right

phonetic = re.sub(r"(ˈ)ɔ", r"\1o", phonetic)
# unstressed /ɔ/ has by assimilation an allophone [o] before a stressed syllable with /u/ or /i/
phonetic = re.sub(r"ɔ([bdzʒɡɦmnlrpftskxʲʃ͡]+)ˈ([uiʊ]+)", r"o\1ˈ\2", phonetic)
# unstressed /u/ has an allophone [ʊ]
phonetic = re.sub(r"([^ˈ])u", r"\1ʊ", phonetic)
# one allophone [e] covers unstressed /ɛ/ and /ɪ/
phonetic = re.sub(r"([^ˈ])ɛ", r"\1e", phonetic)
phonetic = re.sub(r"^ɛ", r"e", phonetic)
@@ -261,5 +264,9 @@ def ipa(text: str, check_accent: bool) -> str:


if __name__ == "__main__":
for w in [f"Сла{ACUTE}ва", f"Украї{ACUTE}ні", f"сме{ACUTE}рть", f"ворога{ACUTE}м"]:
print(w, "->", ipa(w, check_accent=True))
for w in [f"Сла{ACUTE}ва", f"Украї{ACUTE}ні", f"сме{ACUTE}рть", f"ворога{ACUTE}м",
# подвійний "у"
f"ва{ACUTE}куум",
# "o"
f"при{ACUTE}пхнутого", f"поверхово{ACUTE}див", f"електро{ACUTE}нні"]:
print(w, "->", ipa(w, check_accent=True))