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