   my $file= shift;
    my $fileOut = shift;
    
    use POSIX qw(setlocale LC_ALL LC_CTYPE);
    
    # sauvegarde la "locale" initial
    my $old_locale = setlocale(LC_CTYPE);
    my $new_locale = setlocale(LC_CTYPE, "ISO-8859-1");
    $new_locale = setlocale(LC_CTYPE);
    
    use locale;
    

#-------------------------
# definitions de variables
#-------------------------
    
    my %listeMot = ();
    my %listePatron = ();

#-------------------------
# Partie 1
# A. ouverture du fichier des patrons : ce fichier contient sur chaque 
#    ligne une sequence : mot1 mot2
# B. dans la boucle while qui suit on va reperer pour chaque mot 
#  (a gauche du patron) l'ensemble des mots associés (a droite du precedent)
#  on cree ensuite un tableau indexe qui associe au mot de gauche la 
#  liste des mots associes
#  motgauche -> (motdroite-1,motdroite-2,...)
#  on n'ajoute qu'une seule occurrence des mots presents a droite mais 
#  on compte a frequence d'un patron donne dans un tableau de patron
#-------------------------

    
    open(F,"<$file");
    while (my $ligne=<F>) {
        $ligne=~/([\w]+)[^\w]+([\w]+)/; #"expression qui à posée problème."
        my $mot1=$1;
        my $mot2=$2;
        
        my $patron="$mot1\t$mot2";
        if (!(exists($listeMot{$mot1}))) {
            my @tmp=();
            push(@tmp, $mot2);
            $listeMot{$mot1}=\@tmp; # "principale difficulté de ce script : construction d'un référence vers un tableau."
            # print "FM : $listeMot{$mot1}\n";
            $listePatron{$patron}++;
        }
        else {
            my $tmp=$listeMot{$mot1};
            my @tmp2=@$tmp;
            if (!(grep(/$mot2/, @tmp2))) {
                push(@tmp2,$mot2);
            }
            $listeMot{$mot1}=\@tmp2; # idem
            #print "NM : $listeMot{$mot1}\n";
            $listePatron{$patron}++;
        }
    }
    close(F);



#-------------------------
# Partie 2
# A. Création du fichier de sortie et squelette minimal
# B. parcours du tableau des associations motgauche -> (motdroite-1,motdroite-2,...)
# pour chaque motgauche on crée un noeud du graphe idem pour chaque mot de la liste associée
# afin de ne pas créer de doublon on utilise un tableau contenant pour chaque mot son indice
# on vérifie dans ce tableau la présence ou non du mot à associer à un noeud
#-------------------------
    open (F,">$fileOut") || die "Echec open $fileOut $!\n";
    print F '<?xml version="1.0" encoding="iso-8859-1"?>', "\n",
    '<graphml>', "\n",
    ' <key id="d0" for="node" attr.name="forme" attr.type="string"/>', "\n",
    ' <key id="d1" for="edge" attr.name="frequence" attr.type="double"/>', "\n",
    ' <graph edgedefault="undirected">', "\n";
    
    my $id = 1;
    my %listeId = ();
    while (my ($mot, $liste) = each(%listeMot)) {
        my @tmp = @$liste; # ici, on "reconstruit" le tableau à partir de la référence
        #print "$mot\t@tmp\n";
        if ($mot !~/HASH/) {
            my $tmpID;
            if (!(exists($listeId{$mot}))) {
                print F " <node id=\"$id\"><data key=\"d0\">$mot</data></node>\n";
                $listeId{$mot}=$id;
                $tmpID=$id;
                $id++;
            }
            else {
                $tmpID=$listeId{$mot};
            }
            foreach my $cible (@tmp) {
                my $nbpatron=0;
                my $patron="$mot\t$cible";
                $nbpatron=$listePatron{$patron};
                if (!(exists($listeId{$cible}))) {
                    print F " <node id=\"$id\"><data key=\"d0\">$cible</data></node>\n";
                    $listeId{$cible}=$id;
                    print F " <edge source=\"$tmpID\" target=\"$id\"><data key=\"d1\">$nbpatron</data></edge>\n";
                    $id++;
                }
                else {
                    print F " <edge source=\"$tmpID\" target=\"$listeId{$cible}\"><data key=\"d1\">$nbpatron</data></edge>\n";
                }
            }
        }
    }
    print F " </graph>\n";
    print F "</graphml>\n";
    close(F);
    setlocale(LC_CTYPE, $old_locale);