I love to cut stuff up and rearrange it. Here's a tool for doing that with text. It uses Markov Chains to analyze the frequency of word arrangements in an original text. Then it spits out random text based on those frequencies. The entertainment value of the result varies a lot with what you use for input text, but it can make some really hilarious stuff. Also, the more text you give it the better it does, basically, though it takes longer to analyze it, of course. Try giving it 2 or 3 radically different kinds of text, like an erotic short story and some record reviews. Things get pretty wacky. I originally got the core of the code from the first edition of O'Reilly's Programming Perl, the pre-perl5, pink camel book. I tweaked the script a little and have been using it for years for various things. Just recently I decided to make it into an object-oriented perl module. It's still a work in progress, but it works fine. the main application of it so far has been the Jung-Markov Collective Dream Constructor. Here's the code:

# this is a module version
# of the old Travesty script
# from way back in the perl4 camel book days...
#  steev hise, july 2001
#  copyleft 2001, gnu gpl, etc.
#################################################

package Text::Travesty;
use strict;
use Data::Dumper;
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $AUTOLOAD %ok_field $VERSION $ERROR);

use Exporter;
$VERSION = 1.00;
@ISA = qw(Exporter);

# the constructor accepts the input text as a string or array of strings.
sub new {
    my ($class, @input) = @_;
    my $self = {};
    bless($self, $class);
    srand(time());
    
    # munge input into one string
    my $input = "@input"; 
    
    # Do each word.
    my(@ary,@word,$a,$p,$n,$w,%num);
    
    @ary = split /\s/,$input;
    while ($#ary > 1) {
      $a = $p;
      $p = $n;
      $w = shift(@ary);
      $n = $num{$w};
      if ($n eq '') {
	push(@word,$w);
	$n = pack('S',$#word);
	$num{$w} = $n;
      }
      $self->{lookup}->{$a . $p} .= $n;
    }
    $self->{words} = \@word;
    return $self;
}

# this method spews out the words, based on the frequencies.  If there is
# more than one possibility to choose from, choose one randomly.
# give it the number of words of output you want.
# it returns a string.
sub travestize {
    my($self,$limit) = @_;
    my($a,$p,$n,$foo,@output);
    $a = $self->{a};
    $p = $self->{p};

    for (0..$limit) {    
       $n = $self->{lookup}->{$a . $p};
       ($foo,$n) = each(%{$self->{lookup}}) if $n eq '';    # a bootstrap ?
       # I'm still working on a different routine to cause the
       # output to start from a random place in the original text,
       # rather than always at the beginning. but it's proven more
       # difficult than you'd think.
       
       $n = substr($n, int(rand(length($n))) & 0122226,2);
       $a = $p;
       $p = $n;
       my($w) = unpack('S',$n);
       #print $w;  # debugging.
       push @output, $self->{words}->[$w];            
    }

    # store some of these weird variables.
    $self->{a} = $a;
    $self->{p} = $p;
    return join ' ', @output;
}


### keep perl happy and comfortable.
1;

Here's some example output, run on 10 Megabytes of some of my saved email:

Thanks for taking care of himself, I'm teaching him how to publish content former, shell account. And I'd also like to get my new stuff if you do a desert robot pyrotechnic closer, cheaper, and smaller. ahhhh... keep in mind the place is a collection of recordings featuring the radically impractical...leave your tommy gear home...BYOSM (bring your own thing too! immediately following the deadline to file his taxes, Mr. Seiff sits surrounded by odd artifacts of the events that make pornography easier to have he on a radio interview with Steev Hise To: Allan Hise hise@io.com Subject: lan hey do you think of it... i had done x instead. i still had it. so, i dunno... i really like music, never have. :-\ smh Steev Hise, Wannabe Has-Been steev@detritus.net http://detritus.net/steev I don't think the mother tongue of Miguel Matamoros - who's lifetime output consists of almost anything, Dimuzio's listed sound sources on his new Kyma stuff. Looking forward to the product.

jose Condo Conversions Excuse Landlords Evict Ellis flat Lower Heights. Disabled, lower income with a good first step in getting a taste too sweet or too urban would be more secure. i can get a great weekend.

Happy writing! Linda, Authors Writer's Friend gold paid." Toll Line 1.800.431.1579, Amazon.com, WritingNow.com, & bn.com http://www.writingnow.com> Call for Participants INTERNET HOSTING COLLECTIVE -- CALL FOR PARTICIPANTS Please forward widely to concerned people and mailing lists.

Are you interested in getting that to happen. I hear most of the golden era of Cuban singers, for he was also a DHCP server (for the inside net) and it renewed my enthusiasm to work for a year. Right now it's all helping me and wanted to do your own risk. Unfortunately, the interviews are available on chartered web addresses. Further confusion could arise for employees and would love to have my pine configured, client, outlook express, can also check my mail and I spent painting in a couple years, but now that he met and worked at Mr. Seiff's boasts about his association. Getting Away With Treason , July 20, 1988, in which I did, and for one suspect charged with criminal violation of the Integratron.

Log in or register to write something here or to contact authors.