Evolution of topics in Romeo & Juliet

Posted by & filed under 3D, App, Art, Book, Computation, Linguistics, Literature.

The actual APP that does some analysis of Shakespeare’s “Romeo and Juliet” is located HERE. Please wait through a potential little load or evaluation times, it is computing! Read below for the explanation of how app works and other ideas on Shakespeare’s data mining.

enter image description here

April 23, 2016 marks 400th anniversary of Shakespeare’s death. Just a few decades of life’s work produced texts that fascinate humanity for already 400 years. This centuries-old fascination tells us Shakespeare’s works highlight the perpetual social and cultural phenomena. And also that Shakespeare is a seldom genius, a true master of the written and spoken word. But have you ever thought that Shakespeare’s texts can be deemed as data? Perhaps Emerging filed of digital humanities can tell us what to read between the lines. Modern technologies can provide a new insight into social networks of characters, semantic, statistical and other properties of corpus that is usually considered of only high artistic value. Is there a pattern in the art? Could you think of data mining analysis or visualizations to apply to Shakespeare’s works?

EXAMPLE: Storyline

Imagine I would like to see in a few quick pictures how the dramatic development of events propagates through a play. I consider “Romeo and Juliet” and download full text as a string (lower-casing all words):

    romeojuliet = ToLowerCase[Import["http://shakespeare.mit.edu/romeo_juliet/full.html"]];

Now I will write a function drama that displays the density of a specific word in a play. It is done by indexing positions of words in the text and then running SmoothKernelDistribution algorithm hidden inside SmoothHistogram function that also plots the density:

    drama[keywords_List] := With[
      {pos = StringPosition[romeojuliet, #][[All, 1]] & /@ keywords},
      SmoothHistogram[pos,
       Frame -> None, BaseStyle -> White,
       PlotLegends -> Placed[keywords, {{.93, .8}}],
       AspectRatio -> 1/3, ImageSize -> 700, PlotTheme -> "Marketing",
       PlotStyle -> {Automatic, Automatic, Dashed, Dashed, Dashed},
       Filling -> {1 -> {2}}, FillingStyle -> Directive[White, Opacity[.8]]]]

And now with a few computations drama reads the play and announces the verdict with just 3 images. Visually we see clearly what was important as the time went by. The 3rd image of interplay between “love”, “hate”, “life”, and “death” speaks the most.

    drama[{"romeo", "juliet", "life", "death"}]
    drama[{"romeo", "juliet", "love", "hate"}]
    drama[{"love", "hate", "life", "death"}]

sdfr45wtrhgfdasaf

To make a cloud app, we need to modify function a bit and use CloudDeploy.

    dramaFORM[keywords_String] := Rasterize@Module[
       {pos, leg, keys = TextWords[ToLowerCase[keywords]]},
       leg = {"romeo", "juliet"}~Join~keys;
       pos = StringPosition[romeojuliet, #][[All, 1]] & /@ leg;
       SmoothHistogram[DeleteCases[pos, {} | {_Integer}],
        Frame -> None, PlotLegends -> Placed[leg, Bottom],
        AspectRatio -> 1/3, ImageSize -> 700, PlotTheme -> "Marketing",
        PlotStyle -> {Automatic, Automatic}~Join~Table[Dashed, {Length[leg] - 2}],
        Filling -> {1 -> {2}}, FillingStyle -> Directive[White, Opacity[.8]]]]

    CloudDeploy[FormFunction[{
        "x" -> <|"Label" -> "", 
        "Interpreter"->"String",
        "Hint"->"hint: love, death",
        "Help"->Style["type Shakespeare's words separated by spaces or comma, be patient, wait, behold ;-)",Italic]|>}, 
        dramaFORM[#x]&,
        AppearanceRules-><|
        "Title" -> Grid[{{"Evolution of topics through Romeo & Juliet"},{Spacer[{10,5}]},{img}},Alignment->Center], 
        "Description" -> "DETAILS:  http://wolfr.am/RomeoJuliet "|>,
        FormTheme -> "Black"],
    "RomeoAndJuliet",   
    Permissions->"Public"]

EXAMPLE: Wordcloud

It is also interesting to know how modern society sees Shakespeare. The code below for the word cloud runs over Encyclopedia Britannica article about Shakespeare.

    text=Import["http://www.britannica.com/print/article/537853"];
    base[w_]:=With[{tmp=WordData[w,"BaseForm","List"]}, If[(Head[tmp]===Missing)||tmp==={},w,tmp[[1]]]];
    SetAttributes[base,Listable];
    tst=Quiet[base[TextWords[StringDelete[DeleteStopwords[ToLowerCase[text]],DigitCharacter..]]]];
    blackLIST={"shakespeare","william","th","iii","iv","vi"};
    WordCloud[DeleteCases[DeleteCases[tst,_First],Alternatives@@blackLIST],
        WordOrientation->{{-\[Pi]/4,\[Pi]/4}},AspectRatio->1/3,
        ScalingFunctions->(#^.01&),ImageSize->800]

enter image description here

DATA & CODE SOURCES:

One Response to “Evolution of topics in Romeo & Juliet”

  1. Frank

    What is the difference between the “programming lab” and “development platform”

Leave a Reply

Your email address will not be published. Required fields are marked *