#!usr/bin/perl
open my $FILE, "<:encoding(utf-8)", $ARGV[0]  ;
open my $OUT, ">:encoding(utf-8)", "nom_adj.txt" or die "Couldn't open: $!";

my @lignes=<$FILE>;
close $FILE;
while (my $ligne=shift(@lignes)) {
    chomp $ligne;
    my $sequence="";
    my $longueur=0;
    if ( $ligne =~ /<element><data type=\"type\">V<\/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\">NOM<\/data><data type=\"lemma\">[^<]+<\/data><data type=\"string\">([^<]+)<\/data><\/element>/) {
			my $forme=$1;
			$sequence.=" ".$forme;
			$longueur=2;
		}
    }
    if ($longueur == 2) {
	print $OUT "$sequence\n";
    }
}

close $OUT;
exit;
