Skip to main content

Sinophone (三耨風)

build lint coverage Documentation Status

pypi support-version license commit


wuu-Hant

sinophone (IPA: /ˈsaɪnəˌfoʊn/) is a python package that helps to manipulate Chinese phonology. It is divided into two submodules, sinophone.phonetics and sinophone.phonology. The former is a general abstraction of IPA symbols and distinctive features which could well be applied to other languages, while the latter is designed specifically to suit the purpose of working with the phonologies of Chinese languages.

Install

pip install sinophone

Documentation

Please visit the documentation for more information.

Example of use

In the following example, I simulated a tiny portion of Shanghainese phonology. Observe how sinophone can collocate phonemes to create a list of hypothetical syllables, and then pick out the ones that contradict the phonotactic constraint pc. It also applied a phonological rule when printing the syllable in phonetic transcription as bʊ̃ŋ˥˥, instead of the phonemic one, boŋ˥˥.

from sinophone.phonetics import *
from sinophone.phonology import *

# Syllable 音節
# Let's create some syllables.
kaq = Syllable(
    Initial("k"),
    Final(
        nucleus=Nucleus("ɐ"),
        coda=Coda("ʔ"),
    ),
    Tone("˥˥"),
)
kaq
"""
# note that the output is actually colored when printed to the shell.
<Syllable [<Initial 'k'> <Final [<Medial ''> <Nucleus 'ɐ'> <Coda 'ʔ'>]> <Tone '˥˥'>]>
"""

lon = Syllable(Initial("l"), Final(nucleus=Nucleus("o"), coda=Coda("ŋ")), Tone("˨˧"))

bo = Syllable(Initial("b"), Final(nucleus=Nucleus("o")), Tone("˨˧"))


# PhonologicalRule 音韻規則
# Let's create a phonological rule, saying that /o/
# becomes [ʊ̃] when it is followed by a nasal.
pr = PhonologicalRule(
    Nucleus("o"),
    IPAString("ʊ̃"),
    SyllableFeatures({"Final": {IPAFeatureGroup("+nasal")}}),
)
pr
"""
<PhonologicalRule "o -> ʊ̃ / {'Final': {'+nasal'}}">
"""


# PhonotacticConstraint 音位排列制約
# Let's create a phonotactic constraint, saying that
# voiced non-nasal, non-lateral-approximant consonants
# cannot collocate with extra-high-level tone.
pc = PhonotacticConstraint(
    SyllableFeatures(
        {
            "Initial": {
                IPAFeatureGroup("-nasal -lateral-approximant +voiced"),
            },
            "Tone": {IPAFeatureGroup("+extra-high-level")},
        }
    ),
    PhonotacticAcceptability(False, False),
)
pc
"""
<PhonotacticConstraint {'Initial': {'-lateral-approximant -nasal +voiced'},
'Tone': {'+extra-high-level'}}: {'existent': False, 'grammatical': False}>
"""

# Phonology 音系
# Let's create a simple phonology with the above elements.
phonology = Phonology(
    syllables={kaq, bo, lon},
    phonotactics={pc},
    phonological_rules=[pr],
)

# Automatically generate syllable components from syllables.
sorted(phonology.initials)
"""
[<Initial 'b'>, <Initial 'k'>, <Initial 'l'>]
"""

# Automatically collocate to create hypothetical syllables,
# regardless of phonotactics.
spc = sorted(phonology.collocations)

# Pretty-print the above list.
for syllable in spc:
    phonology.pretty_print_syllable(syllable)
"""
.. output abbreviated for brevity
Syllables are colored red if completely contradicting phonotactics, 
green if completely phonotactically acceptable.
See `sinophone.options.RAINBOW_COLOR_SCHEME` for more colors.
"""

# List hypothetical syllables which contradict phonotactics.
[
    syllable.phonetic_ipa_str
    for syllable in spc
    if phonology.render_syllable(syllable).acceptability
    != PhonotacticAcceptability(True, True)
]
"""
[<IPAString 'bʊ̃ŋ˥˥'>, <IPAString 'bo˥˥'>, <IPAString 'bɐʔ˥˥'>]
"""

Metadata

Release files for sinophone 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sinophone 0.0.2
File Size Uploaded Provenance Actions
sinophone-0.0.2.tar.gz 21.9 kB Without provenance Details for sinophone-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sinophone 0.0.2
File Interpreter ABI Platform Actions
sinophone-0.0.2-py3-none-any.whl Python 3 none any Details for sinophone-0.0.2-py3-none-any.whl

Total release size: 40.2 kB

Release files / sinophone-0.0.2.tar.gz

Download URL sinophone-0.0.2.tar.gz
Size 21.9 kB
Tags Source
SHA-256 checksum
How to use checksums
be826050d88cab5e276266ba72024e0512349e9ab196e2de865b40ca7a1ca828
BLAKE2b-256 checksum
How to use checksums
88105dfd68e8b7e8363909a20905a35216214cb40537a3e2b8377ae7621a293c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / sinophone-0.0.2-py3-none-any.whl

Download URL sinophone-0.0.2-py3-none-any.whl
Size 18.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6c9b20b54104a39e90a0e0f9ad406f2626a424730b0e4168ee7a315b1a6069ed
BLAKE2b-256 checksum
How to use checksums
7b4c3db7d939ce386bac2b6d8445dcfbe9d14babd951a15436536c1272b006a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Security for sinophone 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page