Getting started

Setup

See installation instructions here.

Usage

To use as a web app, see here. This document covers how to get started using Prosodic in python.

To use within python, load jupyter or ipython:

ipython

Recommended practice is to import with fullname.

import prosodic

Loading texts

You can load a text by a URL or a filename pointing to a text file:

sonnets = prosodic.Text('https://raw.githubusercontent.com/quadrismegistus/prosodic/develop/corpora/corppoetry_en/en.shakespeare.txt')

Or directly by a string:

sonnet = prosodic.Text("""
Those hours, that with gentle work did frame
The lovely gaze where every eye doth dwell,
Will play the tyrants to the very same
And that unfair which fairly doth excel;
For never-resting time leads summer on
To hideous winter, and confounds him there;
Sap checked with frost, and lusty leaves quite gone,
Beauty o’er-snowed and bareness every where:
Then were not summer’s distillation left,
A liquid prisoner pent in walls of glass,
Beauty’s effect with beauty were bereft,
Nor it, nor no remembrance what it was:
But flowers distill’d, though they with winter meet,
Leese but their show; their substance still lives sweet.
""")

Examining texts

Any text when displayed will show the dataframe stored at its .df attribute:

# the sonnet object displays as `sonnet.df`
sonnet
word_num_forms syll_is_stressed syll_is_heavy syll_is_strong syll_is_weak word_is_punc
stanza_num line_num line_txt word_lang wordtoken_num wordtoken_txt wordform_num syll_num syll_txt syll_ipa
1 1 Those hours, that with gentle work did frame en 1 Those 1 1 Those ðoʊz 1 0 1
2 hours 1 1 ho 'aʊ 2 1 1 1 0
2 urs ɛːz 2 0 1 0 1
2 1 hours 'aʊrz 2 1 1
3 , 0 0 0 1
... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
14 Leese but their show; their substance still lives sweet. en 7 substance 1 2 tance stəns 1 0 1 0 1
8 still 1 1 still 'stɪl 1 1 1
9 lives 1 1 lives 'lɪvz 1 1 1
10 sweet 1 1 sweet 'swiːt 1 1 1
11 . 0 0 0 1

195 rows × 6 columns

Can also look at particular lines:

sonnet.line1
word_num_forms syll_is_stressed syll_is_heavy syll_is_strong syll_is_weak word_is_punc
stanza_num line_num line_txt word_lang wordtoken_num wordtoken_txt wordform_num syll_num syll_txt syll_ipa
1 1 Those hours, that with gentle work did frame en 1 Those 1 1 Those ðoʊz 1 0 1
2 hours 1 1 ho 'aʊ 2 1 1 1 0
2 urs ɛːz 2 0 1 0 1
2 1 hours 'aʊrz 2 1 1
3 , 0 0 0 1
... ... ... ... ... ... ... ... ... ... ... ...
6 gentle 1 2 tle təl 1 0 1 0 1
7 work 1 1 work 'wɛːk 1 1 1
8 did 1 1 did dɪd 2 0 1
2 1 did 'dɪd 2 1 1
9 frame 1 1 frame 'freɪm 1 1 1

15 rows × 6 columns

Parsing texts

Run the parsing command:

sonnet.parse()
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 Those hours, that with gentle work did frame 1 those HO urs THAT with GEN tle WORK did FRAME -+-+-+-+-+ -+-+-+-+-+ 0 0 10 8 0 0 0 0 0 0 0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
2 those HOURS that.with GEN tle WORK did FRAME -+--+-+-+ -+--+-+-+ 0 0 9 8 0 0 0 0 0 0 0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
2 The lovely gaze where every eye doth dwell, 1 the LO vely GAZE where E very EYE doth DWELL -+-+-+-+-+ -+-+-+-+-+ 0 0 10 8 0 0 0 0 0 0 0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
2 the LO vely GAZE where E ve.ry EYE doth DWELL -+-+-+--+-+ -+-+-+--+-+ 1 0 11 8 0 0 0 0 1 1 1 0.000000 0.000000 0.000000 0.000000 0.090909 0.090909 0.090909
3 the LO vely GAZE where E.VE ry EYE doth DWELL -+-+-++-+-+ -+-+-+--+-+ 1 0 11 8 0 0 1 0 0 1 1 0.000000 0.000000 0.090909 0.000000 0.000000 0.090909 0.090909
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
13 But flowers distill'd, though they with winter meet, 1 but FLO wers DIS.TILL'D though THEY with WIN ter MEET -+-++-+-+-+ -+--+-+-+-+ 2 0 11 8 0 0 1 0 1 2 2 0.000000 0.000000 0.090909 0.000000 0.090909 0.181818 0.181818
2 but FLO wers.dis TILL'D though THEY with WIN ter MEET -+--+-+-+-+ -+--+-+-+-+ 2 0 11 8 0 0 0 2 0 2 2 0.000000 0.000000 0.000000 0.181818 0.000000 0.181818 0.181818
3 but FLO.WERS dis TILL'D though THEY with WIN ter MEET -++-+-+-+-+ -+--+-+-+-+ 2 0 11 8 0 0 1 0 1 1 2 0.000000 0.000000 0.090909 0.000000 0.090909 0.090909 0.181818
4 but FLO wers DIS till'd THOUGH they.with WIN ter MEET -+-+-+--+-+ -+--+---+-+ 4 0 11 8 1 1 2 0 0 3 4 0.090909 0.090909 0.181818 0.000000 0.000000 0.272727 0.363636
14 Leese but their show; their substance still lives sweet. 1 LEESE but.their SHOW their SUBS tance STILL lives SWEET +--+-+-+-+ +--+-+-+++ 1 0 10 9 0 1 0 0 0 1 1 0.000000 0.100000 0.000000 0.000000 0.000000 0.100000 0.100000

36 rows × 19 columns

The results, a special ParseList object, will be accessible at sonnet.parses. It displays as a dataframe accessible at sonnet.parses.df.

Displaying parsed texts

In a notebook environmnent, the simplest way to view the parse is to to render it.

sonnet.parses.render()
  1. Those hours, that with gentle work did frame
  2. The lovely gaze where every eye doth dwell,
  3. A liquid prisoner pent in walls of glass,
  4. Nor it, nor no remembrance what it was:
  5. Then were not summer's distillation left,
  6. Will play the tyrants to the very same
  7. And that unfair which fairly doth excel;
  8. Leese but their show; their substance still lives sweet.
  9. For never-resting time leads summer on
  10. Sap checked with frost, and lusty leaves quite gone,
  11. But flowers distill'd, though they with winter meet,
  12. To hideous winter, and confounds him there;
  13. Beauty's effect with beauty were bereft,
  14. Beauty o'er-snowed and bareness every where:

Saving parse output

sonnet.parses.df.to_csv('my_parse_output.csv')