Skip to content

quadrismegistus/cadence

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Cadence

A rhythm analysis toolkit, gathering multiple parsing engines:

  • Prosodic for fast English and Finnish metrical scansion.
    • Cadence now uses its own metrical parser, a rewritten version of Prosodic's.
  • Stanza for syntactic parsing.
  • MetricalTree for sentence rhythm/phrasal stress assignment based on Stanza's syntactic parses.

Quickstart

Install

1. Install python package

# install from pypi
pip install -U cadences    # "cadence" was taken :-/

# or from github very latest
pip install -U git+https://github.com/quadrismegistus/cadence

2. Insteall espeak (TTS)

Install espeak, free TTS software, to 'sound out' unknown words. See here for all downloads.

Load cadence

# this should work following installation
import cadence as cd

Load texts

# verse
sonnetXIV = """
How can I then return in happy plight,
That am debarred the benefit of rest?
When dayโ€™s oppression is not eased by night,
But day by night and night by day oppressed,
And each, though enemies to eitherโ€™s reign,
Do in consent shake hands to torture me,
The one by toil, the other to complain
How far I toil, still farther off from thee.
I tell the day, to please him thou art bright,
And dost him grace when clouds do blot the heaven:
So flatter I the swart-complexiond night,
When sparkling stars twire not thou gildst the even.
But day doth daily draw my sorrows longer,
And night doth nightly make griefโ€™s length seem stronger.
"""

# prose
melville="""Is it that by its indefiniteness it shadows forth the
heartless voids and immensities of the universe, and thus stabs us
from behind with the thought of annihilation, when beholding
the white depths of the milky way? Or is it, that as in
essence whiteness is not so much a colour as the visible absence
of colour; and at the same time the concrete of all colours;
is it for these reasons that there is such a dumb blankness,
full of meaning, in a wide landscape of snows: a colourless,
all-colour of atheism from which we shrink?"""
# These are identical
sonnet = cd.Verse(sonnetXIV)
sonnet = cd.Text(sonnetXIV, linebreaks=True, phrasebreaks=False)

# So are these
prose = cd.Prose(melville)
prose = cd.Text(melville, linebreaks=False, phrasebreaks=True)

Available features

# Tokenize
sonnet.words()
word_ispunc
para_i sent_i sentpart_i line_i word_i word_str
1 1 1 1 1 How 0
2 can 0
3 I 0
4 then 0
5 return 0
... ... ... ... ... ...
4 17 14 15 grief's 0
16 length 0
17 seem 0
18 stronger 0
19 . 1

135 rows ร— 1 columns

# Syllabify
sonnet.sylls()
prom_strength prom_stress prom_weight word_isfunc word_ispunc word_nsyll
para_i sent_i sentpart_i line_i word_i word_str word_tok word_ipa_i word_ipa syll_i syll_str syll_ipa syll_stress syll_weight
1 1 1 1 1 How how 1 haสŠ 1 How haสŠ U H NaN 0.0 1.0 1.0 0 1
2 can can 1 kรฆn 1 can kรฆn U H NaN 0.0 1.0 1.0 0 1
3 I i 1 'aษช 1 I 'aษช P H 1.0 1.0 1.0 0.0 0 1
2 aษช 1 I aษช U H 0.0 0.0 1.0 1.0 0 1
4 then then 1 'รฐษ›n 1 then 'รฐษ›n P H 1.0 1.0 1.0 0.0 0 1
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
4 17 14 16 length length 1 'lษ›ล‹kฮธ 1 length 'lษ›ล‹kฮธ P H NaN 1.0 1.0 0.0 0 1
17 seem seem 1 'siหm 1 seem 'siหm P H NaN 1.0 1.0 0.0 0 1
18 stronger stronger 1 'strษ”หล‹.ษ›ห 1 stron 'strษ”หล‹ P H 1.0 1.0 1.0 0.0 0 2
2 ger ษ›ห U L 0.0 0.0 0.0 0.0 0 2
19 . 0 0 . NaN NaN NaN NaN NaN NaN 1 0

186 rows ร— 6 columns

