#!/Utils/bin/perl5 -w

$first = ". ";

while (<STDIN>) {
  tr/A-Z\n\!\?/a-z \.\./; # translate upper case to lower case; new line to 
                          # space; '!' and '?' to '.'
  s/[^a-z \.]/ /g;        # substitute all characters for space exept letters, 
                          # space and period
  s/ \./ /g;              # substitute space followed by period for space
                          # (spurious sentence boundries)
  s/ +/ /g;               # substitute duplicate spaces for single space
  s/^[ \.]+//;            # remove leading space or leading period

  $rest = $_;  
  while($rest) {
    $trigram = $first . substr($rest,0,1);
    $first = substr($trigram,1,2);
    $rest = substr($rest,1);
    print "$trigram\n";
 }
}

