bugfixes and fine tuning for import/export
This commit is contained in:
parent
cd034f2e09
commit
c0759152ce
|
@ -18,9 +18,12 @@ my $redis = redis();
|
|||
my $p = config("redis_prefix");
|
||||
my @keys = $redis->keys("$p:chains:*");
|
||||
|
||||
print "# shithead-ng file (version 0)\n# this file cannot be used by other markov chain programs, without modification.\n# do not remove the first line, as it is used by the import script to determine whether the file is a standard irc log or a shithead-ng specific file.\n\x1c";
|
||||
say "shithead-ng file (version 0)\nthis file cannot be used by other markov chain programs, without modification.\ndo not remove the first line, as it is used by the import script to determine whether the file is a standard irc log or a shithead-ng specific file.";
|
||||
|
||||
for (@keys) {
|
||||
# mark the beginning of the record
|
||||
print "\n\x1c";
|
||||
|
||||
my $prefix = quotemeta $p;
|
||||
my $k = $_;
|
||||
$k =~ s/$prefix:chains://;
|
||||
|
@ -28,5 +31,5 @@ for (@keys) {
|
|||
my @words = split ",", $k;
|
||||
push @words, @{ $redis->lrange($_, 0, -1) };
|
||||
@words = map { $_ eq '___end___' ? "\x1d" : $_ } @words;
|
||||
print join("\x1f", @words), "\n\x1c";
|
||||
print join "\x1f", @words;
|
||||
}
|
||||
|
|
|
@ -16,18 +16,19 @@ close BRAIN;
|
|||
# open it again from the top
|
||||
open BRAIN, $brain_file or die $!;
|
||||
|
||||
if ($line =~ m/^#\ shithead-ng\ file\ \(version\ .+\)$/) {
|
||||
if ($line =~ m/^shithead-ng\ file\ \(version\ .+\)$/) {
|
||||
# shithead-ng specific file
|
||||
while (<BRAIN>) {
|
||||
next unless $_ =~ m/^\x1c/;
|
||||
$_ =~ s/^\x1c//;
|
||||
my @words = split "\x1f", @words;
|
||||
chomp;
|
||||
my @words = split "\x1f", $_;
|
||||
@words = map { $_ eq "\x1d" ? "___end___" : $_ } @words;
|
||||
|
||||
# Write to redis
|
||||
my $p = config("redis_prefix");
|
||||
my $redis = redis();
|
||||
$redis->lpush("$p:chains:".shift @words.",".shift @words, @words);
|
||||
$redis->lpush("$p:chains:".shift(@words).",".shift(@words), @words);
|
||||
}
|
||||
} else {
|
||||
# generic irc log file
|
||||
|
|
Loading…
Reference in New Issue