# Syntax-parse
sonnet.syntax()
dep_head dep_type pos_case pos_definite pos_degree pos_gender pos_mood pos_number pos_person pos_polarity pos_poss pos_prontype pos_tense pos_upos pos_verbform pos_voice pos_xpos word_depth
para_i sent_i word_i word_str
1 1 1 How 5 advmod Int ADV WRB 4
2 can 5 aux AUX Fin MD 4
3 I 5 nsubj Nom Sing 1 Prs PRON PRP 5
4 then 5 advmod Dem ADV RB 5
5 return 0 root VERB Inf VB 5
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
4 15 grief's 16 compound Plur NOUN NNS 8
16 length 14 obj Sing NOUN NN 8
17 seem 14 xcomp VERB Inf VB 10
18 stronger 17 xcomp Cmp ADJ JJR 12
19 . 5 punct PUNCT . 3

135 rows ร— 18 columns

Sentence-level information from MetricalTree

# Show sentences
sentence = sonnet.sent(1)
sentence.mtree()

svg

# Show sentence tree for prose
prose.sent(1).mtree()

svg

# Stress grid of sentence inferred from syntactic tree
sentence.grid()

png

Metrical parsing

# Parse lines (verse)
sonnet.parse()

How can I then return in happy plight,

That am debarred the benefit of rest?

When day's oppression is not eased by night,

But day by night and night by day oppressed,

And each, though enemies to either's reign,

Do in consent shake hands to torture me,

The one by toil, the other to complain

How far I toil, still farther off from thee.

I tell the day, to please him thou art bright,

And dost him grace when clouds do blot the heaven:

So flatter I the swart- complexiond night,

When sparkling stars twire not thou gildst the even.

But day doth daily draw my sorrows longer,

And night doth nightly make grief's length seem stronger.

*total *s_unstressed *unres_across *unres_within *w_peak *w_stressed dep_head dep_type mtree_ishead num_parses pos_case pos_definite pos_degree pos_gender pos_mood pos_number pos_person pos_polarity pos_poss pos_prontype pos_tense pos_upos pos_verbform pos_voice pos_xpos prom_lstress prom_pstrength prom_pstress prom_strength prom_stress prom_tstress prom_weight word_depth word_isfunc word_ispunc word_nsyll
para_i unit_i parse_rank is_troch parse_i parse parse_str sent_i sentpart_i line_i combo_i slot_i slot_meter syll_str_parse word_i word_str word_tok word_ipa_i word_ipa syll_i syll_str syll_ipa syll_stress syll_weight
1 1 1 0 1 wwSSwSwSwS ๐–ง๐—ˆ๐— ๐–ผ๐–บ๐—‡ ๐—œ ๐™ฉ๐™๐™š๐™ฃ ๐—‹๐–พ๐˜๐˜‚๐—ฟ๐—ป ๐—‚๐—‡ ๐—ต๐—ฎ๐—ฝ๐—‰๐—’ ๐—ฝ๐—น๐—ถ๐—ด๐—ต๐˜, 1 1 1 1 1 w ๐–ง๐—ˆ๐— 1 How how 1 haสŠ 1 How haสŠ U H 0.0 0.0 0.0 0.0 0.0 0.0 5 advmod NaN 4 Int ADV WRB 0.0 NaN 0.0 NaN 0.0 0.000000 1.0 4 1.0 0 1
2 w ๐–ผ๐–บ๐—‡ 2 can can 1 kรฆn 1 can kรฆn U H 0.0 0.0 0.0 0.0 0.0 0.0 5 aux NaN 4 AUX Fin MD 0.0 NaN 0.0 NaN 0.0 0.333333 1.0 4 1.0 0 1
3 s ๐—œ 3 I i 1 'aษช 1 I 'aษช P H 0.0 0.0 0.0 0.0 0.0 0.0 5 nsubj NaN 4 Nom Sing 1 Prs PRON PRP 0.0 NaN 0.0 1.0 1.0 0.000000 1.0 5 0.0 0 1
4 s ๐™ฉ๐™๐™š๐™ฃ 4 then then 1 'รฐษ›n 1 then 'รฐษ›n P H 1.0 0.0 1.0 0.0 0.0 0.0 5 advmod NaN 4 Dem ADV RB 0.0 NaN 0.0 1.0 1.0 0.000000 1.0 5 0.0 0 1
5 w ๐—‹๐–พ 5 return return 1 rษช.'tษ›หn 1 re rษช U L 0.0 0.0 0.0 0.0 0.0 0.0 0 root NaN 4 VERB Inf VB NaN NaN NaN 0.0 0.0 NaN 0.0 5 0.0 0 2
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
14 2 0 1 wSwSwSSwSSw ๐– ๐—‡๐–ฝ ๐—ป๐—ถ๐—ด๐—ต๐˜ ๐–ฝ๐—ˆ๐—๐— ๐—ป๐—ถ๐—ด๐—ต๐—๐—…๐—’ ๐—บ๐—ฎ๐—ธ๐—ฒ ๐™œ๐™ง๐™ž๐™š๐™›'๐™จ ๐˜ญ๐˜ฆ๐˜ฏ๐˜จ๐˜ต๐˜ฉ ๐˜€๐—ฒ๐—ฒ๐—บ ๐™จ๐™ฉ๐™ง๐™ค๐™ฃ๐—€๐–พ๐—‹. 4 17 14 1 8 w ๐˜ญ๐˜ฆ๐˜ฏ๐˜จ๐˜ต๐˜ฉ 16 length length 1 'lษ›ล‹kฮธ 1 length 'lษ›ล‹kฮธ P H 1.0 0.0 0.0 0.0 0.0 1.0 14 obj NaN 2 Sing NOUN NN 1.0 0.0 0.0 NaN 1.0 0.750000 1.0 8 0.0 0 1
9 s ๐˜€๐—ฒ๐—ฒ๐—บ 17 seem seem 1 'siหm 1 seem 'siหm P H 0.0 0.0 0.0 0.0 0.0 0.0 14 xcomp NaN 2 VERB Inf VB 1.0 0.0 0.0 NaN 1.0 0.750000 1.0 10 0.0 0 1
10 s ๐™จ๐™ฉ๐™ง๐™ค๐™ฃ 18 stronger stronger 1 'strษ”หล‹.ษ›ห 1 stron 'strษ”หล‹ P H 1.0 0.0 1.0 0.0 0.0 0.0 17 xcomp NaN 2 Cmp ADJ JJR 1.0 1.0 1.0 1.0 1.0 1.000000 1.0 12 0.0 0 2
11 w ๐—€๐–พ๐—‹ 18 stronger stronger 1 'strษ”หล‹.ษ›ห 2 ger ษ›ห U L 0.0 0.0 0.0 0.0 0.0 0.0 17 xcomp NaN 2 Cmp ADJ JJR NaN NaN NaN 0.0 0.0 NaN 0.0 12 0.0 0 2
12 NaN . 19 . 0 0 . NaN NaN 0.0 NaN NaN NaN NaN NaN 5 punct NaN 2 PUNCT . NaN NaN NaN NaN NaN NaN NaN 3 NaN 1 0

