Wolfram Language

Open live version

Determine If a Text Is Prose or Poetry

Make a function that determines whether a Shakespearean text is prose or poetry.


code

prose = ExampleData[{"Text", "Hamlet"}];
poetry = ExampleData[{"Text", "ShakespearesSonnets"}];
proseorpoetry = Classify[<| "Prose" -> {prose}, "Poetry" -> {poetry} |>]

how it works

Gather examples of Shakespearean poetry and prose to train a classifier:

prose = ExampleData[{"Text", "Hamlet"}];
poetry = ExampleData[{"Text", "ShakespearesSonnets"}];

Make a classifier function using the training examples:

proseorpoetry = Classify[<| "Prose" -> {prose}, "Poetry" -> {poetry} |>]

Test the classifier on Shakespearean prose not in the training set:

proseorpoetry[ "It did always seem so to us: but now, in the division of the kingdom, it appears not which of the dukes he values most; for equalities are so weighed, that curiosity in neither can make choice of either's moiety."]

Test the classifier on Shakespearean poetry not in the training set:

proseorpoetry[ "Crabbed Age and Youth Cannot live together: Youth is full of pleasance, Age is full of care; Youth like summer morn, Age like winter weather; Youth like summer brave, Age like winter bare: Youth is full of sports, Age's breath is short, Youth is nimble, Age is lame: Youth is hot and bold, Age is weak and cold, Youth is wild, and Age is tame:- Age, I do abhor thee; Youth, I do adore thee; O! my Love, my Love is young! Age, I do defy thee- O sweet shepherd, hie thee, For methinks thou stay'st too long. "]