Skip to main content

A Classical Phonology framework

Project description

loquax

A Classical Phonology framework

Code style: black Build status

Loquax, (Latin for "chatty"), is an extensible Python library for analyzing and manipulating phonology of endangered & extinct languages. With hobbyists and academia in mind, it provides functionality for:

...

...

Its a zero-dependency framework, with functional style Python 3.10+ features to revive the sounds of the past, one phoneme at a time.

Try It Out Now: Loquax Latin Online

To see loquax in action without diving into code, visit Loquax Latin Online. This web application uses loquax under the hood. On the Loquax Latin Online, you can perform real-time Latin syllabification, IPA transcription, and scansion.

Quickstart

pip install loquax
from loquax import Document
from loquax.languages import Latin

catilinarian_orations = Document("Quoūsque tandem abutēre, Catilīna, patientiā nostrā?", Latin)
print(catilinarian_orations.to_string(ipa=True, scansion=True))

# outputs:
# kʷɔ.uːs.kʷɛ    tan.dɛm    a.bʊ.teː.rɛ    ka.tɪ.liː.na    pa.tɪ.ɛn.tɪ.aː    nɔs.traː
#  u   -   u      -   u     u u   -  u     u  u   -  u     u  u  u  u  -      u   -

Syllabification & Tokenization {#syllabification}

print(catilinarian_orations.tokens)

# outputs:
# [kʷɔ.uːs.kʷɛ, tan.dɛm, a.bʊ.teː.rɛ, ka.tɪ.liː.na, pa.tɪ.ɛn.tɪ.aː, nɔs.traː]

print(catilinarian_orations.tokens[0].syllables)

# outputs:
# [quo, ūs, que]

Phoneme Analysis

Understand unique sounds and their roles within words relative to a Language

from loquax.abstractions import Phoneme
from loquax.languages import Latin

p = Phoneme('p', Latin)
print(p.is_consonant and p.is_liquid)  # outputs: True

Morphological Transformations {#morphological-transformations}

The central problem of phonology is that linguistic units have changing features depending on their context and neighbours.

Loquax allows users to tackle this by defining their own morphisms.

In this example, we create a Morphism that targets syllables with a nucleus and at least one coda, then transforms them into long syllables. The transformation is only applied if the next syllable has an onset of length greater than or equal to one.

from loquax.morphisms import Morphism, Rule, RuleSequence
from loquax.syllables import Syllable
from dataclasses import replace

long_position_morphism = Morphism[Syllable](
    target=Rule[Syllable](check_fn=lambda s: s.nucleus and s.coda and len(s.coda) >= 1),
    transformation=lambda s: replace(s, is_long=True),
    suffix=RuleSequence(
        [Rule[Syllable](check_fn=lambda s: s.coda and len(s.onset) >= 1)]
    ),
)

Once you've got a handle on individual morphisms, it's time to start collecting them! MorphismStore helps you to organize your morphisms in a neat and structured way.

from loquax.abstractions import MorphismStore

# Assuming morphism1, morphism2, morphism3 are predefined Morphism objects...
morphism_store = MorphismStore([morphism1, morphism2, morphism3])

With a well-organized MorphismStore, applying transformations becomes a breeze.

Make use of the apply_all method to apply all transformations in your MorphismStore to a given syllable or phoneme sequence, in the order they were added to the store.

This way, you can simulate a chain of transformations or even model complex linguistic phenomena with a single function call.

# Consider we have a sequence of syllables...
syllables_sequence = [syllable1, syllable2, syllable3]

# Apply all transformations stored in MorphismStore
transformed_sequence = morphism_store.apply_all(syllables_sequence)

# transformed_sequence now holds the syllables transformed by morphism1, morphism2, morphism3 in order.

IPA Transliteration {#ipa-transliteration}

To convert text into the International Phonetic Alphabet for universal comprehension, you can use the to_string function with ipa=True:

print(catilinarian_orations.to_string(ipa=True))

# outputs:
# kʷɔ.uːs.kʷɛ    tan.dɛm    a.bʊ.teː.rɛ    ka.tɪ.liː.na    pa.tɪ.ɛn.tɪ.aː    nɔs.traː

Scansion {#scansion}

Scansion is the process of marking the stresses in a poem, and dividing the lines into feet. It's a critical part of the study and enjoyment of classical verse, like in Latin and Ancient Greek poetry. Loquax makes it easy to integrate scansion into your language analysis pipeline.

Currently only differentiation between long and short syllables is made

print(catilinarian_orations.to_string(scansion=True))

# outputs:
# quo.ūs.que    tan.dem    a.bu.tē.re    ca.ti.lī.na    pa.ti.en.ti.ā    nos.trā
#  u  -   u      -   u     u u  -  u     u  u  -  u     u  u  u  u  -     u   -

Extensibility {#extensibility}

Loquax allows for extensibility, so you can build and customize your own language rules for unique or theoretical languages. Here's an example of how to define custom rules and apply them:

# Create your own custom language with unique rules and phonemes
from loquax.languages import Latin
from loquax.abstractions import (
    PhonemeSyllabificationRuleStore, Language, 
    Constants, Tokenizer, MorphismStore, 
    Syllable, Morphism, Phoneme
)

# Let's suppose we have defined custom syllabification rules and constants
custom_syllabification_rules = PhonemeSyllabificationRuleStore(...)
custom_constants = Constants(...)
custom_tokenizer = Tokenizer(...)
custom_syllable_morphisms = MorphismStore[Syllable]([...])
custom_phoneme_morphisms = MorphismStore[Phoneme]([...])

# Creation of our language object we can instantiate new `Documents` and other abstractions with
my_lang = Language(
    language_name='MyLang',
    iso_639_code='myl', # Made-up ISO 639 code for our custom language
    constants=custom_constants,
    syllabification_rules=custom_syllabification_rules,
    syllable_morphisms=custom_syllable_morphisms,
    phoneme_morphisms=custom_phoneme_morphisms,
    tokenizer=custom_tokenizer,
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

loquax-0.1.5.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

loquax-0.1.5-py3-none-any.whl (26.6 kB view details)

Uploaded Python 3

File details

Details for the file loquax-0.1.5.tar.gz.

File metadata

  • Download URL: loquax-0.1.5.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for loquax-0.1.5.tar.gz
Algorithm Hash digest
SHA256 74d92cfd11e6b10479dae4ff0494d8646a0021f8db129df9a28b83a7549075f4
MD5 c958673586e12814a164b892ca69d448
BLAKE2b-256 61e4d5311ad2c44f16c477e4a8542cf349e9262b76607c9beca5f8ec8c45f0b4

See more details on using hashes here.

File details

Details for the file loquax-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: loquax-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 26.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for loquax-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e3abe2b6220a2609b07869c9b552e01b7746cbd0bc691cb481f29e67fff1a099
MD5 93427bdf05461c1ebdc25c78a7a9af96
BLAKE2b-256 b6850d51b2565a2a222bb7e9a7740bb110ea832dc88250bd36537574fa391a1f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page