#!/usr/bin/perl

use locale;
use POSIX qw(locale_h);
setlocale(LC_ALL, "norwegian");

my %fork;

use Getopt::Mixed;
Getopt::Mixed::getOptions("abbr=s");

open (ABBR, $opt_abbr);
while (<ABBR>) {
    s/\s//g;
    my @a = split(/\./);
    foreach my $a (@a) { $fork{$a}=1 }
}



while (<STDIN>) {

    s/ +/ /g;

    my @words = split (/([!|\?|\.|:|;| ])/);

    my $l = @words;
    my $i;
    foreach my $w (@words) {

	print $w;

	my $prev; my $next; my $pprev;
	if ($w =~ m/^[!|\?|\.|:|;]$/) {

	    my $j = 1;
	    while (!$prev) {
		my $c = $words[$i-$j];
		if ($c =~ /\S/) { $prev = $c }
		if (($i-$j) == -1) { $prev = "START__" }
		$j++;
	    }

	    my $j = 2;
	    while (!$pprev) {
		my $c = $words[$i-$j];
		if ($c =~ /\S/) { $pprev = $c }
		if (($i-$j) < 0) { $pprev = "START__" }
		$j++;
	    }

	    my $j = 1;
	    while (!$next) {
		my $c = $words[$i+$j];
		if ($c =~ /\S/) { $next = $c }
		if (($i+$j) == $l) { $next = "END__" }
		$j++;
	    }

	    if ($fork{$prev}) { }
	    elsif ($prev =~ m/^\d+\)*$/) { }
	    elsif ($prev =~ m/^\w$/) { }
	    elsif ($words[$i+1] =~ m/\w/) { }
	    elsif ($next =~ m/^[a-z]/) { }
	    elsif (($i == 1) and ($w eq ":")) { } 
	    elsif (($pprev == ".") and ($w eq ":")) { } 
	    else { print "\n" }
	    

	}

	$i++;
    }

}
