So I was thinking to myself the other day, "Self, you need to add something
neat to this site (netfl.org) that's utterly pointless, somewhat belligerent,
and causes you at least some level of grim amusement." Out of that came
something akin to Mad Libs - labotomized, turned upside down, made far too
complex, and tinged with at least some level of player performance realism to
make it almost look as though an AP writer had penned a story. Out of this
embarassing reverie, I realized that I was looking for an excuse to develop a parser that would analyze a large string that was stored in a database and do several transforms on it to change this string, a template for a story, into a full-fledged story. There were transforms implemented to convert any number of generic labels into a random string as well as some more sophisticated transforms that would retrieve statistical data and aggregate it into something textual.
The result? I'm almost proud of it:
Game Summary (Earl Schmidt, NetFL Press)
When I was a young lad, I once tossed a frog in the microwave. My father, as angered as an environmentalist stuck in a room full of Bolivian slash-n-burn agriculturalists, told me to retrieve a stick of dynamite. He then dragged me atop the compost heap and set the embers of my wisdom to flame. To this day, I still wet my pants whenever I think of that memory. I bring this up because the similarities between what happened to me then and what happened to The Spanish Inquisition today are the same. Springfield Rabid Sockpuppets prostrated The Spanish Inquisition as though they were naught but a group of frenchmen on the battlefield, publicly humiliating them by the tune of 51-19 in front of a despondent crowd. Despite the ambient weather, I found myself looking upon the cold, dark, windswept gridiron of my soul, agonizing for three gut-wrenching hours as my eyes were forced to witness the utter lack of skill exhibited by TSI on this particular day. By the end of the opening kickoff, I could already feel the nausea, the lurching in my stomach. By the end of the first quarter, I began to contemplate gnawing off my own leg to escape... SRS lead the all-time series 9-0 against TSI. SRS has a 12-0 regular season record (2-0 in the playoffs). TSI has a 7-5 regular season record. (2-1 in the playoffs)
Overall, Nick Harris may well be the greatest goat this side of the fairytale land of satyrs, unicorns, pixies, and winning TSI seasons, playing about as well as a frog pithed by an epileptic first-grader. This journalist found himself maintaining sanity amidst the botched stumbling of LaDainian Tomlinson and his sidekicks by drinking heavily and choking down moldy peanuts. If Jeff Garcia's body of work exemplifies the high-point of your weekend, you know that you're on the losing end of a sordid, sick joke of a game. Words utterly fail to describe this romp into the realms of ineptitude. When Chekhov saw the long winter, he saw a winter bleak and dark and bereft of hope. Standing here in the garish, filth-ridden stands of this now-empty stadium after the game, I got to thinking - such is truly the fate of both fans of the TSI squad. In the end, this team is just hopeless.
Jeff Garcia said, "We had a chance at the beginning, man. We hung in there through the opening kickoff. We fought, but after that, we just didn't get her done. It's a bit disappointing, to be sure. I'm very disappointed in myself, the way I played as one of the 53 leaders on this football team. It starts with me watching someone else get the ball into the hands of the right guy and watch him making the plays... cheering on the others making the tackles... I did that. That falls on me. We're not going to win football games if they don't start doing their part."
Antonio Gates blathered, "Oh fo real, man. Ya see, I is da real thing. Dose drops, man. Dat weren't my fault, dawg. Th playa wuz trowing too hard and I run the wrong play jus so's he can't find me. No sense me breakin' my assets, man... No sense me making it on 'Jacked Up' or nothin'. No matter... I be back, bro. Expect numba ME to grab up 60 scores this season, yo. Dem otha's, man? I gonna steal the show. They's amateurs spelt wit a capital E."
They were almost perfect on the SRS squad particularly on the defensive side of the ball last week as they racked up a combined 368 points, 204 on offense and 164 on defense. Aaron Rodgers with 25 points on offense and Keith Bulluck with 21 points on defense were the top scorers. However, they were far from perfect. Said Coach/GM Allen Cummings, "I took exception to our execution on a few plays.. For one, Tra Thomas was as sharp as a sponge today. Stimulus. Response. That's all there is to it. Pavlov had a dog and I've got this idiot. I've noticed that the red tazer in particular gets him ready for the games. Doc says that if he spent a little more time working off the flubber in his midsection than 'clubbing' and getting fat on the buck-a-bucket combo at the KFC, well, his medical list wouldn't read like a copy of 'War and Peace'. Back in my day, 'clubbing' was something untoward that you did to baby seals. As for Sidney Rice? He was utterly incompetent, not catching anything on the day. Doc's been looking into a revolutionary new surgery - replace his hands with anything - stickum, chicken claws, even bricks would be an improvement. I mean, he drops balls as if they were live ferrets. Overall though, the the most incompetant player in this game was Mike Jenkins. His nasty effort yielded nothing but the scorn of his teammates. Some players need a bit more instruction than others. I've tried a few less orthodox teaching tools from time to time..."
Says Mike Jenkins, sporting a nice lace evening gown, "Ya, coach says I played like a little girl so I might as well dress the part. I hafta practice in this thing. He calls me the fairy princess. Man, I'm callin my agent. This ain't parta the deal."
Fred Jackson added, "Shoot... he should know he can't fit in no D-cup! I tell ya, he looked like some sort of demented, bloated Valkyrie... Man... brings new meaning to the phrase 'when the fat lady sings.' "
Though the game was already decided on the field, apparently neither team was done. Allen Cummings said, "They stink, not in that 'festering sewage inside a porta-potty next to a dead, bloated cow floating in a culvert' way, but more in the 'the Vienna Boy's Choir has more football talent' way." In response, Al Burns waxed poetic, stating, "Like 'em? No... not really. I'd rather strangle puppies in front of a dozen orphans than pull that wretched owner of theirs out of a burning building."
Technical Details
Oracle has a fairly limited string manipulation library that allows only for the most trivial of manipulations. This is ideally suited to much of what I implemented, though there were other areas where greater sophistication would have made things a lot less complex. Suppose we had an example story template that we randomly select from a table:
When I was a young engineer, I #X# and then #Y#. Then, my colleague
%colleague% %something% and #Z#. We #A#.
The parser has some simple text manipulation functions, notably the replace function. In PL/SQL, this might be something like:
lTemplate := replace(lTemplate, '#X#', get_verbiage('GoodThing'));
lTemplate := replace(lTemplate, '#Y#', get_verbiage('BadThing'));
This would translate the X and Y tags into a randomly selected string of text if get_verbiage contained the following code:
select verbiage into lVerbiage
from (select v.verbiage
from tblverbiage v
inner join tblverbiagetypes vt on v.verbiagetype = vt.oid
where vt.verbiagetype = pType
order by dbms_random.value)
where rownum = 1;
Where we have a very simple table, verbiage, that is tied to a specific type, as would have been passed in as the argument to get_verbiage. Of note is the dbms_random.value call. This order by clause will randomize the order of the output and then the outer select will grab only the first element. Though a better approach may exist, I have yet to discover it.
The %-tagged elements in the template were my way of getting custom data that was not necessarily a simple query. In every other aspect, it behaves identically to the functionality already discussed. In my NetFL example, there is a function that grabs a teams record based on data about the played games. It then translates that into regular season W-L and post season W-L, denoting if the person has won a division, conference, or league championship.