Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env perl
use strict;
use warnings;
use Text::MeCab;
use Algorithm::MarkovChain;
use Perl6::Say;
use Data::Dumper;
open my $in, '<', shift or die $!;
my $text = do { local $/; <$in>; };
close $in;
my $mecab = Text::MeCab->new({});
my @symbols;
for (my $node = $mecab->parse($text); $node; $node = $node->next) {
#say $node->surface;
push @symbols, $node->surface;
}
my $chain = Algorithm::MarkovChain->new;
$chain->seed(
symbols => ¥@symbols,
longest => 4,
);
my @newness = $chain->spew(
length => 140,
strict_start => 1,
#complete => [ qw( the sky is ) ],
);
for my $chunk (@newness) {
print $chunk;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.