#/usr/bin/perl
open(FILE,"$ARGV[0]");
open (FILEOUT, ">sortie_sf_nomprpnom_tree.txt");
my @lignes=<FILE>;
close(FILE);
while (@lignes) {
    my $ligne=shift(@lignes);
	chomp $ligne;
    my $sequence="";
    my $longueur=0;
    if ( $ligne =~ /<element><data type=\"type\">NOM<\/data><data type=\"lemma\">[^<]+<\/data><data type=\"string\">([^<]+)<\/data><\/element>/) {
	my $forme=$1;
	 $sequence.=$forme;
	 $longueur=1;
	 my $nextligne=$lignes[0];
	 if ( $nextligne =~ /<element><data type=\"type\">PRP.*<\/data><data type=\"lemma\">[^<]+<\/data><data type=\"string\">([^<]+)<\/data><\/element>/) {
		   my $forme=$1;
	     $sequence.=" ".$forme;
	     $longueur=2;
		  my $nextligne=$lignes[1];
	 if ( $nextligne =~ /<element><data type=\"type\">NOM<\/data><data type=\"lemma\">[^<]+<\/data><data type=\"string\">([^<]+)<\/data><\/element>/) {
	     my $forme=$1;
	     $sequence.=" ".$forme;
	     $longueur=3;
	 }
	 }
	 
    }
    if ($longueur == 3) {
	print  FILEOUT "$sequence\n";
   	}
	}
	close(FILE);
	close(FILEOUT); 
	
