Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
626 lines (386 sloc) 11.1 KB
This is a literate doctest. Run python -m doctest -v docs.rst to test.

Characters

>>> from greek_accentuation.characters import *

The greek_accentuation.characters module provides basic analysis and manipulation of Greek characters in terms of their Unicode diacritics as if decomposed.

For example:

>>> base('')
'α'
>>> base('Ι')
'Ι'
>>> iota_subscript('')
'\u0345'
>>> IOTA_SUBSCRIPT
'\u0345'
>>> iota_subscript('') == IOTA_SUBSCRIPT
True
>>> not iota_subscript('α')
True
>>> add_diacritic('α', IOTA_SUBSCRIPT)
'ᾳ'

As well as iota_subscript, this works for breathing:

>>> breathing('') == ROUGH
True

accent:

>>> accent('') == ACUTE
True

diaeresis:

>>> diaeresis('') == DIAERESIS
False
>>> diaeresis('ϋ') == DIAERESIS
True

and length:

>>> length('') == SHORT
True
>>> length('') == LONG
True

If the length is not indicated, length will return None:

>>> length('υ')

You can strip the length diacritic if one exists:

>>> strip_length('')
'υ'

If you only want to strip the length diacritic when it's redundant with the circumflex:

>>> remove_redundant_macron('ῡ͂')
'ῦ'
>>> remove_redundant_macron('')
'ῡ'

add_diacritic can be stacked:

>>> add_diacritic(add_diacritic('ο', ROUGH), ACUTE)
'ὅ'

Syllabify

>>> from greek_accentuation.syllabify import *

The greek_accentuation.syllabify module provides basic analysis and manipulation of Greek syllables.

You can syllabify a word with syllabify:

>>> syllabify('γυναικός')
['γυ', 'ναι', 'κός']
>>> syllabify('φῡ́ω')
['φῡ́', 'ω']

There is also a display_word function for displaying the syllabification:

>>> display_word(syllabify('καταλλάσσω'))
'κα.ταλ.λάσ.σω'

Words without vowels will syllabify as a single component:

>>> syllabify('γγγ')
['γγγ']

You can find out if a given character is a vowel or not:

>>> is_vowel('')
True
>>> is_vowel('γ')
False

You can also find out if a sequence of two characters is a diphthong:

>>> is_diphthong('αι')
True
>>> is_diphthong('αε')
False
>>> is_diphthong('αϋ')
False

You can get the ultima, penult or antepenult of a word:

>>> ultima('γυναικός')
'κός'
>>> penult('οἰκία')
'κί'
>>> antepenult('καταλλάσσω')
'ταλ'
>>> antepenult('λόγος')

Given a syllable you can further break it down into onset, nucleus and coda:

>>> onset('κός')
'κ'
>>> nucleus('κός')
'ό'
>>> coda('κός')
'ς'

Or combinations like rime or body:

>>> rime('κός')
'ός'
>>> body('κός')
'κό'
>>> body('ό')
'ό'

If you want to access the onset, nucleus AND coda, it's more efficient to just use:

>>> onset_nucleus_coda('κός')
('κ', 'ό', 'ς')

coda and onset may sometimes return None:

>>> coda('ναι')

Breathing is considered part of the onset:

>>> onset('οἰ')
'̓'
>>> onset_nucleus_coda('ναι')
('ν', 'αι', '')
>>> onset_nucleus_coda('οἰ')
('̓', 'οι', '')

The coda and onset_nucleus_code functions know how to handle moveable nu when indicated with parentheses:

>>> onset_nucleus_coda('ἠ(ν)')
('̓', 'η', '(ν)')

A "word" without vowels is just treated as having an onset:

>>> onset_nucleus_coda('βββ')
('βββ', '', '')
>>> onset('βββ')
'βββ'
>>> nucleus('βββ')
>>> coda('βββ')

You can split out the initial breathing:

>>> split_initial_breathing('οἰκία') == (SMOOTH, 'οικία')
True
>>> split_initial_breathing('λόγος') == (None, 'λόγος')
True
>>> split_initial_breathing('') == (ROUGH, 'ό')
True

This is actually more commonly just used as the debreath function which drops smooth breathing and replaces rough breathing with an h:

