remove duplicate code
This commit is contained in:
parent
5c54d28339
commit
021a3da7a0
|
@ -7,35 +7,9 @@ use FindBin qw($Bin);
|
|||
|
||||
use lib $Bin;
|
||||
|
||||
use MarkovBot::Config;
|
||||
use MarkovBot::Learning;
|
||||
|
||||
# Load Configuration
|
||||
|
||||
my $redis_prefix = config("redis_prefix");
|
||||
my $brain_file = $ARGV[0];
|
||||
|
||||
my $redis = Redis->new();
|
||||
|
||||
open BRAIN, $brain_file or die $!;
|
||||
|
||||
while (<BRAIN>) {
|
||||
|
||||
# Apply preprocessing to the line
|
||||
$_ = $_ . "___end___";
|
||||
$_ = lc $_;
|
||||
$_ =~ y/\,\.\!\?\(\)//d;
|
||||
|
||||
# Split it into individual words
|
||||
my @words = split(' ', $_);
|
||||
|
||||
# Disregard short sentences
|
||||
next if scalar(@words < 4);
|
||||
|
||||
for (my $i = 0; $i <= $#words-2; $i++) {
|
||||
# $words[$i] $words[$i+1] => $words[$i+2]
|
||||
$redis->rpush("$redis_prefix:chains:$words[$i],$words[$i+1]", $words[$i+2]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
learn $_ while <BRAIN>;
|
||||
close BRAIN;
|
||||
|
|
Loading…
Reference in New Issue