open(FILE,"$ARGV[0]");

my @lignes=<FILE>;
close(FILE);
my %dicopatron=();
while (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 $deuxiemeligne=$lignes[1];
		if ( $deuxiemeligne =~ /<element><data type=\"type\">PRP<\/data><data type=\"lemma\">[^<]+<\/data><data type=\"string\">([^<]+)<\/data><\/element>/) {
			my $forme=$1;
			$sequence.=" ".$forme;
			$longueur=2;
			my $troisiemeligne=$lignes[3];
			if ( $troisiemeligne =~ /<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) {
		$dicopatron{$sequence}++; 
    }
}
foreach my $patron (sort {$dicopatron{$b} <=> $dicopatron{$a}} (keys %dicopatron)) {
	print "$patron : $dicopatron{$patron}\n";
}
