Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re^3: Concatenating strings with different length

by Kenosis (Priest)
on Nov 30, 2012 at 18:55 UTC ( #1006507=note: print w/replies, xml ) Need Help??

in reply to Re^2: Concatenating strings with different length
in thread Concatenating strings with different length

Excellent, choroba!

Building on your and GrandFather's suggestions, there's the following:

#!/usr/bin/perl use warnings; use strict; use Lingua::EN::Tagger; my %fragments; my $p = new Lingua::EN::Tagger; my @adjectives = qw/nervous nutty obnoxious outrageous panicky repulsive scary selfish sore tense terrible testy thoughtless tired troubled upset uptight weary wicked worried/; my @stems = ( "It's been said that there were many", 'Goldfish spoke with', 'There were three', 'People used to see 42', 'There were quietly-roaming groups of' ); while ( my $line = <DATA> ) { chomp $line; my $adjective = $adjectives[ int rand $#adjectives + 1 ]; $line = $p->add_tags($line) =~ s/<nns>/$adjective /gr =~ s/<.+?>// +gr; my @words = split / /, $line; for my $i ( 0 .. $#words - 1 ) { push @{ $fragments{ $words[$i] } }, join ' ', @words[ 0 .. $i - 1, $i + 1 .. $#words ]; } } print "Once upon a time...\n\n"; my @sentences; for my $term ( keys %fragments ) { my $stem = $stems[ int rand $#stems + 1 ]; push @sentences, "$stem $term " . ( join ' and ', @{ $fragments{$term} } ) . '.'; } print join ' ', @sentences; print "\n\nThe times have certainly changed.\n\nThe end."; __DATA__ big businesses fast red cars big smart companies fast light planes fast animals big bad wolves small bad girls bad growling bears

Sample output:

Once upon a time...

People used to see 42 small bad outrageous girls. There were three outrageous fast red cars and small bad girls. Goldfish spoke with light fast scary planes. There were three growling bad nervous bears. There were quietly-roaming groups of nervous big bad wolves and bad growling bears. There were three scary fast light planes. There were quietly-roaming groups of tense fast animals. Goldfish spoke with bad big nervous wolves and small outrageous girls and growling nervous bears. People used to see 42 big wicked businesses and smart selfish companies and bad nervous wolves. Goldfish spoke with smart big selfish companies. Goldfish spoke with red fast outrageous cars. Goldfish spoke with wicked big businesses. It's been said that there were many fast red outrageous cars and light scary planes and tense animals. There were quietly-roaming groups of selfish big smart companies.

The times have certainly changed.

The end.

An emerging Perl storyteller...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1006507]
[Corion]: erix: Naah, I just saw the announcement and remembered that discussion. Maybe I'll try building a DBD::SQLite with the zip stuff built-in, just for fun
[Corion]: Oh - and a good morning to you too :)
[erix]: we have these largish series (dozens) of largisch (1-2 GB) tabsep files that might be shrunk a bit in this way. Bound to get a bit slower but that doesn't matter too much for us

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2018-01-24 08:59 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (256 votes). Check out past polls.