Skip to content

Instantly share code, notes, and snippets.

@kyanny
Created May 22, 2009 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyanny/116095 to your computer and use it in GitHub Desktop.
Save kyanny/116095 to your computer and use it in GitHub Desktop.
#!/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