use strict; use locale; my $fen_gauche=0; my $fen_droite=3; my $cat_cooc="(VER|NOM|ADV|ADJ)"; my (%antidico, %cooc, @cat_phrase, @lemme_phrase); if ( $#ARGV !=0 ) { die "Usage : ", $0, " texte_étiqueté\n"; } open( ANTIDICO,"<", "antidictionnaire.txt" ) or die "Impossible d'ouvrir antidictionnaire.txt : ", $!, "\n"; while ( my $ligne = ){ chomp $ligne; $antidico{$ligne} = 1; } close ANTIDICO; open ( TEXTE, "<", $ARGV[0] ) or die "Impossible d'ouvrir ",$ARGV[0], " : ", $!, "\n"; while ( my $ligne = ){ chomp $ligne; my ( $forme, $categorie, $lemme ) = split( /\t/, $ligne ); if ( $categorie ne "SENT" ) { push ( @lemme_phrase, $lemme ); push ( @cat_phrase, $categorie ); } else { for ( my $i=0; $i<=$#lemme_phrase; $i++ ) { my $pivot = $lemme_phrase[$i]; for (my $j=($i-$fen_gauche); $j<=($i+$fen_droite); $j++){ if ( ($j >= 0) and ($j <= $#lemme_phrase) and ($j != $i) and (not defined($antidico{$lemme_phrase[$j]})) and ($cat_phrase[$j] =~ /$cat_cooc/) ) { $cooc{$pivot}{$lemme_phrase[$j]}++; } } } @lemme_phrase=(); @cat_phrase=(); } } close TEXTE; print "Quel pivot ? (X pour finir) : "; my $pivot = ; chomp $pivot; while ( $pivot ne "X" ){ if ( defined ( $cooc{$pivot} ) ) { my %cooc_pivot = %{$cooc{$pivot}}; foreach my $cooccurrent ( sort { ($cooc_pivot{$b} <=> $cooc_pivot{$a}) or ($a cmp $b) } keys %cooc_pivot) { print $cooccurrent, "\t", $cooc_pivot{$cooccurrent},"\n"; } } else { print "\"",$pivot, "\" n'a pas de cooccurrents !\n"; } print "Quel pivot ? (X pour finir) : "; $pivot = ; chomp $pivot; }