>>> debreath('οἰκία')
'οικία'
>>> debreath('')
'hό'
>>> debreath('λόγος')
'λόγος'
>>> debreath('κἀγω')
'κἀγω'

The rebreath function will convert h back to rough breathing and add smooth breathing if necessary, effectively reversing debreath.

>>> rebreath('οικία')
'οἰκία'
>>> rebreath('')
'ὅ'

You can find out the length of a syllable:

>>> syllable_length('κός') == SHORT
True
>>> syllable_length('σω') == LONG
True
>>> syllable_length('τοῦ') == LONG
True
>>> syllable_length('') == LONG
True

If the syllable length is unknown, syllable_length will return None which is aliased to UNKNOWN:

>>> syllable_length('ναι') == UNKNOWN
True

You can optionally pass syllable_length a boolean argument final to tell it whether it's the final syllable in a word, which will affect its handling of certain diphthongs:

>>> syllable_length('οἰ', final=False) == LONG
True
>>> syllable_length('ναι', final=True) == SHORT
True
>>> syllable_length('ναι', final=False) == LONG
True

You can extract the accent of a syllable with syllable_accent:

>>> syllable_accent('κός') == ACUTE
True
>>> syllable_accent('ναι') is None
True
>>> syllable_accent('φῶς') == CIRCUMFLEX
True

You can also test the accentuation class of a word:

>>> oxytone('θεός')
True
>>> paroxytone('λόγος')
True
>>> proparoxytone('κύριος')
True
>>> perispomenon('θεοῦ')
True
>>> properispomenon('δοῦλος')
True
>>> barytone('λόγος')
True

You can automatically add smooth breathing if necessary:

>>> add_necessary_breathing('οι')
'οἰ'
>>> add_necessary_breathing('ελήλυθας')
'ἐλήλυθας'
>>> add_necessary_breathing('άνθρωπε')
'ἄνθρωπε'
>>> add_necessary_breathing('οίδαμεν')
'οἴδαμεν'

But it won't do it if not necessary:

>>> add_necessary_breathing('οἰ')
'οἰ'
>>> add_necessary_breathing('θεός')
'θεός'

Finally, there are two experimental functions morae and contonation:

>>> morae('γυναικός')
['u', 'mm', 'M']
>>> morae('θεός')
['m', 'M']
>>> morae('λόγος')
['M', 'm']
>>> morae('κύριος')
['U', 'u', 'm']
>>> morae('θεοῦ')
['m', 'Mm']
>>> morae('δοῦλος')
['Mm', 'm']
>>> morae('ἐλήλυθας')
['mM', 'u', 'u']
>>> morae('δὲ')
['m']
>>> morae('τὴν')
['mm']
>>> morae('ὑμᾶς')
['u', 'Mm']
>>> contonation('ἀγαθός')
[3]
>>> contonation('ψυχή')
[2]
>>> contonation('ἀγαθοῦ')
[3]
>>> contonation('νόμος')
[1, 2]
>>> contonation('νόμου')
[1, 2]
>>> contonation('πεῖραι')
[1]
>>> contonation('πείραις')
[1, 2]
>>> contonation('ἄνθρωπε')
[1, 2]
>>> contonation('τὴν')
[]

Accentuation

>>> from greek_accentuation.accentuation import *

The greek_accentuation.accentuation module uses the two modules above to analyze and manipulate the accentuation of Greek words.

get_accent_type will return the type of accent on a word (as tuple of syllable number from end and accent, but you can compare this to constants provided):

>>> get_accent_type('ψυχή') == OXYTONE
True
>>> get_accent_type('ἀγαθοῦ') == PERISPOMENON
True
>>> get_accent_type('νόμος') == PAROXYTONE
True
>>> get_accent_type('πεῖραι') == PROPERISPOMENON
True
>>> get_accent_type('ἄνθρωπε') == PROPAROXYTONE
True

If you want to display the type of accent you can use display_accent_type:

>>> display_accent_type(get_accent_type('ψυχή'))
'oxytone'
>>> display_accent_type(get_accent_type('ἀγαθοῦ'))
'perispomenon'
>>> display_accent_type(get_accent_type('νόμος'))
'paroxytone'
>>> display_accent_type(get_accent_type('πεῖραι'))
'properispomenon'
>>> display_accent_type(get_accent_type('ἄνθρωπε'))
'proparoxytone'

