Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Tolstoy Chains

by andyf (Pilgrim)
on May 10, 2004 at 03:23 UTC ( [id://351945]=poem: print w/replies, xml ) Need Help??

I just fed Tolstoys War and Peace to rclamps /Algorithm-MarkovChain-0.06/lib/Algorithm/MarkovChain.pm and after about 120 seconds chaining the whole text it concluded...

histories of government have purposes of the conditions of the weakness of history.

Replies are listed 'Best First'.
Re: Tolstoy Chains
by nimdokk (Vicar) on May 10, 2004 at 16:21 UTC
    And that about sums it up pretty accurately. Wonder what it would say about "Finnegan's Wake" by James Joyce.
      A day in the life of a troubled Irishman.

      I remember back in the 80s reading a bit in National Lampoon magazine the gist of which was Cliff's Notes on Cliff's Notes. It was for students who didn't even have time to read the Cliff's Notes to cram for their Lit reading exams. Each book was boiled down to a one-sentence synopsis. The only one that I recall was Crime and Punishment: "A man kills a woman and feels bad." The whole bit was brilliant, though.

      Feed The Naked Lunch to your chain and see what you get. That should be interesting, because in essence Burrows had his own Markov chain cranking away in his head.

        Yes nimdoc, rather uncanny I agree. Anyway I think we are a long way from Lingua::Lit::Condense yet but it would great for students indeed.
        Imagine,
        condense prideandprejudice.txt "Human bonding is complex" condense oneflewover.txt "Insanity is relative" condense 1984.txt "Government watches people" cool!
        Anyway, I searched ibiblio/gutenberg and turned found no lunch nor on Google. Which confirms there is no free lunch. I found a couple of excerpts though to cat together. They were formatted pretty weirdly so a quick blast with
        perl -pi -e 's/\W/ /g' lunch.txt

        and we lost all the punctuation, which imho is best for this sort of pseudo science (the loss of symbols to untrapped punctuation outweighs their syntactic value).

        Anyway Burrows ....

        I have picked the choice few sentences out of 15 or so, truncated some,

        Old Pete men suck the Florida tan the same about you
        taboos curses and subway is lurking in Washington Square a cell of rotten
        he has scored he cruises the same dirty junky he hangs off
        Thanks kid I am evidently his sharkskin suit
        And the bodys string of inquiry ruling that anesthizes his enveloping presence
        all over from shooting in my kid I ll wipe your release


        - absolute filth imho, but who should concerned mothers sue? Mr Markov or Mr Burrows?, or Me?.

        Still searching for Joyce.

        Andy
Re: Tolstoy Chains
by Anonymous Monk on May 12, 2004 at 05:33 UTC
    Where's the code?
      #!/usr/bin/perl use strict; use Algorithm::MarkovChain; my $mc = Algorithm::MarkovChain->new(); unless (scalar(@ARGV) gt 0) { die "usage: file [longest_chain(int)] [longest_output(int)]" }; my $infile = shift; my $longest = shift; my $outlength = shift; unless ($longest > 2 and $longest < 10) {$longest = 3}; # sensible constraints unless ($outlength > 2 and $outlength < 20) {$outlength = 10}; if ($infile) { $| = 1; print "seeding from $infile\n"; open IN, $infile; while (<IN>) { $mc->seed(symbols => [m/(\S+)/g], longest => $longest); print "\r$. "; } print "\nSeeded, chain length $longest. Hit enter for random ut +terings of $outlength words.\n"; } while (<>) { print join(' ', $mc->spew(length => $outlength)),"\n"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: poem [id://351945]
Approved by exussum0
Front-paged by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-03-28 13:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found