only commit so far

This commit is contained in:
Nick Stokoe
2023-01-05 15:24:09 +00:00
commit ee3f6dffde
2 changed files with 116 additions and 0 deletions

49
chaining.pl Executable file
View File

@@ -0,0 +1,49 @@
#!/usr/bin/perl
use strict;
use warnings;
use v5.10;
my @sentences;
while(<>) {
chomp;
my @sentence_frags = grep /\S/, split /[.?!]/;
# $sentences[-1] .= shift @sentence_frags
# if @sentences && @sentence_frags;
push @sentences, @sentence_frags;
}
my %words;
for (@sentences) {
my @words = grep /\S/, split /\W/;
my $last = '';
for my $word (@words) {
$word = lc $word;
$words{$last}{$word}++;
$last = $word;
}
$words{$last}{''}++;
}
#say for @sentences;
#use Data::Dumper;
#print Dumper %words;
for my $si (0..10) {
my $word = '';
while(1) {
my $next = $words{$word};
my @next2 = map { ($_) x $next->{$_} } keys %$next;
$word = $next2[int rand @next2];
last if
$word eq '';
print "$word ";
}
print "\n";
}