RubyFlow : The Ruby Community Blog

Home   Submit   Sign Up   Log In   leaders   Twitter   RSS Feed  
 

New Gem: Literate Randomizer

I wanted an easy way to generate good, random, near-english prose. There wasn't a gem that made me happy, so I wrote a new one: Introducing literate_randomizer. (my blog post)

> LiterateRandomizer.paragraph
=> "Says he slipped rapidly growing in creating. Assure you can't get back. Action of inorganic elements of any binary compressed marked the way up at."

Comments

Did you checkout some of the ngrams gems, such as raingrams?postmodern - October 19, 2012 05:18
I did not. Thanks for the link :). I'll take a look.shanebdavis - October 20, 2012 22:25
Raingrams looks great. Yours right? Nice work! I was thinking about trying some tri-grams to see how much better the prose appeared. I also wanted to anchor sentence endings that came from the text. Currently I just truncate when the desired sentence length is reached -- unless it is one of the hard-coded preposition words. I spent a decent amount of time working with the random generation part of the code using the simple, core bi-gram model. I may think about using a library like yours at the core and wrapping the random-generation code around it in a future release.shanebdavis - October 20, 2012 22:41
@shaebdavis correct, tri-grams and higher will produce more accurate text. This requires having a greater corpus to train the models against, otherwise you'll get verbatim training sentences. Also, there's the problem of enforcing grammar and preventing run-on sentences. You can always enforce minimum / maximum sentence length with a recursive sentence building method. I tried adding some basic random generating methods in Raingrams.postmodern - October 22, 2012 02:53

Post a Comment

Comment abilities for non registered users are currently deactivated, pending time to add a proper CAPTCHA to solve the escalating spam problem. Sorry!