#!/usr/bin/env perl

use utf8;
use 5.008;
use strict;
use warnings;

binmode(STDOUT, ":utf8");

my $INPUT_FILE = $ARGV[0];
my $OUTPUT_FILE_TRAIN = $INPUT_FILE . 'conlltransTRAIN';
my $OUTPUT_FILE_TEST = $INPUT_FILE . 'conlltransTEST';

open my $IN, "<:utf8", $INPUT_FILE or die "Cannot open $INPUT_FILE for reading!\n";
open my $OUT_R, ">:utf8", $OUTPUT_FILE_TRAIN or die "Cannot open $OUTPUT_FILE_TRAIN for writing!\n";
open my $OUT_E, ">:utf8", $OUTPUT_FILE_TEST or die "Cannot open $OUTPUT_FILE_TEST for writing!\n";

while (<$IN>) {
    chomp;
    my $l = $_;
    if ($l eq '') { print $OUT_R "\n"; print $OUT_E "\n"; }
    else {
	my (@t) = split /\t/, $l;
	my $pos = substr($t[2],0,1);
#	print $OUT_R "$t[0]\t$t[1]\t$t[2]\t$t[2]\t$t[3]\t$t[3]\t$t[5]\t$t[5]\t$t[6]\t_\t$t[7]\t_\n";
	print $OUT_R "$t[0]\t$t[1]\t_\t$t[2]\t_\t$t[3]\t_\t$t[5]\t$t[6]\t_\t$t[7]\t_\n";
	print $OUT_E "$t[0]\t$t[1]\t$t[2]\t$t[2]\t$t[3]\t$t[3]\t$t[5]\t$t[5]\t_\t_\t_\t_\n";
	print $OUT_R "$t[4]\t$t[0]\t_\t$pos\t_\t$t[3]\t_\t$t[5]\t$t[6]\t_\t$t[7]\t_\n";
	print $OUT_E "$t[4]\t$t[0]\t$pos\t$pos\t$t[3]\t$t[3]\t$t[5]\t$t[5]\t_\t_\t_\t_\n";
    }
}