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')
⎾ building text with 3 words @ 2024-08-06 20:04:16,133
│ ⎾ tokenizing @ 2024-08-06 20:04:16,135
│ ⎿ 0 seconds @ 2024-08-06 20:04:16,147
│ ⎾ building stanzas @ 2024-08-06 20:04:16,148
│ │ iterating stanzas:   0%|          | 0/1 [00:00<?, ?it/s]│ │ iterating stanzas: 100%|██████████| 1/1 [00:00<00:00,  2.07it/s]│ │ iterating stanzas: 100%|██████████| 1/1 [00:00<00:00,  2.06it/s]
│ ⎿ 0.5 seconds @ 2024-08-06 20:04:16,660
⎿ 0.5 seconds @ 2024-08-06 20:04:16,660

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.
""")
⎾ building text with 104 words @ 2024-08-06 20:04:16,664
│ ⎾ tokenizing @ 2024-08-06 20:04:16,664
│ ⎿ 0 seconds @ 2024-08-06 20:04:16,666
│ ⎾ building stanzas @ 2024-08-06 20:04:16,666
│ │ iterating stanzas:   0%|          | 0/1 [00:00<?, ?it/s]│ │ iterating stanzas: 100%|██████████| 1/1 [00:01<00:00,  1.12s/it]│ │ iterating stanzas: 100%|██████████| 1/1 [00:01<00:00,  1.12s/it]
│ ⎿ 1.1 seconds @ 2024-08-06 20:04:17,786
⎿ 1.1 seconds @ 2024-08-06 20:04:17,786

Examining texts

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

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

195 rows × 7 columns

Can also look at particular lines:

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

15 rows × 7 columns

Parsing texts

Run the parsing command:

sonnet.parse()
⎾ parsing text Text() @ 2024-08-06 20:04:17,828
│ ⎾ parsing 14 lines [5x] @ 2024-08-06 20:04:17,829
│ │ parsing [5x]:   0%|          | 0/14 [00:00<?, ?it/s]│ │ stanza 01, line 01: those HO urs THAT with GEN tle WORK did FRAME     :   0%|          | 0/14 [00:00<?, ?it/s]│ │ stanza 01, line 01: those HO urs THAT with GEN tle WORK did FRAME     :   7%|▋         | 1/14 [00:00<00:09,  1.39it/s]│ │ stanza 01, line 02: the LO vely GAZE where E very EYE doth DWELL      :   7%|▋         | 1/14 [00:00<00:09,  1.39it/s]│ │ stanza 01, line 03: will PLAY the TY rants TO the VE ry SAME          :   7%|▋         | 1/14 [00:00<00:09,  1.39it/s]│ │ stanza 01, line 04: and THAT un FAIR which FAIR ly DOTH ex CEL        :   7%|▋         | 1/14 [00:01<00:09,  1.39it/s]│ │ stanza 01, line 04: and THAT un FAIR which FAIR ly DOTH ex CEL        :  29%|██▊       | 4/14 [00:01<00:02,  4.32it/s]│ │ stanza 01, line 05: for NE ver RES ting TIME leads SUM mer ON         :  29%|██▊       | 4/14 [00:01<00:02,  4.32it/s]│ │ stanza 01, line 06: to HI deo.us WIN ter AND con FOUNDS him.there     :  29%|██▊       | 4/14 [00:01<00:02,  4.32it/s]│ │ stanza 01, line 07: sap CHECKED with FROST and LUS ty LEAVES quite GON:  29%|██▊       | 4/14 [00:01<00:02,  4.32it/s]│ │ stanza 01, line 08: BEA uty.o'er SNOWED and BA reness E very WHERE    :  29%|██▊       | 4/14 [00:01<00:02,  4.32it/s]│ │ stanza 01, line 09: THEN were.not SUM mer's DIS til LA tion LEFT      :  29%|██▊       | 4/14 [00:01<00:02,  4.32it/s]│ │ stanza 01, line 10: a LI quid PRI soner PENT in WALLS of GLASS        :  29%|██▊       | 4/14 [00:01<00:02,  4.32it/s]│ │ stanza 01, line 11: BEA uty's EF.FECT with BEA uty WERE be REFT       :  29%|██▊       | 4/14 [00:01<00:02,  4.32it/s]│ │ stanza 01, line 12: nor IT nor NO re MEM brance WHAT it.was           :  29%|██▊       | 4/14 [00:01<00:02,  4.32it/s]│ │ stanza 01, line 13: but FLO wers.dis TILL'D though THEY with WIN ter M:  29%|██▊       | 4/14 [00:01<00:02,  4.32it/s]│ │ stanza 01, line 14: LEESE but.their SHOW their SUBS tance STILL lives :  29%|██▊       | 4/14 [00:01<00:02,  4.32it/s]│ │ stanza 01, line 14: LEESE but.their SHOW their SUBS tance STILL lives : 100%|██████████| 14/14 [00:01<00:00, 12.50it/s]
│ ⎿ 1.1 seconds @ 2024-08-06 20:04:18,951
⎿ 1.1 seconds @ 2024-08-06 20:04:18,952
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 2 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 2 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 1 0 10 8 0 0 0 0 0 0 0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
3 Will play the tyrants to the very same 1 will PLAY the TY rants TO the VE ry SAME -+-+-+-+-+ -+-+---+-+ 1 1 0 10 8 0 0 1 0 0 1 1 0.000000 0.000000 0.100000 0.000000 0.000000 0.100000 0.100000
4 And that unfair which fairly doth excel; 1 and THAT un FAIR which FAIR ly DOTH ex CEL -+-+-+-+-+ -+-+-+---+ 1 1 0 10 7 0 0 1 0 0 1 1 0.000000 0.000000 0.100000 0.000000 0.000000 0.100000 0.100000
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
13 But flowers distill'd, though they with winter meet, 1 but FLO wers.dis TILL'D though THEY with WIN ter MEET -+--+-+-+-+ -+--+-+-+-+ 2 4 0 11 8 0 0 0 2 0 2 2 0.000000 0.000000 0.000000 0.181818 0.000000 0.181818 0.181818
2 but FLO wers DIS.TILL'D though THEY with WIN ter MEET -+-++-+-+-+ -+--+-+-+-+ 2 4 0 11 8 0 0 1 0 1 2 2 0.000000 0.000000 0.090909 0.000000 0.090909 0.181818 0.181818
3 but FLO.WERS dis TILL'D though THEY with WIN ter MEET -++-+-+-+-+ -+--+-+-+-+ 2 4 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 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 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

28 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. Will play the tyrants to the very same
  4. And that unfair which fairly doth excel;
  5. For never-resting time leads summer on
  6. To hideous winter, and confounds him there;
  7. Sap checked with frost, and lusty leaves quite gone,
  8. Beauty o'er-snowed and bareness every where:
  9. Then were not summer's distillation left,
  10. A liquid prisoner pent in walls of glass,
  11. Beauty's effect with beauty were bereft,
  12. Nor it, nor no remembrance what it was:
  13. But flowers distill'd, though they with winter meet,
  14. Leese but their show; their substance still lives sweet.

Saving parse output

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