King James Programming: Markov chain trained on the Bible and a comp sci textbook

[Permalink]

We are one apocalypse away from that becoming the gospel according to Saint Markov.

4 Likes

That is just a thing of perverse beauty.

I think I’m going to try working a bit of that into my own code.

1 Like

Ohhh I thought these were written by Markov Chaney.

Hmm. Now I wonder what Hubbard used.

Sigh. Here’s how I spent last night:

#!/usr/bin/perl 
#=====================================
#
#         FILE:  lovebible.pl
#
#        USAGE:  ./lovebible.pl 
#
#      VERSION:  1.0
#      CREATED:  05/12/2013 20:08:15 GMT
#     REVISION:  ---
#=============================

use strict;
use warnings;


use Algorithm::MarkovChain;
use Path::Class;
use autodie; # die if problem reading or writing a file


my @inputs = qw(king_james_bible.txt lovecraft_complete.txt); 
my $dir = dir(".");
my $f = "";
my @symbols = ();

foreach $f (@inputs) {
    my $file = $dir->file($f);
	my $lcounter = 0;
    my $wcounter = 0;
    my $file_handle = $file->openr();
    while( my $line = $file_handle->getline() ) {
		chomp ($line);
		my @words = split(' ', $line);
        push(@symbols, @words);
		$lcounter++;
		$wcounter += scalar(@words);
    }
	print "$lcounter lines, $wcounter words read from $f\n";
}   

my $chain = Algorithm::MarkovChain::->new();

$chain->seed(symbols => \@symbols, longest => 6);

print "About to spew ...\n";
print "---\n\n";
foreach (1 .. 20) {
    my @newness = $chain->spew(length   => 40,
                               complete => [ qw( the ) ]);
    print join (" ", @newness), ".\n\n";
}

Exercises for the reader:

  1. Figure out where to get hold of king_james_bible.txt and complete_lovecraft.txt (it’s not rocket science)

  2. Tinker with the Markov chain generator

Enjoy!

4 Likes

Charlie, mind if we post this?

1 Like

Markov Chaney once shot a book in the face. He also was CEO of Googleburton for a while, became the Vice President of Stats and drove a Monte Carlo.

2 Likes

Brilliant!

The LORD shall smite the waves thereof toss themselves, yet can never with those dark, unknown to man; so that I did not disturb thy door. Vainly did I struggle and shriek we heard on the night there shall be with.

I’m blogging it now but you’re welcome to share!

Charlie’s Diary blog entry: lovebible.pl

Note that what comes out is pretty much word salad. You’ll need to run it for a while and cherry-pick the output to find anything good. Here’s a sample run:

krina:markov charlie$ ./lovebible.pl 2> /dev/null
99820 lines, 821134 words read from king_james_bible.txt
16536 lines, 775603 words read from lovecraft_complete.txt
About to spew ...
---

the people came only two boxes in the accustomed metal as
the hair of women, as many as were of the men were heads of
the morning, nor did not yield as much as to the outer world
despite their guest.

the hills hear thy children within thee. 23:22 These things
about which is better that are weak, few or none of their
first month, in me: or mask. We went down in his chariot.
10:17 And Job answered and said, 9:2.

the LORD; it lived far from the traces of the amnesia? Had
my present body and mind alike. I took them away as I saw
good. 16:51 Neither hath the earth. 57:6 They have deeply
into the hand of Israel heard.

the doctor would never speak. To Mr. Ward he said, Take ye
have been too – not merely a great round red god ascended a
normal atmosphere in the vine; no more effective than
materialists in delineating the extremes of the.

the children of the discipline of our captors, which were
spoken of Paul. 16:15 And she snapped. "The shadows… there
is no proof, the deeper into adjuncts of the seemingly
deserted basement. Dr. McNeill unlocked a greypainted steel
door, but I.

the coast turneth to Ramah, and the prince and rejoice
therefore that she help me, I do not this abominable thing
that is in it; but thy disciples according unto thy land:
but remarkable for his mercy endureth for ever. 44:33.

the mystery of how assiduously he haunts those whom they had
carried the secret places. The doctor has distinctly assured
me for all they ever escaped a sense of Greenland and
Iceland in search of these wonders-and of heart, but ye.

the wicked shall have profaned among debris which slid down
through the eons to me. 11:15 But if ye have ought against
any: that your transgressions are discovered, so that were
the chief of Joseph. 13:8 And it grieved me thy.

the memories appeared, I therefore was not given unto him
the elders of the Jews, and to the hills, ravines, and
bluffs hemmed in the uniform wetness of my table upon him,
as hinted by his relatives, wishing to transport our.

the mists. There were never dead, but of plebeian ignorance,
since the old fishing town as legend according unto the
greatness unto our real impulses contrast with sackcloth,
and went into the inner gate that looketh toward the east,
and the.

the blue-winged fly retain Evidently they saw that light old
spires of Kingsport. Even as it was said that she was in the
room. It was very exciting the chief gods had rest of the
heifer shall wash his males an.

the general disgust which his habits and misalliance had
declared this day, shall start before the Life touches
onDolliver Romance, the Elixir of Life touches onDolliver
Romance, the place – is never got his bow abode of delirium.
Dream, madness, and.

the son of David, is risen violently, and I strained passage
of artificial settings, their coming she is, Prague – quick!
Get her out of my narrative effects despite a limited amount
of manufacturing were also practiced. Travel was very
latest.

(That’s enough gibberish for now!)

1 Like

This is possibly the greatest use of a computer ever. If only all programming manuals read like this.

Clearly a Doctor Who reference, a relic left over from the Time War perhaps?

You may have to move to a higher order Markov chain. This program is just order 1, which rarely generates anything of interest. Sadly, I know not of Perl.

The input may be a bit small for that. It’s not much fun if just copies long sequences from the source material.

The book I’m learning Python with (ThinkPython, you can get a free copy on the publisher’s site), have an exercise of this kind. And I’m having quite a bit of fun mixing:

  • The accomplisht cook or, The art & mystery of cookery by Robert May,

and

  • The Kama Sutra of Vatsyayana.

Some crazy extracts :

The best way of making all manner of sweet herbs picked and cleansed, steep them in few and not harsh words, not laughing loudly in their own private rooms.

The following principles are laid down on the ground.

Colouring the teeth, is called high union, while the elephant and the hare make the rest into little cakes as broad as your finger, with some strong broth or gravy only, give them a warm, and broth it: lay Lemon on it, and scum it, and put the fowl on fine sippets. Sometimes you may do of any other way of exciting a woman. Or, he may have formerly given her, with the cream, a quart of good thick cream, and raw eggs, a little ising glass, and being roasted put them in September. Take four stone of pork, and cut it into thin slices; then mince some sweet Herbs and put to it butter, rose-water, and some dissolved musk; bake it and use the same spices as abovesaid, and serve them with bread and flower. 2.

Grated bread, Fennil seed, coriander-seed, cinamon, and sugar.

Otherways.

Beaten butter with lemon in bits like square dice, and salt; mingle all together, then put it in fair water half an inch long, yolks of six eggs with vinegar or grape verjuyce, and four of the clock in the Book of all manner of sweet herbs, sage, spinage, marigold leaves and flowers, white or green wheat, and blew-bottles for blew. To keep Sparagus all the external enjoyments of life, still have recourse to other men.

1 Like

This topic was automatically closed after 5 days. New replies are no longer allowed.