"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects." (Robert A. Heinlein)
Showing posts with label Random-blog-generator. Show all posts
Showing posts with label Random-blog-generator. Show all posts

Thursday, 28 July 2011

Random blog post title generator with Polygen

After so many “Test drive:” blog post I sometimes feel that my writing has become too much repetitive. I so decided to have some relax and, with a little of self-irony, I'll try writing a random blog post generator using Polygen. Writing a full post generator is a huge task: as you start decomposing a phrase structure the number of options literally explode. So let's start just with generating the post title.

A top down approach

The top-down approach is the one I find more natural while dealing with a Polygen grammar, so let's start with defining the very basic structure of a blog post
S ::= Title "\n"^
Body "\n"^
Tags;
the “\n” string is a new line escape character while the “^” operator tells Polygen to concatenate without adding spaces (To avoid a new line starting with a space).
We'll set the “Body” symbol to an empty preposition and forget about if (at least for the moment).
Body ::= _;
Titles for “review style” posts are usually something like “installed some-program on some-system”; this can be written, in Polygen grammar language, like following:
Title ::= Action (Program ("on the" Computer | "on" Os | "on the" Computer "and" Os) | Os "on the" Computer);