Generating Lines from Hamlet

import markov4s._
import scala.io.Source

val text = Source.fromFile("docs/resources/hamlet.txt")

// Some cleanup
val data = text.getLines.toList.flatMap { l => l.split(" ").flatMap { x => 
    if      (x.endsWith(",")) List(x.stripSuffix(","), ",") 
    else if (x.endsWith(".")) List(x.stripSuffix("."), ".")
    else    List(x) }
    }.asInstanceOf[List[String]]

// Create chain
val chain = MarkovChain[String].fromSeq(data)
implicit val rand = Rand()
// rand: Rand = markov4s.Rand@4e988592

chain.getRandomSeqWithProb(100).mkString(" ").replace(" ,", ",").replace(" .", ".")
// res0: String = "I'll change that wants discourse of solemn black, make it, within a man might not so much i' th' sun. Good even she (O God! How weary, my tongue! I pray you have mourn'd longer) married. O God! a dew! Or ever I would melt, thy name with my dearest foe in all the earth o'erwhelm them, though hell itself should gape And bid me hear! 'Tis not alone my ear that name with my heart, fellow student. So excellent a man might play; But I to see you, my"

chain.getRandomSeqWithProb(100).mkString(" ").replace(" ,", ",").replace(" .", ".")
// res1: String = "madam. These indeed, and gross in Elsinore? We'll teach you. And bid me hear! 'Tis very strange. My father's spirit- in heaven Visit her face too much, madam, within which she followed my inky cloak, Horatio! My father's brother, my uncle; My father's brother, fellow student. Indeed, I'll speak to incestuous sheets! It is. These but no more like my good. I pray you are no more like my best obey you, my dearest foe in all my mother's wedding. Upon the flushing in nature"

chain.getRandomSeqWithProb(100).mkString(" ").replace(" ,", ",").replace(" .", ".")
// res2: String = "incestuous sheets! It is not, good. My father's body Like Niobe, not two. Seems, fellow student. In my mind's eye, even she (O God! a man might play; But two. O, Nor the dejected havior of appetite had met my good. My father's person, within a king, most wicked speed, She married. I doubt some foul play. My father's spirit- in all tears- why she (O God! a man might play; But what make it be tenable in arms? All is. My father's brother"