From c5ff1052b43eea3e9ff777e7b5ba73775e5b43de Mon Sep 17 00:00:00 2001 From: Serhiy Stetskovych Date: Thu, 28 Dec 2023 12:48:45 +0200 Subject: [PATCH 1/2] Add test pipeline. --- .github/workflows/python-package.yml | 40 +++++++++++++++ ipa_uk/__init__.py | 2 +- tests/test_phonemizations.py | 76 ++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/python-package.yml create mode 100644 tests/test_phonemizations.py diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml new file mode 100644 index 0000000..6d9749b --- /dev/null +++ b/.github/workflows/python-package.yml @@ -0,0 +1,40 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python package + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + workflow_call: + +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.9", "3.10", "3.11"] + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install package + run: | + python -m pip install --upgrade pip + python -m pip install flake8 pytest + pip install . + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 ipa_uk --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 ipa_uk --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest diff --git a/ipa_uk/__init__.py b/ipa_uk/__init__.py index 6f171a7..f50c0e3 100644 --- a/ipa_uk/__init__.py +++ b/ipa_uk/__init__.py @@ -27,7 +27,7 @@ class AccentIsMissing(ValueError): pass -def ipa(text: str, check_accent: bool) -> str: +def ipa(text: str, check_accent: bool = False) -> str: """ Returns the IPA transcription of the given word or sentence according to the Wiktionary algorithm diff --git a/tests/test_phonemizations.py b/tests/test_phonemizations.py new file mode 100644 index 0000000..a44f072 --- /dev/null +++ b/tests/test_phonemizations.py @@ -0,0 +1,76 @@ +from ipa_uk import ipa, ACUTE + +def test_without_stress(): + assert ipa(f"ма{ACUTE}ма") == "ˈmɑmɐ" + assert ipa("мова") == "mɔʋɐ" + assert ipa("віра") == "ʋirɐ" + assert ipa("примха") == "prɪmxɐ" + assert ipa("велич") == "ʋɛlɪʧ" + assert ipa("Петре") == "pɛtre" + assert ipa("мине") == "menɛ" + assert ipa("осінь") == "ɔsʲinʲ" + assert ipa("тому") == "tomu" + assert ipa("Умань") == "umɐnʲ" + assert ipa("туди") == "tʊdɪ" + + assert ipa("пил") == "pɪl" + assert ipa("піт") == "pʲit" + assert ipa("бук") == "buk" + assert ipa("біль") == "bʲilʲ" + assert ipa("мат") == "mɑt" + assert ipa("стать") == "stɑtʲ" + assert ipa("дим") == "dɪm" + assert ipa("дім") == "dʲim" + assert ipa("кут") == "kut" + assert ipa("кіт") == "kʲit" + assert ipa("ґуля") == "gulʲɐ" + assert ipa("ґіпс") == "gʲips" + assert ipa("глум") == "ɦlum" + assert ipa("гість") == "ɦʲisʲtʲ" + assert ipa("хор") == "xɔr" + assert ipa("хід") == "xʲid" + assert ipa("фах") == "fɑx" + assert ipa("фільм") == "fʲilʲm" + assert ipa("вир") == "ʋɪr" + assert ipa("він") == "ʋʲin" + assert ipa("вухо") == "wuxo" + assert ipa("враз") == "wrɑz" + assert ipa("вперше") == "ʍpɛrʃe" + assert ipa("сад") == "sɑd" + assert ipa("Сян") == "sʲɐn" # alternative ɕɐn + assert ipa("зад") == "zɑd" + assert ipa("зір") == "zʲir" # alternative ʑir + assert ipa("шар") == "ʃɑr" + assert ipa("шість") == "ʃʲisʲtʲ" + assert ipa("затишшя") == "zɐtɪʃʲ:ɐ" + assert ipa("жар") == "ʒɑr" + assert ipa("жінка") == "ʒʲinkɐ" + assert ipa("заміжжя") == "zɐmiʒʲ:ɐ" + assert ipa("цирк") == "ʦɪrk" + assert ipa("ціна") == "ʦʲinɑ" + assert ipa("дзень") == "ʣɛnʲ" + assert ipa("дзінь") == "ʣʲinʲ" + assert ipa("час") == "ʧɑs" + assert ipa("чіп") == "ʧʲip" + assert ipa("узбіччя") == "ʊzbʲiʧʲ:ɐ" + assert ipa("бджола") == "bdʒolɑ" + assert ipa("бджіл") == "bdʒʲil" + assert ipa("мат") == "mɑt" + assert ipa("міра") == "mʲirɐ" + assert ipa("нас") == "nɑs" + assert ipa("ніс") == "nʲis" + assert ipa("лук") == "luk" + assert ipa("люк") == "lʲʊk" + assert ipa("рак") == "rɑk" + assert ipa("ряд") == "rʲɐd" + assert ipa("як") == "jɐk" + assert ipa("гай") == "ɦɑi̯" + assert ipa("найшов") == "nɐi̯ʃɔu̯" + assert ipa("став") == "stɑu̯" + + assert ipa("Полісся") == "polʲisʲ:ɐ" + assert ipa("чужоземець") == "ˌt͡ʃʊʒozɛmet͡sʲ" + + + + From 6b71fa0d46fb3737ad8c5ac5847061b30777c92e Mon Sep 17 00:00:00 2001 From: Serhiy Stetskovych Date: Fri, 29 Dec 2023 13:50:20 +0200 Subject: [PATCH 2/2] Add tests for vowels --- tests/test_phonemizations.py | 161 ++++++++++++++++++++--------------- 1 file changed, 94 insertions(+), 67 deletions(-) diff --git a/tests/test_phonemizations.py b/tests/test_phonemizations.py index a44f072..7e87e30 100644 --- a/tests/test_phonemizations.py +++ b/tests/test_phonemizations.py @@ -1,75 +1,102 @@ from ipa_uk import ipa, ACUTE -def test_without_stress(): +def test_stressed_a(): assert ipa(f"ма{ACUTE}ма") == "ˈmɑmɐ" - assert ipa("мова") == "mɔʋɐ" - assert ipa("віра") == "ʋirɐ" - assert ipa("примха") == "prɪmxɐ" - assert ipa("велич") == "ʋɛlɪʧ" - assert ipa("Петре") == "pɛtre" - assert ipa("мине") == "menɛ" - assert ipa("осінь") == "ɔsʲinʲ" - assert ipa("тому") == "tomu" - assert ipa("Умань") == "umɐnʲ" - assert ipa("туди") == "tʊdɪ" + +def test_unstressed_a(): + assert ipa(f"мо{ACUTE}ва") == "ˈmɔu̯ɐ" + +def test_stressed_e(): + assert ipa(f"ве{ACUTE}лич") == "ˈʋɛlet͡ʃ" + +def test_unstressed_e(): + assert ipa(f"Пе{ACUTE}тре") == "ˈpɛtre" + +def test_stressed_y(): + assert ipa(f"при{ACUTE}мха") == "ˈprɪmxɐ" + +def test_unstressed_y(): + assert ipa(f"мине{ACUTE}") == "meˈnɛ" + +def test_stressed_i(): + assert ipa(f"ві{ACUTE}ра") == "ˈʋʲirɐ" + +def test_unstressed_i(): + assert ipa(f"ко{ACUTE}рінь") == "ˈkɔrʲinʲ" + +def test_stressed_o(): + assert ipa(f"коро{ACUTE}ва") == "kɔˈrɔu̯ɐ" + +def test_unstressed_o(): + assert ipa(f"о{ACUTE}сінь") == "ˈɔsʲinʲ" + +def test_stressed_u(): + assert ipa(f"У{ACUTE}мань") == "ˈumɐnʲ" + +def test_unstressed_u(): + assert ipa(f"туди{ACUTE}") == "tʊˈdɪ" + + # assert ipa("тому") == "tomu" + + - assert ipa("пил") == "pɪl" - assert ipa("піт") == "pʲit" - assert ipa("бук") == "buk" - assert ipa("біль") == "bʲilʲ" - assert ipa("мат") == "mɑt" - assert ipa("стать") == "stɑtʲ" - assert ipa("дим") == "dɪm" - assert ipa("дім") == "dʲim" - assert ipa("кут") == "kut" - assert ipa("кіт") == "kʲit" - assert ipa("ґуля") == "gulʲɐ" - assert ipa("ґіпс") == "gʲips" - assert ipa("глум") == "ɦlum" - assert ipa("гість") == "ɦʲisʲtʲ" - assert ipa("хор") == "xɔr" - assert ipa("хід") == "xʲid" - assert ipa("фах") == "fɑx" - assert ipa("фільм") == "fʲilʲm" - assert ipa("вир") == "ʋɪr" - assert ipa("він") == "ʋʲin" - assert ipa("вухо") == "wuxo" - assert ipa("враз") == "wrɑz" - assert ipa("вперше") == "ʍpɛrʃe" - assert ipa("сад") == "sɑd" - assert ipa("Сян") == "sʲɐn" # alternative ɕɐn - assert ipa("зад") == "zɑd" - assert ipa("зір") == "zʲir" # alternative ʑir - assert ipa("шар") == "ʃɑr" - assert ipa("шість") == "ʃʲisʲtʲ" - assert ipa("затишшя") == "zɐtɪʃʲ:ɐ" - assert ipa("жар") == "ʒɑr" - assert ipa("жінка") == "ʒʲinkɐ" - assert ipa("заміжжя") == "zɐmiʒʲ:ɐ" - assert ipa("цирк") == "ʦɪrk" - assert ipa("ціна") == "ʦʲinɑ" - assert ipa("дзень") == "ʣɛnʲ" - assert ipa("дзінь") == "ʣʲinʲ" - assert ipa("час") == "ʧɑs" - assert ipa("чіп") == "ʧʲip" - assert ipa("узбіччя") == "ʊzbʲiʧʲ:ɐ" - assert ipa("бджола") == "bdʒolɑ" - assert ipa("бджіл") == "bdʒʲil" - assert ipa("мат") == "mɑt" - assert ipa("міра") == "mʲirɐ" - assert ipa("нас") == "nɑs" - assert ipa("ніс") == "nʲis" - assert ipa("лук") == "luk" - assert ipa("люк") == "lʲʊk" - assert ipa("рак") == "rɑk" - assert ipa("ряд") == "rʲɐd" - assert ipa("як") == "jɐk" - assert ipa("гай") == "ɦɑi̯" - assert ipa("найшов") == "nɐi̯ʃɔu̯" - assert ipa("став") == "stɑu̯" + # assert ipa("пил") == "pɪl" + # assert ipa("піт") == "pʲit" + # assert ipa("бук") == "buk" + # assert ipa("біль") == "bʲilʲ" + # assert ipa("мат") == "mɑt" + # assert ipa("стать") == "stɑtʲ" + # assert ipa("дим") == "dɪm" + # assert ipa("дім") == "dʲim" + # assert ipa("кут") == "kut" + # assert ipa("кіт") == "kʲit" + # assert ipa("ґуля") == "gulʲɐ" + # assert ipa("ґіпс") == "gʲips" + # assert ipa("глум") == "ɦlum" + # assert ipa("гість") == "ɦʲisʲtʲ" + # assert ipa("хор") == "xɔr" + # assert ipa("хід") == "xʲid" + # assert ipa("фах") == "fɑx" + # assert ipa("фільм") == "fʲilʲm" + # assert ipa("вир") == "ʋɪr" + # assert ipa("він") == "ʋʲin" + # assert ipa("вухо") == "wuxo" + # assert ipa("враз") == "wrɑz" + # assert ipa("вперше") == "ʍpɛrʃe" + # assert ipa("сад") == "sɑd" + # assert ipa("Сян") == "sʲɐn" # alternative ɕɐn + # assert ipa("зад") == "zɑd" + # assert ipa("зір") == "zʲir" # alternative ʑir + # assert ipa("шар") == "ʃɑr" + # assert ipa("шість") == "ʃʲisʲtʲ" + # assert ipa("затишшя") == "zɐtɪʃʲ:ɐ" + # assert ipa("жар") == "ʒɑr" + # assert ipa("жінка") == "ʒʲinkɐ" + # assert ipa("заміжжя") == "zɐmiʒʲ:ɐ" + # assert ipa("цирк") == "ʦɪrk" + # assert ipa("ціна") == "ʦʲinɑ" + # assert ipa("дзень") == "ʣɛnʲ" + # assert ipa("дзінь") == "ʣʲinʲ" + # assert ipa("час") == "ʧɑs" + # assert ipa("чіп") == "ʧʲip" + # assert ipa("узбіччя") == "ʊzbʲiʧʲ:ɐ" + # assert ipa("бджола") == "bdʒolɑ" + # assert ipa("бджіл") == "bdʒʲil" + # assert ipa("мат") == "mɑt" + # assert ipa("міра") == "mʲirɐ" + # assert ipa("нас") == "nɑs" + # assert ipa("ніс") == "nʲis" + # assert ipa("лук") == "luk" + # assert ipa("люк") == "lʲʊk" + # assert ipa("рак") == "rɑk" + # assert ipa("ряд") == "rʲɐd" + # assert ipa("як") == "jɐk" + # assert ipa("гай") == "ɦɑi̯" + # assert ipa("найшов") == "nɐi̯ʃɔu̯" + # assert ipa("став") == "stɑu̯" - assert ipa("Полісся") == "polʲisʲ:ɐ" - assert ipa("чужоземець") == "ˌt͡ʃʊʒozɛmet͡sʲ" + # assert ipa("Полісся") == "polʲisʲ:ɐ" + # assert ipa("чужоземець") == "ˌt͡ʃʊʒozɛmet͡sʲ"