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.
# install from pypi
pip install -U cadences # "cadence" was taken :-/
# or from github very latest
pip install -U git+https://github.com/quadrismegistus/cadence
Install espeak, free TTS software, to 'sound out' unknown words. See here for all downloads.
-
On Linux, type into the terminal:
apt-get install espeak
-
On Mac:
-
Install homebrew if not already installed.
-
Type into the Terminal app:
brew install espeak
-
-
On Windows: Download and install from http://espeak.sourceforge.net/download.html.
# this should work following installation
import cadence as cd
# 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)
# 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
# Show sentences
sentence = sonnet.sent(1)
sentence.mtree()
# Show sentence tree for prose
prose.sent(1).mtree()
# Stress grid of sentence inferred from syntactic tree
sentence.grid()
# 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