﻿#!/usr/bin/perl -w
use strict;
use warnings;
use utf8;
use open qw(:std :utf8);
use integer;
use Unicode::Normalize;


# Filter_2_08_check_s.pl
# 2010-04-04
# Wolfgang Schmidle

# what does it do?
# input
# output


my $unusualFirstCharacters = ".,:;!? )]}";

# text input

my @filters = (
	"Filter_3_00_Schummelskript.pl",
	"Filter_3_01_replace_unknown_characters.pl",
	"Filter_3_02_replace_replacements.pl",
	"Filter_3_03_replace_escape_sequences.pl",
	"Filter_3_04_replace_underscores.pl",
	"Filter_3_05_add_basic_xml.pl",
	"Filter_3_06_make_tags_wellformed.pl",
	"Filter_4_00_Schummelskript.pl",
	"Filter_4_01_pb.pl",
	"Filter_4_02_move_floats.pl",
	"Filter_4_03_insert_lb.pl",
	"Filter_4_04_insert_s.pl"
);

my $file = shift @ARGV;

$_ = shift @filters;
my $command = "perl $_ \"$file\"";
foreach (@filters) { $command .= " | perl $_"; }

my $result = `$command`;

my @text = split "\n", $result;


# go through the text

my $i = 0;
my $pb = 0;
my $page;

foreach (@text) {
	$i++;
	if (m!<pb[ >]!) { 
		$pb++;
		$page = ( m!\[(.+?)\]! ? $1 : $pb );
	}

	# find very short <s>
	
	if (m!<s>.{0,10}</s>!) {	
		warn "Line $i (page $page): very short <s>:\n$_\n"; 
	}
	
	# find unusual characters at the beginning of <s>
	
	if (m!<s>[$unusualFirstCharacters]!) {	
		warn "Line $i (page $page): <s> starts with an unusual character:\n$_\n"; 
	}
}

die "That's all.\n";


# TO DO:
# bei den sehr kurzen Sätzen sollte man noch tags herausrechnen

