Package: loquax
loquaxAClassicalPhonology frameworkLoquax, (Latin for "chatty"), is anextensiblePython library for analyzing and manipulating phonology of endangered & extinct languages. With hobbyists and academia in mind, it provides functionality for:...SyllabificationBreak down words into their fundamental phonetic components.Phoneme Analysis:Understand the unique sounds and their roles within words.Morphological Transformations:Observe and manipulate the structure of words.IPA Transliteration:Convert text into the International Phonetic Alphabet for universal comprehension.Scansion:Analyze the rhythm of verse in classical poetry, and syllable weight in general.Extensibility:Build and customize your own language rules for unique or theoretical languages....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 OnlineTo seeloquaxin action without diving into code, visitLoquax Latin Online. This web application usesloquaxunder the hood.
On the Loquax Latin Online, you can perform real-time Latin syllabification, IPA transcription, and scansion.QuickstartpipinstallloquaxfromloquaximportDocumentfromloquax.languagesimportLatincatilinarian_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 AnalysisUnderstand unique sounds and their roles within words relative to aLanguagefromloquax.abstractionsimportPhonemefromloquax.languagesimportLatinp=Phoneme('p',Latin)print(p.is_consonantandp.is_liquid)# outputs: TrueMorphological 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 aMorphismthat 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.fromloquax.morphismsimportMorphism,Rule,RuleSequencefromloquax.syllablesimportSyllablefromdataclassesimportreplacelong_position_morphism=Morphism[Syllable](target=Rule[Syllable](check_fn=lambdas:s.nucleusands.codaandlen(s.coda)>=1),transformation=lambdas:replace(s,is_long=True),suffix=RuleSequence([Rule[Syllable](check_fn=lambdas:s.codaandlen(s.onset)>=1)]),)Once you've got a handle on individual morphisms, it's time to start collecting them!MorphismStorehelps you to organize your morphisms in a neat and structured way.fromloquax.abstractionsimportMorphismStore# Assuming morphism1, morphism2, morphism3 are predefined Morphism objects...morphism_store=MorphismStore([morphism1,morphism2,morphism3])With a well-organizedMorphismStore, applying transformations becomes a breeze.Make use of theapply_allmethod 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 MorphismStoretransformed_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 theto_stringfunction withipa=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 madeprint(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 phonemesfromloquax.languagesimportLatinfromloquax.abstractionsimport(PhonemeSyllabificationRuleStore,Language,Constants,Tokenizer,MorphismStore,Syllable,Morphism,Phoneme)# Let's suppose we have defined custom syllabification rules and constantscustom_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 withmy_lang=Language(language_name='MyLang',iso_639_code='myl',# Made-up ISO 639 code for our custom languageconstants=custom_constants,syllabification_rules=custom_syllabification_rules,syllable_morphisms=custom_syllable_morphisms,phoneme_morphisms=custom_phoneme_morphisms,tokenizer=custom_tokenizer,)