303 rows ร— 36 columns

# Parse prose
prose.parse()

Is it that by its indefiniteness it shadows forth

the heartless voids and immensities of the universe,

and thus

stabs us from behind with the thought of annihilation,

when beholding the white depths of the milky way?

Or is it,

that as in essence whiteness is not so

much a colour as the visible absence of colour;

and at the same time the concrete of all colours;

is it for these reasons that there is such a dumb blankness,

full of meaning,

in a wide landscape of snows:

a colourless,

all- colour of atheism from which we shrink?

*total *s_unstressed *unres_across *unres_within *w_peak *w_stressed dep_head dep_type mtree_ishead num_parses pos_case pos_definite pos_degree pos_gender pos_mood pos_number pos_person pos_polarity pos_poss pos_prontype pos_tense pos_upos pos_verbform pos_xpos prom_lstress prom_pstrength prom_pstress prom_strength prom_stress prom_tstress prom_weight word_depth word_isfunc word_ispunc word_nsyll
para_i unit_i parse_rank is_troch parse_i parse parse_str sent_i sentpart_i line_i combo_i slot_i slot_meter syll_str_parse word_i word_str word_tok word_ipa_i word_ipa syll_i syll_str syll_ipa syll_stress syll_weight
1 1 1 0 1 wSwwSwSwSwwSSw ๐–จ๐—Œ ๐—ถ๐˜ ๐—๐—๐–บ๐— ๐–ป๐—’ ๐™ž๐™ฉ๐™จ ๐—‚๐—‡๐—ฑ๐—ฒ๐–ฟ๐—‚๐™ฃ๐™ž๐—๐–พ๐—‡๐–พ๐—Œ๐—Œ ๐˜ช๐˜ต ๐˜€๐—ต๐—ฎ๐—ฑ๐—ผ๐˜„๐˜€ ๐˜ง๐˜ฐ๐˜ณ๐˜ต๐˜ฉ 1 1 1 12 1 w ๐–จ๐—Œ 1 Is is 2 ษชz 1 Is ษชz U H 0.0 0.0 0.0 0.0 0.0 0.0 8 aux 0.0 27 Ind Sing 3 Pres AUX Fin VBZ 0.0 NaN 0.0 0.0 0.0 0.666667 1.0 3 1.0 0 1
2 s ๐—ถ๐˜ 2 it it 1 'ษชt 1 it 'ษชt P H 0.0 0.0 0.0 0.0 0.0 0.0 8 nsubj NaN 27 Nom Neut Sing 3 Prs PRON PRP 0.0 NaN 0.0 1.0 1.0 0.333333 1.0 4 0.0 0 1
3 w ๐—๐—๐–บ๐— 3 that that 2 รฐษ™t 1 that รฐษ™t U H 0.0 0.0 0.0 0.0 0.0 0.0 8 mark NaN 27 SCONJ IN 0.0 NaN 0.0 0.0 0.0 0.333333 1.0 4 1.0 0 1
4 w ๐–ป๐—’ 4 by by 1 baษช 1 by baษช U H 0.0 0.0 0.0 0.0 0.0 0.0 6 case NaN 27 ADP IN 0.0 NaN 0.0 NaN 0.0 0.333333 1.0 4 1.0 0 1
5 s ๐™ž๐™ฉ๐™จ 5 its its 1 ษชts 1 its ษชts U H 1.0 1.0 0.0 0.0 0.0 0.0 6 nmod:poss 0.0 27 Neut Sing 3 Yes Prs PRON PRP$ 0.0 0.0 0.0 NaN 0.0 0.333333 1.0 5 1.0 0 1
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
14 8 0 8 wSwwSwSwwSwS ๐–บ๐—…๐—…- ๐—ฐ๐—ผ๐—…๐—ˆ๐—Ž๐—‹ ๐˜ฐ๐˜ง ๐—ฎ๐˜๐—๐–พ๐—ถ๐—Œ๐—† ๐˜ง๐˜ณ๐˜ฐ๐˜ฎ ๐˜„๐—ต๐—ถ๐—ฐ๐—ต ๐—๐–พ ๐˜€๐—ต๐—ฟ๐—ถ๐—ป๐—ธ? 2 11 6 14 10 w ๐˜ง๐˜ณ๐˜ฐ๐˜ฎ 66 from from 1 frสŒm 1 from frสŒm U H 1.0 0.0 1.0 0.0 0.0 0.0 67 case NaN 8 ADP IN 0.0 0.0 0.0 NaN 0.0 0.250000 1.0 13 1.0 0 1
11 s ๐˜„๐—ต๐—ถ๐—ฐ๐—ต 67 which which 1 'wษชสง 1 which 'wษชสง P H 0.0 0.0 0.0 0.0 0.0 0.0 69 obl NaN 8 Rel PRON WDT 0.0 NaN 0.0 1.0 1.0 0.000000 1.0 14 0.0 0 1
12 w ๐—๐–พ 68 we we 2 wiห 1 we wiห U L 0.0 0.0 0.0 0.0 0.0 0.0 69 nsubj NaN 8 Nom Plur 1 Prs PRON PRP 0.0 0.0 0.0 0.0 0.0 0.250000 0.0 14 1.0 0 1
13 s ๐˜€๐—ต๐—ฟ๐—ถ๐—ป๐—ธ 69 shrink shrink 1 'สƒrษชล‹k 1 shrink 'สƒrษชล‹k P H 0.0 0.0 0.0 0.0 0.0 0.0 63 acl:relcl NaN 8 Ind Plur 1 Pres VERB Fin VBP 1.0 1.0 1.0 NaN 1.0 1.000000 1.0 14 0.0 0 1
14 NaN ? 70 ? 0 0 ? NaN NaN 0.0 NaN NaN NaN NaN NaN 3 punct NaN 8 PUNCT . NaN NaN NaN NaN NaN NaN NaN 3 NaN 1 0

1241 rows ร— 35 columns

About

Rhythm analysis toolkit in Python

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published