syllable_add_accent adds the given accent to a syllable:

>>> syllable_add_accent('κος', ACUTE)
'κός'
>>> syllable_add_accent('ος', ACUTE)
'ός'
>>> syllable_add_accent('ου', CIRCUMFLEX)
'οῦ'
>>> syllable_add_accent('φως', CIRCUMFLEX)
'φῶς'
>>> make_oxytone('θεος')
'θεός'

This is the same as:

>>> add_accent(syllabify('θεος'), OXYTONE)
'θεός'

The module also provides:

>>> make_paroxytone('λογος')
'λόγος'
>>> make_proparoxytone('κυριος')
'κύριος'
>>> make_perispomenon('θεου')
'θεοῦ'
>>> make_properispomenon('δουλος')
'δοῦλος'

If a perispomenon or properispomenon are not possible the respective functions will place an acute instead:

>>> make_perispomenon('λογος')
'λογός'
>>> make_properispomenon('λογος')
'λόγος'

Given a syllabification, possible_accentuations will give the possible accentuations given the general rules of Greek accentuation:

>>> s = syllabify('εγινωσκου')
>>> for accent_class in possible_accentuations(s):
...     print(add_accent(s, accent_class))
εγινωσκού
εγινωσκοῦ
εγινώσκου

If vowels of unmarked length are to be treated as short, set default_short=True:

>>> s = syllabify('κυριος')
>>> for accent_class in possible_accentuations(s):
...     print(add_accent(s, accent_class))
κυριός
κυρίος
κυρῖος
κύριος
>>> s = syllabify('κυριος')
>>> for accent_class in possible_accentuations(s, default_short=True):
...     print(add_accent(s, accent_class))
κυριός
κυρίος
κύριος
>>> s = syllabify('ὀνομα')
>>> for accent_class in possible_accentuations(s):
...     print(add_accent(s, accent_class))
ὀνομά
ὀνομᾶ
ὀνόμα
ὄνομα
>>> s = syllabify('ὀνομα')
>>> for accent_class in possible_accentuations(s, default_short=True):
...     print(add_accent(s, accent_class))
ὀνομά
ὀνόμα
ὄνομα
>>> s = syllabify('ἐληλυθας')
>>> for accent_class in possible_accentuations(s):
...     print(add_accent(s, accent_class))
ἐληλυθάς
ἐληλυθᾶς
ἐληλύθας
ἐληλῦθας
ἐλήλυθας
>>> s = syllabify('ἐληλυθας')
>>> for accent_class in possible_accentuations(s, default_short=True):
...     print(add_accent(s, accent_class))
ἐληλυθάς
ἐληλύθας
ἐλήλυθας

The recessive function will find the most recessive possible accent:

>>> recessive('εγινωσκον')
'εγίνωσκον'
>>> recessive('εγινωσκου')
'εγινώσκου'
>>> strip_length(recessive('δεικνυς'))
'δεῖκνυς'
>>> strip_length(recessive('δεικνῠς'))
'δεῖκνυς'
>>> strip_length(recessive('δεικνῡς'))
'δείκνυς'

You can place a "wall" | past which the accent will not recede:

>>> recessive('εἰσηλθον')
'εἴσηλθον'
>>> recessive('εἰσ|ηλθον')
'εἰσῆλθον'

The on_penult function will attempt to place the accent on the penult:

>>> on_penult('φωνησαι')
'φωνῆσαι'
>>> on_penult('ἀπο|λυσαι')
'ἀπολῦσαι'
>>> on_penult('πιασαι', default_short=True)
'πιάσαι'

If the word only has one syllable, it will fall back to an oxytone:

>>> on_penult('δος')
'δός'

The persistent function will try to persist the accent from the given form:

>>> persistent('ἀνθρωπος', 'ἄνθρωπος')
'ἄνθρωπος'
>>> persistent('ἀνθρωπου', 'ἄνθρωπος')
'ἀνθρώπου'
>>> persistent('καταβαινον', 'καταβαίνων')
'καταβαῖνον'