
# Estelle Salmon

open(INPUT,"<:encoding(utf-8)",$ARGV[0]);
open(OUTPUT,">:encoding(utf-8)","$ARGV[0].xml");
print OUTPUT "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
print OUTPUT "<corpus>\n";


while (my $ligne=<INPUT>) {
	next if ($ligne=~/^$|^#$/);
	$ligne=~s/\r//;
	# if c'est une sent_id paire on écrit </titre><description>
	if ($ligne =~ /sent_id = ([0-9]+)$/) { 
		my $id_phrase = $1;
		if ($id_phrase =~ /[02468]$/){
			print OUTPUT "</titre><description>";
			#print "phrase paire"
			}
		elsif ($id_phrase =~ /[13579]$/) {
			if ($id_phrase =~ /^1$/) {
				#print "phrase 1";
				print OUTPUT "<item><titre>"}
				
			else {print OUTPUT "</description></item><item><titre>"
			#print "phrase impaire"
			}
		}
	}
	
	
	# recuperation des informations importantes 
	if ($ligne=~/^([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t[^\t]*\t[^\t]*\t([^\t]*)\t([^\t]*)\t[^\t]*\t[^\t]*$/) {
		my $id=$1;
		my $string=$2;
		my $lemma=$3;
		my $type=$4;
		my $id_gov=$5;
		my $relation=$6;
		
		print OUTPUT "<element><data type=\"id\">$id</data><data type=\"string\">$string</data><data type=\"lemma\">$lemma</data><data type=\"type\">$type</data><data type=\"id_gov\">$id_gov</data><data type=\"rel\">$relation</data></element>\n";
	
	}

}	
close(INPUT);
print OUTPUT "</description>\n</item>\n</corpus>\n";
close(OUTPUT);
