# setup
import prosodic
# load sonnets
= prosodic.Text('https://raw.githubusercontent.com/quadrismegistus/prosodic/develop/corpora/corppoetry_en/en.shakespeare.txt') sonnets
Examples
Comparing Shakespeare’s sonnets
Loading text
Parsing text
# parse sonnets beforehand if customizing
sonnets.parse()
# the parses are here
sonnets.parses
parse_score | parse_ambig | parse_is_bounded | parse_num_sylls | parse_num_words | *w_peak | *w_stress | *s_unstress | *unres_across | *unres_within | *total_sylls | *total | *w_peak_norm | *w_stress_norm | *s_unstress_norm | *unres_across_norm | *unres_within_norm | *total_sylls_norm | *total_norm | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
stanza_num | line_num | line_txt | parse_rank | parse_txt | parse_meter | parse_stress | |||||||||||||||||||
1 | 1 | FROM fairest creatures we desire increase, | 1 | from FAI rest CREA tures WE de SIRE in CREASE | -+-+-+-+-+ | -+-+-+-+-+ | 0 | 0 | 10 | 6 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | |
2 | from FAI rest CREA tures WE de SI re IN crease | -+-+-+-+-+- | -+-+-+-+-++ | 1 | 0 | 11 | 6 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0.000000 | 0.090909 | 0.000000 | 0.000000 | 0.000000 | 0.090909 | 0.090909 | ||||
3 | from FAI rest CREA tures WE de SI re IN.CREASE | -+-+-+-+-++ | -+-+-+-+-++ | 1 | 0 | 11 | 6 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.090909 | 0.090909 | 0.090909 | ||||
4 | from FAI rest CREA tures WE de SI re.in CREASE | -+-+-+-+--+ | -+-+-+-+--+ | 2 | 0 | 11 | 6 | 0 | 0 | 0 | 2 | 0 | 2 | 2 | 0.000000 | 0.000000 | 0.000000 | 0.181818 | 0.000000 | 0.181818 | 0.181818 | ||||
2 | That thereby beauty's rose might never die, | 1 | that THE reby BEA uty's ROSE might NE ver DIE | -+-+-+-+-+ | -+++-+-+-+ | 1 | 0 | 10 | 7 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0.000000 | 0.100000 | 0.000000 | 0.000000 | 0.000000 | 0.100000 | 0.100000 | ||
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
154 | 14 | Love's fire heats water, water cools not love. | 2 | love's FI re HEATS wa.ter WA ter COOLS not LOVE | -+-+--+-+-+ | ++-++-+-+-+ | 4 | 0 | 11 | 8 | 1 | 2 | 0 | 0 | 1 | 3 | 4 | 0.090909 | 0.181818 | 0.000000 | 0.000000 | 0.090909 | 0.272727 | 0.363636 | |
3 | love's FI.RE heats WA ter WA ter COOLS not LOVE | -++-+-+-+-+ | ++-++-+-+-+ | 4 | 0 | 11 | 8 | 0 | 2 | 1 | 0 | 1 | 3 | 4 | 0.000000 | 0.181818 | 0.090909 | 0.000000 | 0.090909 | 0.272727 | 0.363636 | ||||
4 | LOVE'S fire HEATS wa.ter WA ter COOLS not LOVE | +-+--+-+-+ | ++++-+-+-+ | 4 | 0 | 10 | 8 | 1 | 2 | 0 | 0 | 1 | 3 | 4 | 0.100000 | 0.200000 | 0.000000 | 0.000000 | 0.100000 | 0.300000 | 0.400000 | ||||
5 | LOVE'S.FI re HEATS.WA ter WA ter COOLS not LOVE | ++-++-+-+-+ | ++-++-+-+-+ | 4 | 0 | 11 | 8 | 0 | 0 | 0 | 4 | 0 | 4 | 4 | 0.000000 | 0.000000 | 0.000000 | 0.363636 | 0.000000 | 0.363636 | 0.363636 | ||||
6 | love's FI re HEATS wa TER wa TER cools NOT love | -+-+-+-+-+- | ++-++-+-+++ | 9 | 0 | 11 | 8 | 2 | 5 | 2 | 0 | 0 | 7 | 9 | 0.181818 | 0.454545 | 0.181818 | 0.000000 | 0.000000 | 0.636364 | 0.818182 |
6622 rows × 19 columns
Inspecting parses
By default these parses are shown with one row per parse, but we can also see parses…
By syllable
='syll') sonnets.parses.stats(by
parse_score | parse_is_bounded | meterpos_num_slots | syll_is_stressed | syll_is_heavy | *w_peak | *w_stress | *s_unstress | *unres_across | *unres_within | syll_is_strong | syll_is_weak | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
stanza_num | line_num | line_txt | parse_rank | parse_txt | parse_meter | parse_stress | wordtoken_num | wordtoken_txt | meterpos_num | meterpos_val | syll_num | syll_txt | syll_ipa | meterslot_num | ||||||||||||
1 | 1 | FROM fairest creatures we desire increase, | 1 | from FAI rest CREA tures WE de SIRE in CREASE | -+-+-+-+-+ | -+-+-+-+-+ | 1 | FROM | 1 | w | 1 | FROM | frʌm | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | ||
2 | fairest | 2 | s | 1 | fai | 'fɛ | 2 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | |||||||
3 | w | 2 | rest | rɪst | 3 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | |||||||||
3 | creatures | 4 | s | 1 | crea | 'kriː | 4 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | |||||||
5 | w | 2 | tures | ʧɛːz | 5 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | |||||||||
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
154 | 14 | Love's fire heats water, water cools not love. | 6 | love's FI re HEATS wa TER wa TER cools NOT love | -+-+-+-+-+- | ++-++-+-+++ | 6 | water | 7 | w | 1 | wa | 'wɔː | 7 | 9 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 1 | 0 |
8 | s | 2 | ter | tɛː | 8 | 9 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | |||||||||
7 | cools | 9 | w | 1 | cools | 'kuːlz | 9 | 9 | 0 | 1 | 1 | 1 | 0 | 1 | 0 | 0 | 0 | |||||||||
8 | not | 10 | s | 1 | not | 'nɑt | 10 | 9 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | |||||||||
9 | love | 11 | w | 1 | love | 'lʌv | 11 | 9 | 0 | 1 | 1 | 1 | 0 | 1 | 0 | 0 | 0 |
67752 rows × 12 columns
By line
='line') sonnets.parses.stats(by
parse_score | parse_is_bounded | parse_num_sylls | parse_num_words | *w_peak | *w_stress | *s_unstress | *unres_across | *unres_within | *total_sylls | *total | *w_peak_norm | *w_stress_norm | *s_unstress_norm | *unres_across_norm | *unres_within_norm | *total_sylls_norm | *total_norm | |||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
stanza_num | line_num | line_txt | ||||||||||||||||||
1 | 1 | FROM fairest creatures we desire increase, | 1.000000 | 0.0 | 10.750000 | 6.0 | 0.000000 | 0.250000 | 0.000000 | 0.50000 | 0.250000 | 1.000000 | 1.000000 | 0.000000 | 0.022727 | 0.000000 | 0.045455 | 0.022727 | 0.090909 | 0.090909 |
2 | That thereby beauty's rose might never die, | 1.000000 | 0.0 | 10.000000 | 7.0 | 0.000000 | 1.000000 | 0.000000 | 0.00000 | 0.000000 | 1.000000 | 1.000000 | 0.000000 | 0.100000 | 0.000000 | 0.000000 | 0.000000 | 0.100000 | 0.100000 | |
3 | But as the riper should by time decease, | 1.000000 | 0.0 | 10.000000 | 8.0 | 0.000000 | 0.000000 | 1.000000 | 0.00000 | 0.000000 | 1.000000 | 1.000000 | 0.000000 | 0.000000 | 0.100000 | 0.000000 | 0.000000 | 0.100000 | 0.100000 | |
4 | His tender heir might bear his memory: | 1.000000 | 0.0 | 10.000000 | 7.0 | 0.000000 | 0.000000 | 0.666667 | 0.00000 | 0.333333 | 1.000000 | 1.000000 | 0.000000 | 0.000000 | 0.066667 | 0.000000 | 0.033333 | 0.100000 | 0.100000 | |
5 | But thou, contracted to thine own bright eyes, | 2.250000 | 0.0 | 10.000000 | 8.0 | 0.000000 | 0.750000 | 1.000000 | 0.50000 | 0.000000 | 2.250000 | 2.250000 | 0.000000 | 0.075000 | 0.100000 | 0.050000 | 0.000000 | 0.225000 | 0.225000 | |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
154 | 10 | Which from Love's fire took heat perpetual, | 5.782609 | 0.0 | 10.695652 | 7.0 | 0.434783 | 1.391304 | 1.304348 | 1.73913 | 0.913043 | 5.347826 | 5.782609 | 0.040711 | 0.133202 | 0.123320 | 0.158103 | 0.085375 | 0.500000 | 0.540711 |
11 | Growing a bath and healthful remedy | 4.500000 | 0.0 | 10.000000 | 6.0 | 0.500000 | 0.750000 | 1.875000 | 0.75000 | 0.625000 | 3.625000 | 4.500000 | 0.050000 | 0.075000 | 0.187500 | 0.075000 | 0.062500 | 0.362500 | 0.450000 | |
12 | For men diseased; but I, my mistress' thrall, | 0.000000 | 0.0 | 10.000000 | 8.0 | 0.000000 | 0.000000 | 0.000000 | 0.00000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | |
13 | Came there for cure, and this by that I prove, | 1.000000 | 0.0 | 10.000000 | 10.0 | 0.000000 | 0.000000 | 1.000000 | 0.00000 | 0.000000 | 1.000000 | 1.000000 | 0.000000 | 0.000000 | 0.100000 | 0.000000 | 0.000000 | 0.100000 | 0.100000 | |
14 | Love's fire heats water, water cools not love. | 4.666667 | 0.0 | 10.833333 | 8.0 | 0.666667 | 2.000000 | 0.500000 | 1.00000 | 0.500000 | 3.833333 | 4.666667 | 0.062121 | 0.184848 | 0.045455 | 0.090909 | 0.046970 | 0.353030 | 0.430303 |
2155 rows × 18 columns
By stanza
='stanza') sonnets.parses.stats(by
parse_score | parse_is_bounded | parse_num_sylls | parse_num_words | *w_peak | *w_stress | *s_unstress | *unres_across | *unres_within | *total_sylls | *total | *w_peak_norm | *w_stress_norm | *s_unstress_norm | *unres_across_norm | *unres_within_norm | *total_sylls_norm | *total_norm | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
stanza_num | ||||||||||||||||||
1 | 3.102941 | 0.0 | 10.411765 | 7.838235 | 0.102941 | 0.852941 | 0.779412 | 1.029412 | 0.338235 | 2.823529 | 3.102941 | 0.009759 | 0.082086 | 0.074599 | 0.098128 | 0.032086 | 0.270187 | 0.296658 |
2 | 2.536585 | 0.0 | 10.000000 | 7.829268 | 0.146341 | 0.414634 | 0.829268 | 1.073171 | 0.073171 | 2.390244 | 2.536585 | 0.014634 | 0.041463 | 0.082927 | 0.107317 | 0.007317 | 0.239024 | 0.253659 |
3 | 2.564516 | 0.0 | 10.145161 | 8.048387 | 0.129032 | 0.403226 | 0.500000 | 1.354839 | 0.177419 | 2.403226 | 2.564516 | 0.012317 | 0.039589 | 0.049560 | 0.133724 | 0.017302 | 0.237243 | 0.252493 |
4 | 3.476923 | 0.0 | 10.000000 | 7.138462 | 0.261538 | 0.615385 | 1.123077 | 1.046154 | 0.430769 | 3.000000 | 3.476923 | 0.026154 | 0.061538 | 0.112308 | 0.104615 | 0.043077 | 0.300000 | 0.347692 |
5 | 1.636364 | 0.0 | 10.393939 | 7.303030 | 0.030303 | 0.242424 | 0.666667 | 0.484848 | 0.212121 | 1.575758 | 1.636364 | 0.002755 | 0.023967 | 0.063085 | 0.046832 | 0.019284 | 0.150413 | 0.155923 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
150 | 2.568966 | 0.0 | 10.258621 | 8.379310 | 0.103448 | 0.448276 | 0.672414 | 1.137931 | 0.206897 | 2.465517 | 2.568966 | 0.010057 | 0.044540 | 0.065073 | 0.112644 | 0.019253 | 0.241510 | 0.251567 |
151 | 3.346939 | 0.0 | 10.367347 | 8.387755 | 0.102041 | 1.040816 | 0.346939 | 1.673469 | 0.183673 | 2.795918 | 3.346939 | 0.009833 | 0.097959 | 0.033766 | 0.158071 | 0.017625 | 0.265863 | 0.317254 |
152 | 1.681818 | 0.0 | 10.454545 | 8.727273 | 0.000000 | 0.636364 | 0.272727 | 0.636364 | 0.136364 | 1.636364 | 1.681818 | 0.000000 | 0.059504 | 0.025207 | 0.059504 | 0.013223 | 0.153306 | 0.157438 |
153 | 3.021277 | 0.0 | 10.361702 | 8.106383 | 0.191489 | 0.702128 | 0.382979 | 1.531915 | 0.212766 | 2.659574 | 3.021277 | 0.018182 | 0.067311 | 0.037137 | 0.147002 | 0.019536 | 0.255513 | 0.289168 |
154 | 3.779412 | 0.0 | 10.294118 | 7.338235 | 0.264706 | 0.897059 | 1.073529 | 1.088235 | 0.455882 | 3.455882 | 3.779412 | 0.025134 | 0.086690 | 0.104531 | 0.103654 | 0.043182 | 0.332308 | 0.363191 |
154 rows × 18 columns
Results
# so we can groupby stanza and average
= sonnets.parses.stats(by='stanza').sort_values('parse_score')
df df
parse_score | parse_is_bounded | parse_num_sylls | parse_num_words | *w_peak | *w_stress | *s_unstress | *unres_across | *unres_within | *total_sylls | *total | *w_peak_norm | *w_stress_norm | *s_unstress_norm | *unres_across_norm | *unres_within_norm | *total_sylls_norm | *total_norm | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
stanza_num | ||||||||||||||||||
90 | 0.400000 | 0.0 | 10.300000 | 8.950000 | 0.000000 | 0.150000 | 0.150000 | 0.100000 | 0.000000 | 0.400000 | 0.400000 | 0.000000 | 0.015000 | 0.014545 | 0.010000 | 0.000000 | 0.039545 | 0.039545 |
74 | 0.814815 | 0.0 | 10.111111 | 8.148148 | 0.000000 | 0.037037 | 0.370370 | 0.296296 | 0.111111 | 0.814815 | 0.814815 | 0.000000 | 0.004115 | 0.035690 | 0.029106 | 0.010438 | 0.079349 | 0.079349 |
26 | 1.320000 | 0.0 | 10.440000 | 8.480000 | 0.000000 | 0.280000 | 0.480000 | 0.480000 | 0.080000 | 1.320000 | 1.320000 | 0.000000 | 0.026545 | 0.046182 | 0.045818 | 0.008000 | 0.126545 | 0.126545 |
81 | 1.333333 | 0.0 | 10.133333 | 8.133333 | 0.033333 | 0.300000 | 0.300000 | 0.533333 | 0.166667 | 1.300000 | 1.333333 | 0.003030 | 0.029832 | 0.030000 | 0.053468 | 0.016364 | 0.129663 | 0.132694 |
43 | 1.366667 | 0.0 | 10.000000 | 8.633333 | 0.000000 | 0.433333 | 0.266667 | 0.666667 | 0.000000 | 1.366667 | 1.366667 | 0.000000 | 0.043401 | 0.026667 | 0.067407 | 0.000000 | 0.137475 | 0.137475 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
17 | 3.577778 | 0.0 | 9.866667 | 8.400000 | 0.200000 | 0.711111 | 0.844444 | 1.733333 | 0.088889 | 3.222222 | 3.577778 | 0.021481 | 0.074119 | 0.089843 | 0.182806 | 0.009012 | 0.338743 | 0.377262 |
95 | 3.770492 | 0.0 | 10.245902 | 7.442623 | 0.163934 | 0.836066 | 0.836066 | 1.573770 | 0.360656 | 3.426230 | 3.770492 | 0.015350 | 0.083905 | 0.078722 | 0.155754 | 0.033681 | 0.334261 | 0.367412 |
154 | 3.779412 | 0.0 | 10.294118 | 7.338235 | 0.264706 | 0.897059 | 1.073529 | 1.088235 | 0.455882 | 3.455882 | 3.779412 | 0.025134 | 0.086690 | 0.104531 | 0.103654 | 0.043182 | 0.332308 | 0.363191 |
104 | 3.851064 | 0.0 | 10.085106 | 8.255319 | 0.063830 | 1.148936 | 0.510638 | 1.872340 | 0.255319 | 3.617021 | 3.851064 | 0.006383 | 0.113926 | 0.049903 | 0.186074 | 0.024952 | 0.358027 | 0.381238 |
27 | 4.073171 | 0.0 | 10.024390 | 8.463415 | 0.000000 | 1.487805 | 0.292683 | 2.243902 | 0.048780 | 3.609756 | 4.073171 | 0.000000 | 0.148780 | 0.029268 | 0.224390 | 0.004878 | 0.360976 | 0.407317 |
154 rows × 18 columns
Examining results
Best sonnet?
# now we can look at "best" sonnet
sonnets.stanza84
- Which should example where your equal grew.
- But he that writes of you, if he can tell
- That you are you, so dignifies his story,
- Not making worse what nature made so clear,
- Who is it that says most? which can say more
- In whose confine immured is the store
- Being fond on praise, which makes your praises worse.
- Let him but copy what in you is writ,
- You to your beauteous blessings add a curse,
- And such a counterpart shall fame his wit,
- That to his subject lends not some small glory;
- Than this rich praise, that you alone are you?
- Lean penury within that pen doth dwell
- Making his style admired every where.
Worst sonnet?
# now we can look at "worst" sonnet
sonnets.stanza51
- From where thou art why should I haste me thence?
- Towards thee I'll run, and give him leave to go.
- Thus can my love excuse the slow offence
- When swift extremity can seem but slow?
- Then should I spur, though mounted on the wind;
- Till I return, of posting is no need.
- But love, for love, thus shall excuse my jade;
- Since from thee going he went wilful-slow,
- Of my dull bearer when from thee I speed:
- O, what excuse will my poor beast then find,
- Therefore desire of perfect'st love being made,
- Shall neigh--no dull flesh--in his fiery race;
- In winged speed no motion shall I know:
- Then can no horse with my desire keep pace;