IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage Perl Discussion :

comment trouver plusieurs mots dans un fichier text


Sujet :

Langage Perl

  1. #21
    Membre chevronné Avatar de dmganges
    Homme Profil pro
    Retraité. Ne recherche pas un emploi.
    Inscrit en
    Septembre 2011
    Messages
    1 392
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 71
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Retraité. Ne recherche pas un emploi.
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2011
    Messages : 1 392
    Points : 2 044
    Points
    2 044
    Par défaut
    @Lolo78
    C'est bien ce que j'avais compris !
    Lorsque j'arrive à 3h00 tu es déjà là, et je devine que tu ne viens pas de tomber du lit, vu le nombre de message auxquels tu as répondu entre 9h00 (la veille) & 3h00 !
    Je me demande quand tu dors.
    J'ai fait ça, mais il y a longtemps, un lit picot au pied de l'ordinateur pour les Jeux olympiques d'hiver en 1992 à Albertville

  2. #22
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2016
    Messages
    74
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2016
    Messages : 74
    Points : 67
    Points
    67
    Par défaut
    Bonsoir,
    Désolé pour le retard , j’ai bien testé les 2 derniers code
    Il y a deux choses qui m’échappe
    c’est cette ligne :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    my ( $FicDico, $LibInfoDico );
    	foreach my $InfoDico (@ListDico) {
    		chomp($InfoDico);
    		( $FicDico, $LibInfoDico ) = split /:/, $InfoDico;
    		my $PathDico = File::Spec->catfile( $RepBase, $FicDico );
    j ai pas saisie le role de chaque variable par exemple $InfoDico

    et cette ligne
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    foreach my $Elem (@TabMots) {
    		push @MotUnique, $Elem unless defined $Exist{$Elem};
    		$Exist{$Elem} = 1;
    	}
    Précisément
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    ........unless defined $Exist{$Elem};
    		$Exist{$Elem} = 1;
    Avarie dire après chaque conversation j’apprends pas mal choses

  3. #23
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2016
    Messages
    74
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2016
    Messages : 74
    Points : 67
    Points
    67
    Par défaut
    J’ai ajouté ces 2 lignes

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    $pourcentage_appr = sprintf( "%0.2f", $pourcentage_appr );
    pour prendre deux chiffres après la virgule
    et ctte ligne

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
     
    #@MotUnique = sort @MotUnique;
    #@MotUnique = sort  { $a cmp $b } @MotUnique;
    @MotUnique = sort { uc $a cmp uc $b or $a cmp $b } @MotUnique;
    Pour prendre en considération du majuscule -lors de trie des mots – (l'exemple younes_ESS.pl)

    Et un menu avce deux choix
    Le premier c’est le travaille habituelle
    2 choix on demande a l’utilisateur d’entrer le chemin de document pour faire le traitement (pour le traitement pas encore ) .


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
     
    #!/usr/bin/perl
    use strict;
    use warnings;
    use utf8;
    use File::Spec
      ;    # Permet une meilleure gestion des noms des chemins sous tous les OS
    use Data::Dumper qw(Dumper);
     
    #==============================================================================================
    # le but de ce tp est  de prendre 5 documents text
    #(contenat 5 domaine differents ) est les classifier selon leur domaine
    # pour une solusion on propopse de creer 5 dic contenant des termes specifique a chaque domaines
    # et calculer la distance entre chaque dic (vect de mots) et fichier text(vecteur de mots)
    # et enfin prendre la valeur maximal
    #================================================================================================
    ActiverAccents();
    menu();
    my $RepBase = 'D:\WorkSpace\eclips\perl_project_classification_doc';
     
    my $FicListDocs = File::Spec->catfile( $RepBase, 'FicListDocs.txt' );
    my $FicListDico = File::Spec->catfile( $RepBase, 'FicListDico.txt' );
     
    my $FicResultat  = File::Spec->catfile( $RepBase, 'Resultat.txt' );
    my $FicDeduction = File::Spec->catfile( $RepBase, 'Deduction.txt' );
    my $fh_Resul;
    my $fh_Deduc;
    open $fh_Resul, '>:utf8', $FicResultat
      or die("Impossible ouvrir $FicResultat \t$!");
    open $fh_Deduc, '>:utf8', $FicDeduction
      or die("Impossible ouvrir $FicDeduction \t$!");
     
    # Construction de @MotUnique contenant l'ensemble des mots de tous les dicos excepté les doublons
    my $fh_ListDico;
    open $fh_ListDico, '<:utf8', $FicListDico
      or die("Impossible ouvrir  $FicListDico \t$!");
    my @ListDico = <$fh_ListDico>;
    close $fh_ListDico;
     
    my @TabMots = ();
    my $fh_Dico;
    my ( %Exist, @MotUnique );
    foreach my $Dico (@ListDico) {
    	chomp($Dico);
     
    	my ( $FicDico, $LibInfoDico );
    	foreach my $InfoDico (@ListDico) {
    		chomp($InfoDico);
    		( $FicDico, $LibInfoDico ) = split /:/, $InfoDico;
    		my $PathDico = File::Spec->catfile( $RepBase, $FicDico );
    		open $fh_Dico, '<:utf8', $PathDico
    		  or die("Impossible ouvrir  $PathDico \t$!");
     
    	}
     
    	@TabMots = <$fh_Dico>;
    	close $fh_Dico;
    	chomp(@TabMots);
     
    	foreach my $Elem (@TabMots) {
    		push @MotUnique, $Elem unless defined $Exist{$Elem};
    		$Exist{$Elem} = 1;
    	}
    }
     
    #print "@MotUnique\n";
     
    my @nom_recuperer = ();
     
    my $fh_ListDocs;
    open $fh_ListDocs, '<:utf8', $FicListDocs
      or die("Impossible ouvrir  $FicListDocs \t$!");
    my @ListDocs = <$fh_ListDocs>;
    close $fh_ListDocs;
     
    ############################
     
    my $saisie;
    my $choice = "votre chois est  :";
    chomp( $saisie = <STDIN> );
     
    while ( $saisie != 3 ) {
    	if ( $saisie == 1 ) {
    		print "  votre choix est  $choice 1\n";
    		print "loading ...\n";
    		foreach my $Document (@ListDocs) {
    			chomp($Document);
    			print $fh_Resul "\n\n=============================================";
    			print $fh_Resul "Traitement du fichier $Document :\n\n";
    			my $In_Fic = File::Spec->catfile( $RepBase, $Document );
     
    			if ( -z $In_Fic ) {
    				print $fh_Resul
    				  "\t\tATTENTION le document $Document est VIDE !!!\n";
    				print $fh_Deduc
    				  "\t\tATTENTION le document $Document est VIDE !!!\n";
    			}
     
    			my $fh_Entree;
    			open $fh_Entree, '<:utf8', $In_Fic
    			  or die("Impossible ouvrir  $In_Fic \t$!");
     
    			my %Comptage = ();
    			my $NbLigne;
    			while ( my $Ligne = <$fh_Entree> ) {
    				$NbLigne++;
    				foreach my $Mot (@MotUnique) {
    					chomp $Mot;
    					if ( $Ligne =~ $Mot ) {
    						$Comptage{$Mot}++;
     
    						#print $fh_Resul  "$Mot a la ligne $NbLigne\n";
    					}
    				}
    			}
    			while ( my ( $Mot, $Nb ) = each(%Comptage) ) {
    				print $fh_Resul "Le mot '$Mot' est present $Nb fois\n";
     
    				#remplir les mots trouver dans le tableau[] nom_recuperer
    				push @nom_recuperer, $Mot;
    			}
     
    			#print $fh_Resul  "@nom_recuperer\t\n";
     
    			#comparer les mots avec tous les dico
    			print $fh_Deduc "\n\nDeduction :\n";
    			foreach my $Dico (@ListDico) {
    				my $pourcentage_appr = compare_with_dic( $Document, $Dico );
    				print $fh_Deduc "$Document est $Dico a $pourcentage_appr%\n";
    			}
     
    			close $fh_Entree;
    			undef %Comptage;
    			undef @nom_recuperer;
    		}
    		print "fin de traitement .\n";
    	}
    	if ( $saisie == 2 ) {
    		print "   $choice 2\n";
    		print "svp entrez le liens de votre document\n";
    		my $Doc_saisie;
    		chomp( $Doc_saisie = <STDIN> );
     
    		#if($rep=~/.*\.txt/){
    		open( INPUT, $Doc_saisie ) or die("Impossible ouvrir $Doc_saisie \t$!\n");
    		print "$Doc_saisie\n" ;
     
    	}
     
    	#}
    	if ( $saisie > 3 or $saisie < 0 ) {
    		print "Veuillez entre un numero valide\n";
     
    	}
    	chomp( $saisie = <STDIN> );
    }
    print "au revoir!\n
    \t**Nous agissons toujours pour satisfaire egoistement\n\t notre plaisir, sinon nous ne ferions rien !**";
    close $fh_Resul;
    close $fh_Deduc;
     
    ################################################################
     
    sub compare_with_dic {
    	my ( $Document, $Dico ) = @_;
    	print $fh_Resul "\n\nComparaison de $Document avec $Dico\n ";
    	my $count = 0;
    	my %hash;
    	@hash{@nom_recuperer} = 0 .. $#nom_recuperer;
     
    	my ( $FicDico, $LibInfoDico );
    	foreach my $InfoDico (@ListDico) {
    		chomp($InfoDico);
    		( $FicDico, $LibInfoDico ) = split /:/, $InfoDico;
    		my $PathDico = File::Spec->catfile( $RepBase, $FicDico );
    		open $fh_Dico, '<:utf8', $PathDico
    		  or die("Impossible ouvrir  $PathDico \t$!");
     
    	}
    	my @TabMots = <$fh_Dico>;
    	close $fh_Dico;
    	chomp(@TabMots);
    	my $NbDico = scalar(@TabMots);
     
    	if ($NbDico) {
    		for my $val (@TabMots) {
    			chomp $val;
    			if ( exists $hash{$val} ) {
    				print $fh_Resul
    "Le mot $val est present dans $Dico   la position $hash{$val}.\n";
    				$count += 1;
    			}
    			else {
    				print $fh_Resul "---->$val n'est pas dans $Dico.\n";
    			}
    		}
    		my $pourcentage_appr = ( $count * 100 ) / $NbDico;
    		$pourcentage_appr = sprintf( "%0.2f", $pourcentage_appr );
    		print $fh_Resul
    "\nLe nombre de mots du fichier $Document presents dans le $Dico  est $count  ===>
    		le pourcentage par raport au $Dico = $pourcentage_appr %";
    		return $pourcentage_appr;
     
    	}
    	else {
    		print $fh_Resul "\n\t\tATTENTION $Dico est VIDE !!!\n";
    		print $fh_Deduc "\n\t\tATTENTION $Dico est VIDE !!!\n";
    		return 0;
    	}
     
    }
     
    sub menu {
    	printf("\t\t\t***********************************\n");
    	printf("\t\t\t**     PERL programing           **\n");
    	printf("\t\t\t***********************************\n");
    	printf("\t\t\t       Developper.com               \n");
    	printf("\t\t\t***********************************\n");
    	printf("\t\t\t\t****   MENU   ****\n");
    	printf("\t\t\t1- Lancez la classification \n");
    	printf("\t\t\t2- Classifier un document\n");
    	printf("\t\t\t3- EXIT\n");
    	printf("\t\t\t***********************************\n");
     
    }
     
    #==============================================================
    # Pour avoir les accents sur la console DOS
    # http://perl.developpez.com/faq/perl/?page=Terminal#AccentsDOS
    #==============================================================
    sub ActiverAccents {
    	my $encodage;
     
    	# Windows
    	if ( lc($^O) eq 'mswin32' ) {
    		eval {
    			my ($codepage) = ( `chcp` =~ m/:\s+(\d+)/ );
    			$encodage = "cp$codepage";
    			foreach my $h ( \*STDOUT, \*STDERR, \*STDIN, ) {
    				binmode $h, ":encoding($encodage)";
    			}
    		};
    	}
    	else {
    		$encodage = `locale charmap`;
    		eval {
    			foreach my $h ( \*STDOUT, \*STDERR, \*STDIN, ) {
    				binmode $h, ":encoding($encodage)";
    			}
    		};
    	}
    	return $encodage;
    }
     
    #Sinon :
    #ü 	\x81 	à 	\x85 	è 	\x8A
    #é 	\x82 	ç 	\x87 	ï 	\x8B
    #â 	\x83 	ê 	\x88 	î 	\x8C
    #ä 	\x84 	ë 	\x89

    ***********************************
    ** PERL programing **
    ***********************************
    Developper.com
    ***********************************
    **** MENU ****
    1- Lancez la classification
    2- Classifier un document
    3- EXIT
    ***********************************
    1
    votre choix est votre chois est : 1
    loading ...
    fin de traitement .
    2
    votre chois est : 2
    svp entrez le liens de votre document
    D:\WorkSpace\eclips\perl_project_classification_doc\test.txt
    D:\WorkSpace\eclips\perl_project_classification_doc\test.txt
    3
    au revoir!

    **Nous agissons toujours pour satisfaire egoistement
    notre plaisir, sinon nous ne ferions rien !**
    Merci

  4. #24
    Membre chevronné Avatar de dmganges
    Homme Profil pro
    Retraité. Ne recherche pas un emploi.
    Inscrit en
    Septembre 2011
    Messages
    1 392
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 71
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Retraité. Ne recherche pas un emploi.
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2011
    Messages : 1 392
    Points : 2 044
    Points
    2 044
    Par défaut
    Citation Envoyé par younes2727 Voir le message
    Bonsoir,
    Désolé pour le retard
    Il n'y a pas de retard !
    La terre tourne toujours à la même vitesse

    Citation Envoyé par younes2727 Voir le message
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    my ( $FicDico, $LibInfoDico );
    	foreach my $InfoDico (@ListDico) {
    		chomp($InfoDico);
    		( $FicDico, $LibInfoDico ) = split /:/, $InfoDico;
    		my $PathDico = File::Spec->catfile( $RepBase, $FicDico );
    j ai pas saisie le role de chaque variable par exemple $InfoDico
    Ça c'est le bout de code que j'avais écrit le matin à la va vite...
    Dans l'après-midi, le soleil faisant défaut, je l'ai corrigé dans le #19
    avec FicListDico_ESS.txt =
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    DicoEth.txt:Éthique selon:Spinoza:Nietzsche:
    DicoAnt.txt:Anthropologique selon:Darwin:les néodarwiniens:
    DicoVid.txt:Vide selon la théorie des ensembles: :
    DicoPol.txt:Politique, AU SENS NOBLE DU TERME ☺, selon:Nicolas Machiavel:Bernard de Mandeville:Charles Louis de Secondat, baron de La Brède et de Montesquieu:Hannah Arendt:
    En fait il s'agissait de te monter que le fichier pouvait/devait contenir toutes les informations nécessaires pour peaufiner les libellés... comme dans le #15

    Après c'est toujours le même principe :
    Chaque cellule du tableau @ListDico contient une ligne du fichier FicListDico_ESS.txt
    On découpe le tableau avec le foreach
    Mais dans chaque $InfoFicDico, on à une ligne complète du fichier (une cellule du tableau)
    Il faut donc découper $InfoFicDico avec split
    On voit que chaque ligne du fichier contient au début DEUX informations unitaires :
    1) Le nom du dictionnaire,
    2) Un libellé
    Le tout suivi d'information qui se répètent : les noms de plusieurs auteurs éventuels.
    Le split découpe la ligne à chaque :
    - première info dans $NomFicDico,
    - deuxième info dans $LibInfoDico,
    - et tout le reste dans un tableau @Auteurs Dans lequel on viendra éventuellement puiser par la suite l'information souhaitée pour construire le libellé du fichier Deduction.txt.
    Ainsi pour chaque 'dictionnaire' on peut avoir Zéro à plusieurs intervenants.
    Mais tout ça dépend de ce que tu veux afficher...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
     
    my @TabMots = ();
    my $fh_FicDico;
    my (%Exist, @MotUnique);
    foreach my $InfoFicDico (@ListDico) {
    	chomp ($InfoFicDico);
    	my ( $NomFicDico, $LibInfoDico, @Auteurs ) = split /:/,$InfoFicDico;
    	my $PathDico = File::Spec->catfile( $RepBase, $NomFicDico );
    	open $fh_FicDico , '<:utf8', $PathDico
    		or die("Impossible ouvrir  $PathDico \t$!");
    	@TabMots = <$fh_FicDico>;
    	close $fh_FicDico;
    	chomp (@TabMots);
     
    	foreach my $Elem ( @TabMots ) {
         push @MotUnique, $Elem unless defined $Exist{$Elem} ;
         $Exist{$Elem} = 1;
    	}
    	print $fh_Resul "\n\nINFO sur Dico '$NomFicDico' : $LibInfoDico $Auteurs[0]\n";
    	print $fh_Resul "OU\nINFO sur Dico '$NomFicDico' : $LibInfoDico @Auteurs\n";
    	print $fh_Resul "OU\nINFO sur Dico '$NomFicDico' : $LibInfoDico ". join (" & ",@Auteurs);
    }






    Citation Envoyé par younes2727 Voir le message
    et cette ligne
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    foreach my $Elem (@TabMots) {
    		push @MotUnique, $Elem unless defined $Exist{$Elem};
    		$Exist{$Elem} = 1;
    	}
    Précisément
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    ........unless defined $Exist{$Elem};
    		$Exist{$Elem} = 1;
    On push $Elem dans @MotUnique seulement si $Elem n'est pas vide (defined) et si $Elem existe plusieurs fois dans le tableau, on ne le fait que la première fois qu'on le rencontre.

    Il y a pas mal de façon d'écrire ça !
    Regarde par ici et choisi celle qui te va le mieux !

    Bon je me fais un café et je regarde le #23

  5. #25
    Membre chevronné Avatar de dmganges
    Homme Profil pro
    Retraité. Ne recherche pas un emploi.
    Inscrit en
    Septembre 2011
    Messages
    1 392
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 71
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Retraité. Ne recherche pas un emploi.
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2011
    Messages : 1 392
    Points : 2 044
    Points
    2 044
    Par défaut
    Réponse au #23

    Je ne comprends pas ce que tu veux faire avec :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    print "   $choice 2\n";
    		print "svp entrez le liens de votre document\n";
    		my $Doc_saisie;
    		chomp( $Doc_saisie = <STDIN> );
     
    		#if($rep=~/.*\.txt/){
    		open( INPUT, $Doc_saisie ) or die("Impossible ouvrir $Doc_saisie \t$!\n");
    		print "$Doc_saisie\n" ;
    Pour que ça fonctionne avec le menu que j'ai un peu modifié, j'ai sorti çà :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    #!/usr/bin/perl
    use strict;
    use warnings;
    use utf8;
    use File::Spec;									   # Permet une meilleure gestion des noms des chemins sous tous les OS
    use Data::Dumper qw(Dumper);
     
    #==============================================================================================
    # le but de ce tp est  de prendre 5 documents text
    #(contenat 5 domaine differents ) est les classifier selon leur domaine
    # pour une solusion on propopse de creer 5 dic contenant des termes specifique a chaque domaines
    # et calculer la distance entre chaque dic (vect de mots) et fichier text(vecteur de mots)
    # et enfin prendre la valeur maximal
    #================================================================================================
    ActiverAccents();
     
     
     
    my $choice = menu();
     
     
     
    my $RepBase = 'E:/_SITE/FondsDocumentaire/Spinoza';
     
    my $FicListDocs = File::Spec->catfile( $RepBase, 'FicListDocs.txt' );
    my $FicListDico = File::Spec->catfile( $RepBase, 'FicListDico.txt' );
     
    my $FicResultat  = File::Spec->catfile( $RepBase, 'Resultat.txt' );
    my $FicDeduction = File::Spec->catfile( $RepBase, 'Deduction.txt' );
    my $fh_Resul;
    my $fh_Deduc;
    open $fh_Resul, '>:utf8', $FicResultat 	or die("Impossible ouvrir $FicResultat \t$!");
    open $fh_Deduc, '>:utf8', $FicDeduction 	or die("Impossible ouvrir $FicDeduction \t$!");
     
    # Construction de @MotUnique contenant l'ensemble des mots de tous les dicos excepté les doublons
    my $fh_ListDico;
    open $fh_ListDico, '<:utf8', $FicListDico
      	or die("Impossible ouvrir  $FicListDico \t$!");
    my @ListDico = <$fh_ListDico>;
    close $fh_ListDico;
     
    my @TabMots = ();
    my $fh_Dico;
    my (%Exist, @MotUnique);
    foreach my $Dico (@ListDico) {
    	chomp ($Dico);
    	my $PathDico = File::Spec->catfile( $RepBase, $Dico );
    	open $fh_Dico , '<:utf8', $PathDico
    		or die("Impossible ouvrir  $PathDico \t$!");
    	@TabMots = <$fh_Dico>;
    	close $fh_Dico;
    	chomp (@TabMots);
     
    	foreach my $Elem ( @TabMots ) {
         push @MotUnique, $Elem unless defined $Exist{$Elem} ;
         $Exist{$Elem} = 1;
    	}
    }
    #print "@MotUnique\n";
     
     
    my @nom_recuperer = ();
     
    if ( $choice eq 1 ) {
    	classification (\@MotUnique);
    }
     
    if ( $choice eq 2 ) {
    	print "Je ne comprends pas ce que tu veux faire avec le bout de code qui suit :(\n";
     
    =pod
    print "   $choice 2\n";
    		print "svp entrez le liens de votre document\n";
    		my $Doc_saisie;
    		chomp( $Doc_saisie = <STDIN> );
     
    		#if($rep=~/.*\.txt/){
    		open( INPUT, $Doc_saisie ) or die("Impossible ouvrir $Doc_saisie \t$!\n");
    		print "$Doc_saisie\n" ;
    =cut
    }
     
    if ( $choice eq 3 ) {
    	exit(0);
    }
     
     
    sub classification {
    	my $fh_ListDocs;
    	open $fh_ListDocs, '<:utf8', $FicListDocs
      		or die("Impossible ouvrir  $FicListDocs \t$!");
    	my @ListDocs = <$fh_ListDocs>;
    	close $fh_ListDocs;
     
    	foreach my $Document (@ListDocs) {
    		chomp ($Document);
    		print $fh_Resul  "\n\n=============================================";
    		print $fh_Resul  "Traitement du fichier $Document :\n\n";
    		my $In_Fic = File::Spec->catfile( $RepBase, $Document );
     
    		if ( -z $In_Fic ) {
    			print $fh_Resul "\t\tATTENTION le document $Document est VIDE !!!\n";
    			print $fh_Deduc "\t\tATTENTION le document $Document est VIDE !!!\n";
    		}
     
    		my $fh_Entree;
    		open $fh_Entree, '<:utf8', $In_Fic
      		or die("Impossible ouvrir  $In_Fic \t$!");
     
    		my %Comptage = ();
    		my $NbLigne;
    		while ( my $Ligne = <$fh_Entree> ) {
    			$NbLigne++;
    			foreach my $Mot (@MotUnique) {
    				chomp $Mot;
    				if ( $Ligne =~ $Mot ) {
    					$Comptage{$Mot}++;
    					#print $fh_Resul  "$Mot a la ligne $NbLigne\n";
    				}
    			}
    		}
     
    		while ( my ( $Mot, $Nb ) = each(%Comptage) ) {
    			print $fh_Resul  "Le mot '$Mot' est present $Nb fois\n";
     
    			#remplir les mots trouver dans le tableau[] nom_recuperer
    			push @nom_recuperer, $Mot;
    		}
    		#print $fh_Resul  "@nom_recuperer\t\n";
     
    		#comparer les mots avec tous les dico
    		print $fh_Deduc  "\n\nDéduction :\n";
    		foreach my $Dico (@ListDico) {
    			my $pourcentage_appr = compare_with_dic($Document, $Dico);
    			print $fh_Deduc  "$Document est $Dico à $pourcentage_appr%\n";
    		}
     
    		close $fh_Entree;
    		undef %Comptage;
    		undef @nom_recuperer;
    	}
    	print "au revoir!\n
    \t**Par perfection et par réalité j'entends la même chose**";
    	close $fh_Resul;
    	close $fh_Deduc;
    }
     
     
     
    ################################################################
     
    sub compare_with_dic {
    	my ( $Document, $Dico ) = @_;
    	print $fh_Resul  "\n\nComparaison de $Document avec $Dico\n ";
    	my $count = 0;
    	my %hash;
    	@hash{@nom_recuperer} = 0 .. $#nom_recuperer;
     
    	my $PathDico = File::Spec->catfile( $RepBase, $Dico );
    	open $fh_Dico , '<:utf8', $PathDico
    		or die("Impossible ouvrir  $PathDico \t$!");
    	my @TabMots = <$fh_Dico>;
    	close $fh_Dico;
    	chomp (@TabMots);
     	my $NbDico = scalar(@TabMots);
     
    	if ($NbDico) {
    		for my $val (@TabMots) {
    			chomp $val;
    			if ( exists $hash{$val} ) {
    				print $fh_Resul  "Le mot $val est présent dans $Dico   la position $hash{$val}.\n";
    				$count += 1;
    			} else {
    				print $fh_Resul  "---->$val n'est pas dans $Dico.\n";
    			}
    		}
    		my $pourcentage_appr = ( $count * 100 ) / $NbDico;
    		print $fh_Resul  "\nLe nombre de mots du fichier $Document présents dans le $Dico  est $count  ===>
    		le pourcentage par raport au $Dico = $pourcentage_appr %";
    		return $pourcentage_appr;
     
    	} else {
    		print $fh_Resul  "\n\t\tATTENTION $Dico est VIDE !!!\n";
    		print $fh_Deduc  "\n\t\tATTENTION $Dico est VIDE !!!\n";
    		return 0;
    	}
     
    }
     
    sub menu {
    	print("\t\t\t***********************************\n");
    	print("\t\t\t**     PERL programing           **\n");
    	print("\t\t\t***********************************\n");
    	print("\t\t\t       Developper.com               \n");
    	print("\t\t\t***********************************\n");
    	print("\t\t\t\t****   MENU   ****\n");
    	print("\t\t\t1- Lancez la classification \n");
    	print("\t\t\t2- Classifier un document\n");
    	print("\t\t\t3- EXIT\n");
    	print("\t\t\t***********************************\n");
     
    	while (my $choice = <STDIN>) {
    		chomp( $choice );
    		if ( $choice eq 1 || $choice eq 2 || $choice eq 3 ) {
    			print "Votre choix est : $choice\n";
    			return ($choice);
    		} else {
    			print "Veuillez entre un numero valide\n";
    		}
    	}
    }
     
     
    #==============================================================
    # Pour avoir les accents sur la console DOS
    # http://perl.developpez.com/faq/perl/?page=Terminal#AccentsDOS
    #==============================================================
    sub ActiverAccents {
    	my $encodage;
     
    	# Windows
    	if ( lc($^O) eq 'mswin32' ) {
    		eval {
    			my ($codepage) = ( `chcp` =~ m/:\s+(\d+)/ );
    			$encodage = "cp$codepage";
    			foreach my $h ( \*STDOUT, \*STDERR, \*STDIN, ) {
    				binmode $h, ":encoding($encodage)";
    			}
    		};
    	}
    	else {
    		$encodage = `locale charmap`;
    		eval {
    			foreach my $h ( \*STDOUT, \*STDERR, \*STDIN, ) {
    				binmode $h, ":encoding($encodage)";
    			}
    		};
    	}
    	return $encodage;
    }
     
    #Sinon :
    #ü 	\x81 	à 	\x85 	è 	\x8A
    #é 	\x82 	ç 	\x87 	ï 	\x8B
    #â 	\x83 	ê 	\x88 	î 	\x8C
    #ä 	\x84 	ë 	\x89
    Mais ce n'est pas très cohérent,
    pour que ça fonctionne vite fait je suis obligé de passer le tableau @MotUnique par référence à la fonction classification (Si c'est que tu veux faire)...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    if ( $choice eq 1 ) {
    	classification (\@MotUnique);
    }
    En faisant au coup par coup on est en train de s'embourber

    Avant de coder bille en tête, il faut faire une analyse, au moins succincte, du genre :

    L'utilisateur pourra choisir entre 3 possibilités :
    1 - classification
    2 -
    3 - sortir

    Où chaque possibilité correspondra à une fonction indépendante, facile à maintenir par la suite

    Ensuite, dans 1 - classification, il se passera :
    - et patati
    - et patata
    - ...
    Pour éventuellement faire d'autres sous fonctions indépendantes...

    Je vois que tu commences à apprécier la philo, je me régale
    إلى اللقاء

  6. #26
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2016
    Messages
    74
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2016
    Messages : 74
    Points : 67
    Points
    67
    Par défaut
    Rein a dire ,"Making the simple complicated is commonplace; making the complicated simple, awesomely simple, that's creativity."-Charles Mingus- un chapeau

    dmganges
    Réponse au #23

    Je ne comprends pas ce que tu veux faire avec :
    Code :
    Oui pour la partie deux j'ai voulu faire la même chose que la première partie mais cette fois ci la classification sera avec le document saisie par l'utilisateur
    j'ai essayé de passer le tableau $doc_saisie par référence à la fonction classification : ( !!! )

    Je vois que tu commences à apprécier la philo, je me régale
    Vraiment tu m’as donné l’envie; de plus J'aime les mots qui ont une connotation profonde et mystérieuse



    -هناك أوقات نشعر فيها أنها النهاية ثم نكتشف أنها البداية و هناك أبواب نشعر بأنها مغلقة ثم نكتشف أنها المدخل الحقيقي''

  7. #27
    Membre chevronné Avatar de dmganges
    Homme Profil pro
    Retraité. Ne recherche pas un emploi.
    Inscrit en
    Septembre 2011
    Messages
    1 392
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 71
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Retraité. Ne recherche pas un emploi.
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2011
    Messages : 1 392
    Points : 2 044
    Points
    2 044
    Par défaut
    Bonjour si tu tombes du lit comme moi, ce qui m'étonnerait, ou
    Bonsoir si tu veilles tard comme Lolo78

    Ne me colle pas trop d'arabe, je ne maîtrise pas, j'ai besoin de gros dico
    Ni trop d'anglais, en fait je suis nul en langue et pas seulement en langue
    Ceci dit, je vis exactement la citation d'Abrahim Feki.
    En vieillissant je découvre encore !
    Vieux ont n'hésite pas à s'aventurer sur des passerelles instables, on n'a plus rien à craindre et donc plus rien à espérer.
    Car "il n'y a pas d'Espoir sans Crainte ni de Crainte sans Espoir" E3DA15Exp
    Jeunes on préfère les autoroutes, et c'est bien ainsi.
    Il y a des choses qu'il vaut mieux ne pas connaître trop jeune, car cela ruinerait la vie, l'envie de créer... et donc l'évolution.
    La Nature "veille" égoïstement sur ses propres intérêts avec une efficacité redoutable, déjà en faisant que la philo (trop réfléchir) rebute les plus jeunes
    Cette perfection innée de la Nature est époustouflante !

    Bon j'arrête, sinon...
    Sans plus d'info c'est difficile pour moi :
    j'ai essayé de passer le tableau $doc_saisie par référence à la fonction classification : ( !!! )
    Ce que j'ai collé, n'est pas beau, c'est à reprendre, mais ça fonctionne.
    Creuse un peu ou donne plus d'info !

  8. #28
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2016
    Messages
    74
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2016
    Messages : 74
    Points : 67
    Points
    67
    Par défaut
    Bonsoir, oui j'ai couché tard (mais s’arrivera jamais après une journée très longue )

    Vieux ont n'hésite pas à s'aventurer sur des passerelles instables, on n'a plus rien à craindre et donc plus rien à espérer.
    Car "il n'y a pas d'Espoir sans Crainte ni de Crainte sans Espoir" E3DA15Exp
    Jeunes on préfère les autoroutes, et c'est bien ainsi.
    Il y a des choses qu'il vaut mieux ne pas connaître trop jeune, car cela ruinerait la vie, l'envie de créer... et donc l'évolution.
    Ah en lisant le message , j’ai constaté que suis face a un philosophe qui a de l’expérience dans le terrain , je suis d’accord avec vous ….

    Making the simple complicated is commonplace; making the complicated simple, awesomely simple, that's creativity.
    –dans ce sens –

    En compliquant une chose simple c’est banal et commun entre les gens ; mais Rendant une chose qui semble simple mais dedans compliqué, en une chose étonnamment simple, c'est la créativité.
    J’ai voulu dire qu’ tu m’as bien explique le code Merci a vous



    هناك أوقات نشعر فيها أنها النهاية ثم نكتشف أنها البداية و هناك أبواب نشعر بأنها مغلقة ثم نكتشف أنها المدخل الحقيقي
    Il y a des moment là où on sent que c’est la fin mais on découvre que c’est juste le début de long chemin ,et il y a des Portes qui paraissent fermés et impossible de l’ouvrir et après on découvre qu’elles sont le meilleur et véritable issu –dans ce sens –

    Je vais essayer encore concernent le deuxième choix.
    السلام عليكم

  9. #29
    Membre chevronné Avatar de dmganges
    Homme Profil pro
    Retraité. Ne recherche pas un emploi.
    Inscrit en
    Septembre 2011
    Messages
    1 392
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 71
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Retraité. Ne recherche pas un emploi.
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2011
    Messages : 1 392
    Points : 2 044
    Points
    2 044
    Par défaut
    Merci pour les traductions, c'est à peu près le sens que j'avais trouvé

    Citation Envoyé par younes2727 Voir le message
    Je vais essayer encore concernent le deuxième choix
    Bonne continuation !
    السلام عليكم

    Absent aujourd'hui

  10. #30
    Membre chevronné Avatar de dmganges
    Homme Profil pro
    Retraité. Ne recherche pas un emploi.
    Inscrit en
    Septembre 2011
    Messages
    1 392
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 71
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Retraité. Ne recherche pas un emploi.
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2011
    Messages : 1 392
    Points : 2 044
    Points
    2 044
    Par défaut
    Bonjour, ça fait 2 jours qu'il pleut, j'ai dû meubler :
    Tu ne préfèrerais pas proposer une interface plus sympa que ce permet l'invite de commande ?

    Config.ini :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    [GLOBAL]
    Debug: 1
    Resultat: 1
    Deduction: 1
    FicLog: Younes.log
    FicResul: Resultat.txt
    FicDeduc: Deduction.txt
     
    [DOCU]
    Rep: Documents
    Fic: E:/_DEV/_Younes/Documents/ETH.txt E:/_DEV/_Younes/Documents/TRE.txt E:/_DEV/_Younes/Documents/TTP.txt
     
    [DICO]
    Rep: Dictionnaires
    Fic: E:/_DEV/_Younes/Dictionnaires/DicoAnt.txt E:/_DEV/_Younes/Dictionnaires/DicoEth.txt E:/_DEV/_Younes/Dictionnaires/DicoPol.txt
     
    [DEDU]
    DicoAnt.txt: est anthropologique
    DicoEth.txt: est éthique
    DicoPol.txt: est politique
    DicoVid.txt: est VIDE
    Younes_Tk.pl :
    [Edit 07:30]Ajout d'un évènement Bind pour effacer le message sur 1 clic gauche de la souris :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    855
    856
    857
    858
    859
    860
    861
    862
    863
    864
    865
    866
    867
    868
    869
    870
    871
    872
    873
    874
    875
    876
    877
    878
    879
    880
    881
    882
    883
    884
    885
    886
    887
    888
    889
    890
    891
    892
    893
    894
    895
    896
    897
    898
    899
    900
    901
    902
    903
    904
    905
    906
    907
    908
    909
    910
    911
    912
    913
    914
    915
    916
    917
    918
    919
    920
    921
    922
    923
    924
    925
    926
    927
    928
    929
    930
    931
    932
    933
    934
    935
    936
    937
    938
    939
    940
    941
    942
    943
    944
    945
    946
    use strict;
    use warnings;
    use utf8;
    use Tk;																		# Interface graphique
    use Tk::LabFrame;													# Pour utiliser LabFrame
    use Tk::ROText;														# Pour mettre un widget en lecture seule
    use File::Spec;														# Permet une meilleure gestion des noms des chemins sous tous les OS.
    use Config::Std;													# Lecture/ecriture d'un fichier .ini
    use File::Basename;												# Pour récupérer le nom du fichier sans le path complet
     
    # Initialisation de variables
    my $RepBase = 'E:/_DEV/_Younes';
     
    # Lecture du fichier de configuration
    my $fichier_configuration = File::Spec->catfile( $RepBase, 'config.ini' );
    my %config;
    if ( -e $fichier_configuration ) {
      read_config $fichier_configuration => %config;
    }
    else {
      %config = (
        'GLOBAL'    => {
        	Resultat  => 1,
    			Deduction => 1,
          Debug     => 1,
    			FicLog    => 'Younes.log',
    			FicResul  => 'Resultat.txt',
    			FicDeduc  => 'Deduction.txt',
        },
        'DOCU' => {
        	Rep  => 'Docu',
        	Fic  => 'ETH.txt',
        },
        'DICO' => {
        	Rep  => 'Dico',
        	Fic  => 'DicoEth.txt',
        }
      );
    }
     
    my ( $FicDebug, $fh_Debug, $Choix_Debug ) = ();
    $Choix_Debug = $config{GLOBAL}{Debug};
     
    my $Choix_Fichier_Resultat  = $config{GLOBAL}{Resultat};
    my $Choix_Fichier_Deduction = $config{GLOBAL}{Deduction};
    my $FicResultat  = File::Spec->catfile( $RepBase, $config{GLOBAL}{FicResul} );
    my $FicDeduction = File::Spec->catfile( $RepBase, $config{GLOBAL}{FicDeduc} );
    my $fh_Resul;
    my $fh_Deduc;
     
    my ( $LabRepDocu, $LabRepDico, $MsgErreur, ) = ();
    my @nom_recuperer = ();
    my $Stop ='';
     
    my $RepDocu = File::Spec->catfile( $RepBase, $config{DOCU}{Rep} );
    my $RepDico = File::Spec->catfile( $RepBase, $config{DICO}{Rep} );
    my @PathsDocu = split ( / /, $config{DOCU}{Fic} );
    my @PathsDico = split ( / /, $config{DICO}{Fic} );
     
    # Création d'une fenêtre bidon pour récupérer les dimensions de l'écran
    my $fen  = MainWindow->new;
    my $width = $fen->screenwidth();
    my $height = $fen->screenheight();
    $fen->destroy();
     
    # Creation du widget principal
    my $Wm = MainWindow->new(
    	-width			=> $width,
    	-height			=> $height,
      -background => 'white',
    );
     
    $width = $Wm->screenwidth*(4/5);
    $height = $Wm->screenheight*(4/5);
    $Wm->configure(-height=>$height, -width=>$width, -title=>"Younes");
    $Wm->geometry( $width ."x". $height );
    $Wm->MoveToplevelWindow (100,100);
    #$Wm->overrideredirect(1);
    #$Wm->packPropagate(0);
    #$Wm->raise();
     
    # Invalidation fermeture -> obligation de passer par exit
    $Wm->protocol( "WM_DELETE_WINDOW", sub {
    	fermer_application($Wm, $fichier_configuration, \%config);
    } );
     
     
    ####################################
    # Interface graphique
    my $couleur_commune = '#E0F0FF';
     
    ####################################
    # Cadre pour les messages de service
    my $cadre_messages = $Wm->Frame( -background => $couleur_commune, );
     
    # Label qui affichera les messages concernant les documents
    my $label_documents = $cadre_messages->Label(
      -textvariable => \$LabRepDocu,
      -background   => '#FFE0D0',
      -relief       => 'groove',
    );
     
    # Label qui affichera les messages concernant les dictionnaires
    my $label_dictionnaires = $cadre_messages->Label(
      -textvariable => \$LabRepDico,
      -background   => '#FFE0D0',
      -relief       => 'groove',
    );
     
    # Label qui affichera les messages d'erreur
    my $label_msg_erreur = $cadre_messages->Label(
      -textvariable => \$MsgErreur,
      -background   => '#FFE0D0',
      -relief       => 'groove',
    );
     
     
    #################
    # Cadre résultats
    my $cadre_Resultats = $Wm->Frame();
    my $LabFrame_Resultats = $cadre_Resultats->LabFrame(
      -label       => 'Résultats',
      -background  => '#DCDCDC',
      -font        => '{Simplified Arabic} 10 {bold}',
    );
     
    # Scrolled qui affiche les résultats
    my $widget_Resultats = $LabFrame_Resultats->Scrolled(
      'ROText',
      -scrollbars => 'e',
      -takefocus  => 0,
      -wrap       => 'word',
      -background => '#ABFAA3',
    );
    configurer_tags($widget_Resultats);
     
    # Label pour les déductions
    my $LabFrame_Deductions = $cadre_Resultats->LabFrame(
      -label       => 'Déductions',
      -background  => '#DCDCDC',
      -font        => '{Simplified Arabic} 10 {bold}',
    );
     
    # Scrolled qui affiche les déductions
    my $widget_Deductions = $LabFrame_Deductions->Scrolled(
      'ROText',
      -scrollbars => 'e',
      -takefocus  => 0,
      -wrap       => 'word',
      -background => '#ABFAA3',
    );
    configurer_tags($widget_Deductions);
     
     
    #################
    # Cadre des paths
    my $cadre_Paths = $Wm->Frame( -background => $couleur_commune, );
     
    ###########
    # Documents
    # Label pour les paths des documents
    my $LabFrame_Documents = $cadre_Paths->LabFrame(
      -label       => 'Documents',
      -background  => '#DCDCDC',
      -font        => '{Simplified Arabic} 10 {bold}',
    );
     
    # Scrolled qui affiche les paths des documents
    my $widget_Documents = $LabFrame_Documents->Scrolled(
      'ROText',
      -scrollbars => 'e',
      -takefocus  => 0,
      -wrap       => 'word',
      -background => '#FFE0D0',
    );
    configurer_tags($widget_Documents);
     
    # Remplissage de $widget_Documents avec les infos du fichiers config.ini
    foreach my $PathDocu (@PathsDocu) {
    	$widget_Documents->insert( 'end', "$PathDocu\n", "g12" );
    }
     
     
    ###############
    # Dictionnaires
    # Label pour les paths des dictionnaires
    my $LabFrame_Dictionnaires = $cadre_Paths->LabFrame(
      -label       => 'Dictionnaires',
      -background  => '#DCDCDC',
      -font        => '{Simplified Arabic} 10 {bold}',
    );
     
    # Scrolled qui affiche les paths des dictionnaires
    my $widget_Dictionnaires = $LabFrame_Dictionnaires->Scrolled(
      'ROText',
      -scrollbars => 'e',
      -takefocus  => 0,
      -wrap       => 'word',
      -background => '#FFE0D0',
    );
    configurer_tags($widget_Dictionnaires);
     
    # Remplissage de $widget_Dictionnaires avec les infos du fichiers config.ini
    foreach my $PathDico (@PathsDico) {
    	$widget_Dictionnaires->insert( 'end', "$PathDico\n", "g12" );
    }
     
     
    ###################################################
    # Cadre du haut Documents - Dictionnaires - Gestion
     
    #==================================================
    # Label pour les documents
    my $Frame_Documents = $Wm->LabFrame(
      -label      => 'Documents',
      -background => $couleur_commune,
      -font       => '{Simplified Arabic} 10 {bold}',
    );
     
    # Bouton effacer documents
    my $bouton_EffDocu = $Frame_Documents->Button(
    	-text => "Efface",
    	-command => sub {
    		$widget_Documents->delete( '1.0', 'end' );
    		$widget_Documents->update;
    		$widget_Documents->see('end');
    		undef @PathsDocu;
    		$widget_Resultats->delete( '1.0', 'end' );
    		$widget_Resultats->update;
    		$widget_Resultats->see('end');
    		$widget_Deductions->delete( '1.0', 'end' );
    		$widget_Deductions->update;
    		$widget_Deductions->see('end');
    	}
    );
     
    # Choix du répertoire des documents et récupération des fichiers .txt
    my $widget_RepDocu = $Frame_Documents->Button(
    	-text => "Documents",
    	-command => sub {
    		# Selectionner un répertoire
    		my $Rep = $Wm->chooseDirectory(
    			-title      => "Choix d'un document",
    			-initialdir => $RepDocu,
    		);
    		if ( $Rep) {
    			$LabRepDocu = $Rep;
    			my $types = [  
    				[ 'Fichiers texte', '.txt' ], 
    				[ 'Tous les fichiers', '*' ], 
    			]; 
    			my @PathsDocuWidget = $Wm->getOpenFile(
    				-filetypes  => $types, 
      			-initialdir => "$RepDocu", 
      			-multiple   => 1, 
    			);
    			foreach my $PathDocu (@PathsDocuWidget) {
    				$widget_Documents->insert( 'end', "$PathDocu\n", "g12" );
    				push @PathsDocu, $PathDocu;
    			}
    			@PathsDocu = doublons_grep( \@PathsDocu );
    			@PathsDocu = sort @PathsDocu;
    			( $config{DOCU}{Fic} ) = join(" ",@PathsDocu);
      		$Wm->update();
    		}
    	},
    );
     
     
    #===========================================================
    # Label pour les dictionnaires
    my $Frame_Dictionnaires = $Wm->LabFrame(
      -label      => 'Dictionnaires',
      -background => $couleur_commune,
      -font       => '{Simplified Arabic} 10 {bold}',
    );
     
    # Bouton effacer dictionnaires
    my $bouton_EffDico = $Frame_Dictionnaires->Button(
    	-text => "Efface",
    	-command => sub {
    		$widget_Dictionnaires->delete( '1.0', 'end' );
    		$widget_Dictionnaires->update;
    		$widget_Dictionnaires->see('end');
    		undef @PathsDico;
    		$widget_Resultats->delete( '1.0', 'end' );
    		$widget_Resultats->update;
    		$widget_Resultats->see('end');
    		$widget_Deductions->delete( '1.0', 'end' );
    		$widget_Deductions->update;
    		$widget_Deductions->see('end');
    	}
    );
     
    # Choix du répertoire des dictionnaires et récupération des fichiers .txt
    my $widget_RepDico = $Frame_Dictionnaires->Button(
    	-text => "Dictionnaires",
    	-command => sub {
    		# Selectionner un répertoire
    		my $Rep = $Wm->chooseDirectory(
    			-title      => "Choix d'un dictionnaire",
    			-initialdir => $RepDico,
    		);
    		if ( $Rep) {
    			$LabRepDico = $Rep;
    			my $types = [  
    				[ 'Fichiers texte', '.txt' ], 
    				[ 'Tous les fichiers', '*' ], 
    			]; 
    			my @PathsDicoWidget = $Wm->getOpenFile(
    				-filetypes  => $types, 
      			-initialdir => "$RepDico", 
      			-multiple   => 1, 
    			);
    			foreach my $PathDico (@PathsDicoWidget) {
    				$widget_Dictionnaires->insert( 'end', "$PathDico\n", "g12" );
    				push @PathsDico, $PathDico;
    			}
    			@PathsDico = doublons_grep( \@PathsDico );
    			@PathsDico = sort @PathsDico;
    			( $config{DICO}{Fic} ) = join(" ",@PathsDico);
      		$Wm->update();
    		}
    	},
    );
     
     
    #===========================================================
    # Label pour la gestion
    my $Frame_Gestion = $Wm->LabFrame(
      -label      => '  Gestion   ',
      -background => $couleur_commune,
      -font       => '{Simplified Arabic} 10 {bold}',
    );
     
    # Fichier résultats
    my $case_Resultat = $Frame_Gestion->Checkbutton (
    	-text => "Fichier résultats",
    	-variable => \$Choix_Fichier_Resultat,
    	-command => sub {
    		$config{GLOBAL}{Resultat} = $Choix_Fichier_Resultat;
    	},
    );
     
    # Fichier déductions
    my $case_Deduction = $Frame_Gestion->Checkbutton (
    	-text => "Fichier déductions",
    	-variable => \$Choix_Fichier_Deduction,
    	-command => sub {
    		$config{GLOBAL}{Deduction} = $Choix_Fichier_Deduction;
    	},
    );
     
    # Fichier debug
    my $case_Debug = $Frame_Gestion->Checkbutton (
    	-text => "Fichier debug",
    	-variable => \$Choix_Debug,
    	-command => sub {
    		$config{GLOBAL}{Debug} = $Choix_Debug;
    	},
    );
     
    # Start
    my $bouton_start = $Frame_Gestion->Button(
    	-text    => 'Start',
    	-command => [ \&start ],
    );
     
    # Stop
    my $bouton_stop = $Frame_Gestion->Button(
    	-text    => 'Stop',
    	-command => [ \&stop, ],
    );
     
    # Sav
    my $bouton_sav = $Frame_Gestion->Button(
    	-text    => 'Save',
    	-command => [ \&sav, $Wm, $fichier_configuration, \%config ],
    );
     
    # Exit
    my $bouton_exit = $Frame_Gestion->Button(
    	-text    => 'Exit',
    	-command => [ \&fermer_application, $Wm, $fichier_configuration, \%config ],
    );
     
     
    ####################################
    # Gestion de l'affichage des widgets
    #
    $cadre_messages->pack      (qw / -side bottom -fill both -expand 0 /);
    $label_documents->pack     (qw / -side left   -fill both -expand 1 /);
    $label_dictionnaires->pack (qw / -side left   -fill both -expand 1 /);
    $label_msg_erreur->pack    (qw / -side left   -fill both -expand 1 /);
     
    $cadre_Resultats->pack     (qw / -side bottom -fill both -expand 1 /);
    $LabFrame_Resultats->pack  (qw / -side left   -fill both -expand 1 /);
    $widget_Resultats->pack    (qw / -side bottom -fill both -expand 1 /);
    $LabFrame_Deductions->pack (qw / -side left   -fill both -expand 1 /);
    $widget_Deductions->pack   (qw / -side bottom -fill both -expand 1 /);
     
    $cadre_Paths->pack            (qw / -side bottom -fill both -expand 1 /);
    $LabFrame_Documents->pack     (qw / -side left   -fill both -expand 1 /);
    $widget_Documents->pack       (qw / -side bottom -fill both -expand 1 /);
    $LabFrame_Dictionnaires->pack (qw / -side left   -fill both -expand 1 /);
    $widget_Dictionnaires->pack   (qw / -side bottom -fill both -expand 1 /);
     
    $Frame_Documents->pack     (qw / -side left -fill both -expand 1 /);
    $Frame_Dictionnaires->pack (qw / -side left -fill both -expand 1 /);
    $Frame_Gestion->pack       (qw / -side left -fill both -expand 1 /);
     
    $bouton_EffDocu->grid( $widget_RepDocu, qw / -padx 8 -pady 5 -sticky nsew /);
    $bouton_EffDico->grid( $widget_RepDico, qw / -padx 8 -pady 5 -sticky nsew /);
    $case_Resultat->grid( $case_Deduction, $case_Debug, $bouton_start, $bouton_stop, $bouton_sav, $bouton_exit,	qw / -padx 7 -pady 5 -sticky nsew /);
     
    centrer_widget($Wm);
    $label_msg_erreur->eventAdd( '<<virtual_clic1>>' => '<Button-1>' ) ;
    MainLoop;
     
    # Pour avoir les accents sur la console DOS
    ActiverAccentDOS();
     
     
    #######################
    # Démarre l'application
    sub start {
    	$label_msg_erreur->bind( '<<virtual_clic1>>' => \&ClearMessage ) ;
    	$label_msg_erreur->configure( -background => '#FFE0D0' );
    	$MsgErreur = '';
    	$Stop = '';
    	$widget_Resultats->delete( '1.0', 'end' );
    	$widget_Resultats->update;
    	$widget_Resultats->see('end');
    	$widget_Deductions->delete( '1.0', 'end' );
    	$widget_Deductions->update;
    	$widget_Deductions->see('end');
     
    	if ( $Choix_Fichier_Resultat ) {
    		open $fh_Resul, '>:utf8', $FicResultat 	or die("Impossible ouvrir $FicResultat \t$!");
    	}
    	if ( $Choix_Fichier_Deduction ) {
    		open $fh_Deduc, '>:utf8', $FicDeduction or die("Impossible ouvrir $FicDeduction \t$!");
    	}
    	if ( $Choix_Debug ) {
    		$FicDebug = File::Spec->catfile( $RepBase, $config{GLOBAL}{FicLog} );
    		open $fh_Debug, '>:utf8', $FicDebug 	or die("Impossible ouvrir $FicDebug \t$!");
    	}
    	if ( $Choix_Debug ) {
    		print $fh_Debug "\nLISDOCS=@PathsDocu=\n";
    		print $fh_Debug "LISTDICO=@PathsDico=\n";
    	}
     
    	if ( !@PathsDocu ) {
    		err("ATTENTION Il n'y a pas de document à analyser ARRET");
    	}
    	if ( !@PathsDico ) {
    		err("ATTENTION Il n'y a pas de dictionnaire pour faire le traitement ARRET");
    	}
     
    	my @TabMots = ();
    	my $fh_Dico;
    	my (%Exist, @MotUnique);
    	foreach my $PathDico (@PathsDico) {
    		if ( $Stop eq 'STOP' ) {
    			last;
    		}
    		open $fh_Dico , '<:utf8', $PathDico
    			or die("Impossible ouvrir  $PathDico \t$!");
    		@TabMots = <$fh_Dico>;
    		close $fh_Dico;
    		chomp (@TabMots);
     
    		foreach my $Elem ( @TabMots ) {
         	push @MotUnique, $Elem unless defined $Exist{$Elem} ;
         	$Exist{$Elem} = 1;
    		}
    	}
    	if ( $Choix_Debug ) {
    		print $fh_Debug "\nMOT_UNIQUE=@MotUnique=\n";
    	}
     
    	foreach my $Document (@PathsDocu) {
    		if ( $Stop eq 'STOP' ) {
    			last;
    		}
    		if ( $Choix_Debug ) {
    			print $fh_Debug "\nTRAITEMENT_DOCUMENT=$Document=\n";
    		}
     
    		if ( $Choix_Fichier_Resultat ) {
    			print $fh_Resul  "\n\n=============================================";
    			print $fh_Resul  "Traitement du fichier $Document :\n";
    		}
    		$widget_Resultats->insert( 'end', "\n=============================================", "g14" );
    		$widget_Resultats->insert( 'end', "Traitement du fichier $Document :\n", "g14" );
     
    		my $In_Fic = $Document;
    		if ( -z $In_Fic ) {
    			ano ("ATTENTION le document $Document est VIDE !!!");
    			if ( $Choix_Fichier_Resultat ) {
    				print $fh_Resul "\t\tATTENTION le document $Document est VIDE !!!\n";
    			}
    			$widget_Resultats->insert( 'end', "\t\tATTENTION le document $Document est VIDE !!!\n", "g12" );
    			if ( $Choix_Fichier_Deduction ) {
    				print $fh_Deduc "\t\tATTENTION le document $Document est VIDE !!!\n";
    			}
    			$widget_Deductions->insert( 'end', "\t\tATTENTION le document $Document est VIDE !!!\n", "g12" );
    		}
     
    		my $fh_Entree;
    		open $fh_Entree, '<:utf8', $In_Fic
      		or die("Impossible ouvrir  $In_Fic \t$!");
     
    		my %Comptage = ();
    		my $NbLigne;
    		while ( my $Ligne = <$fh_Entree> ) {
    			if ( $Stop eq 'STOP' ) {
    				last;
    			}
    			$NbLigne++;
    			foreach my $Mot (@MotUnique) {
    				chomp $Mot;
    				if ( $Ligne =~ $Mot ) {
    					$Comptage{$Mot}++;
    					#print $fh_Resul  "$Mot a la ligne $NbLigne\n";
    				}
    			}
    		}
     
    		while ( my ( $Mot, $Nb ) = each(%Comptage) ) {
    			if ( $Stop eq 'STOP' ) {
    				last;
    			}
    			if ( $Choix_Fichier_Resultat ) {
    				print $fh_Resul  "Le mot '$Mot' est present $Nb fois\n";
    			}
    			$widget_Resultats->insert( 'end', "Le mot '$Mot' est present $Nb fois\n", "g8" );
     
    			#remplir les mots trouver dans le tableau[] nom_recuperer
    			push @nom_recuperer, $Mot;
    		}
    		if ( $Choix_Debug ) {
    			print $fh_Debug "\nNOM_RECUPERER=@nom_recuperer=\n";
    		}
     
    		#comparer les mots avec tous les dico
    		if ( $Choix_Fichier_Deduction ) {
    			print $fh_Deduc  "\n\nDéduction :\n";
    		}
    		$widget_Deductions->insert( 'end', "\n\nDéduction :\n", "g12" );
     
    		foreach my $PathDico (@PathsDico) {
    			if ( $Stop eq 'STOP' ) {
    				last;
    			}
    			if ( $Choix_Debug ) {
    				print $fh_Debug "\nCOMPARER_AVEC_DICO=$PathDico=\n";
    			}
    			my $pourcentage_appr = compare_with_dic($Document, $PathDico);
    			my $pourcentage;
     
    			my $deduction;
    			my $FileDico = fileparse($PathDico);
    			if ( $config{DEDU}{$FileDico} ) {
    				$deduction = $config{DEDU}{$FileDico};
    			} else {
    				$deduction = "Déduction indéderminée";
    			}
    			if ( $Choix_Fichier_Deduction ) {
    				$pourcentage = sprintf( "%0.2f", $pourcentage_appr );
    				print $fh_Deduc "$Document est $PathDico à $pourcentage %\n";
    			}
    			$widget_Deductions->insert( 'end', "$Document $deduction à $pourcentage %\n", "g12" );
    		}
     
    		undef %Comptage;
    		undef @nom_recuperer;
    		close $fh_Entree
    	}
    	if ( $Choix_Fichier_Resultat ) {
    		close $fh_Resul;
    	}
    	if ( $Choix_Fichier_Deduction ) {
    		close $fh_Deduc;
    	}
    	if ( $Choix_Debug ) {
    		print $fh_Debug "\nEXIT=\n";
    		close $fh_Debug;
    	}
     
    }
     
    ################################################################
     
    sub compare_with_dic {
    	my ( $Document, $Dico ) = @_;
    	if ( $Choix_Debug ) {
    		print $fh_Debug "\nCOMPARE_WITH_DIC=$Document=====$Dico=\n";
    	}
    	if ( $Choix_Fichier_Resultat ) {
    		print $fh_Resul  "\nComparaison de $Document avec $Dico\n";
    	}
    	$widget_Resultats->insert( 'end', "Comparaison de $Document avec $Dico\n", "g12" );
     
    	my $count = 0;
    	my %hash;
    	@hash{@nom_recuperer} = 0 .. $#nom_recuperer;
     
    	my $PathDico = File::Spec->catfile( $RepBase, $Dico );
    	open my $fh_Dico , '<:utf8', $Dico
    		or die("Impossible ouvrir  $Dico \t$!");
    	my @TabMots = <$fh_Dico>;
    	close $fh_Dico;
    	chomp (@TabMots);
     	my $NbDico = scalar(@TabMots);
     
    	if ($NbDico) {
    		for my $val (@TabMots) {
    			chomp $val;
    			if ( exists $hash{$val} ) {
    				if ( $Choix_Fichier_Resultat ) {
    					print $fh_Resul  "Le mot $val est présent dans $Dico   la position $hash{$val}.\n";
    				}
    				$widget_Resultats->insert( 'end', "Le mot $val est présent dans $Dico   la position $hash{$val}.\n", "g8" );
    				$count += 1;
    			} else {
    				if ( $Choix_Fichier_Resultat ) {
    					print $fh_Resul  "---->$val n'est pas dans $Dico.\n";
    				}
    				$widget_Resultats->insert( 'end', "---->$val n'est pas dans $Dico.\n", "g10" );
    			}
    		}
     
    		my $pourcentage;
    		my $pourcentage_appr = ( $count * 100 ) / $NbDico;
    		$pourcentage = sprintf( "%0.2f", $pourcentage_appr );
    		if ( $Choix_Fichier_Resultat ) {
    			print $fh_Resul  "\nLe nombre de mots du fichier $Document présents dans $Dico  est $count\n\t===> le pourcentage par raport au $Dico = $pourcentage %";
    		}
    		$widget_Resultats->insert( 'end', "Le nombre de mots du fichier $Document présents dans $Dico est $count\n", , 'fbleu' );
    		$widget_Resultats->insert( 'end', "===>	le pourcentage par raport au $Dico = $pourcentage %\n", , 'fbleu' );	
    		return $pourcentage_appr;
     
    	} else {
    		ano ("ATTENTION $Dico est VIDE !!!");
    		if ( $Choix_Fichier_Resultat ) {
    			print $fh_Resul  "\n\t\tATTENTION $Dico est VIDE !!!\n";
    		}
    		$widget_Resultats->insert( 'end', "\n\t\tATTENTION $Dico est VIDE !!!\n", "g12" );
    		if ( $Choix_Fichier_Deduction ) {
    			print $fh_Deduc  "\n\t\tATTENTION $Dico est VIDE !!!\n";
    		}
    		$widget_Deductions->insert( 'end', "\n\t\tATTENTION $Dico est VIDE !!!\n", "g12" );
    		return 0;
    	}
     
    }
     
     
    ##########
    # Anomalie
    sub ano {
    	my ( $Ano ) = @_;
    	$MsgErreur = $Ano;
    	$Wm->bell();
    	$Wm->update();
    	if ( $Choix_Debug ) {
    		print $fh_Debug "\n----------->ANO=$MsgErreur=\n";
    	}
    	return;
    }
     
    ########
    # Erreur
    sub err {
    	my ( $Ano ) = @_;
    	$label_msg_erreur->configure( -background => '#FF0000' );
    	$MsgErreur = $Ano;
    	$Wm->bell();
    	$Wm->update();
    	if ( $Choix_Debug ) {
    		print $fh_Debug "\n---------->ERR=$MsgErreur=\n";
    	}
    	return;
    }
     
    #########################
    # Efface message d'erreur
    sub ClearMessage {
    	$MsgErreur = '';
    	$label_msg_erreur->configure( -background => '#FFE0D0' );
    }
     
     
    ######
    # Stop
    sub stop {
    	$label_msg_erreur->configure( -background => $couleur_commune );
    	$Wm->bell();
      $Stop = 'STOP';
      $MsgErreur = 'Traitement stoppé';
      $Wm->update();
    	return;
    }
     
    ###########################
    # Sauvegarde des paramètres
    sub sav {
    	my ( $mw, $fichier, $ref_config ) = @_;
    	# Sauvegarder configuration
    	sauvegarde_configuration( $fichier, $ref_config );
    	$MsgErreur = 'Paramètres sauvegardés';
    	return;
    }
     
    ##########################
    # Sauvegarde configuration
    sub sauvegarde_configuration {
    	my ( $fichier, $ref_config ) = @_;
    	write_config %{$ref_config}, $fichier;
    	return;
    }
     
     
    #######################
    # Exit de l'application
    sub fermer_application {
    	my ( $Wm, $fichier, $ref_config ) = @_;
    	$Stop = "Fin";
     
    	my %Old_config;
    	if ( -e $fichier_configuration ) {
      	read_config $fichier_configuration => %Old_config;
    	}	else {
      	%Old_config = (
        	'GLOBAL'  => {
          	Debug   => 'NON',
        	},
        	'DOCU' => {
        		Rep  => 'Docu',
        		Fic  => 'ETH.txt',
        	},
        	'DICO' => {
        		Rep  => 'Dico',
        		Fic  => 'DicoEth.txt',
        	}
      	);
    	}
     
    	if ( $Old_config{DOCU}{Fic} ne $config{DOCU}{Fic} ||
    			 $Old_config{DICO}{Fic} ne $config{DICO}{Fic} ||
    			 $Old_config{GLOBAL}{Resultat} ne $config{GLOBAL}{Resultat} ||
    			 $Old_config{GLOBAL}{Deduction} ne $config{GLOBAL}{Deduction} ||
    			 $Old_config{GLOBAL}{Debug} ne $config{GLOBAL}{Debug} ) {
     
    			my $Wm_Sortie = $Wm->Toplevel(
    				-title => "La configuration a été modifiée",
    				-background => 'white',
    			);
      		$Wm_Sortie->geometry("300x100+900+30");
     
      		my $SortieSave = $Wm_Sortie->Button(
    				-text    => 'Save and exit',
    				-font    => '{Simplified Arabic} 12 {bold}',
    				-command => sub {
    					sauvegarde_configuration( $fichier, $ref_config );
    					exit;
    				}
    			);
     
    			my $SortieSansSave = $Wm_Sortie->Button(
    				-text    => 'Exit without save',
    				-font    => '{Simplified Arabic} 12 {bold}',
    				-command => sub {
    					$Wm->destroy;
    					exit;
    				}
    			);
     
    			$SortieSave->grid($SortieSansSave,
    				qw / -padx 15 -pady 5 -sticky nsew /
    			);
     
    		} else {
    			$Wm->destroy;
    			exit;
    		}
    }
     
     
    #############################################################################
    #############################################################################
     
    #================================================
    # But : Centrer un widget automatiquement
    #================================================
    sub centrer_widget {
    	my ( $widget ) = @_;
     
    	# Height and width of the screen
    	my $largeur_ecran = $widget->screenwidth();
    	my $hauteur_ecran = $widget->screenheight();
     
    	# update le widget pour récupérer les vraies dimensions
    	$widget->update;
    	my $largeur_widget = $widget->width;
    	my $hauteur_widget = $widget->height;
     
    	# On centre le widget en fonction de la taille de l'écran
    	my $nouvelle_largeur  = int( ( $largeur_ecran - $largeur_widget ) / 2 );
    	my $nouvelle_hauteur  = int( ( $hauteur_ecran - $hauteur_widget ) / 2 );
    	$widget->geometry($largeur_widget . "x" . $hauteur_widget
    		. "+$nouvelle_largeur+$nouvelle_hauteur");
    	$widget->update;
    	return;
    }
     
     
    #########################################
    # Configuration des polices de caractères
    #
    sub configurer_tags {
    	my $widget_text = shift;
    	for my $police ( 12 .. 72 ) {
    		if ( $police % 2 == 0 ) {
    			$widget_text->tagConfigure(
    				"g$police",
    				-background => '#ABFAA3',
    				-font      => "{Simplified Arabic} $police {bold}",
    				-justify    => 'left',
    			);
    			$widget_text->tagConfigure(
    				"c$police",
    				-background => '#ABFAA3',
    				-font      => "{Simplified Arabic} $police {bold}",
    				-justify    => 'center',
    			);
    			$widget_text->tagConfigure(
    				"d$police",
    				-background => '#ABFAA3',
    				-font      => "{Simplified Arabic} $police {bold}",
    				-justify    => 'right',
    			);
    		}
    	}
     
    	$widget_text->tagConfigure(
    		'ara',
    		-background => '#D9FDFD',
    		-font      => '{Simplified Arabic} 36', # Arabe
    		-justify    => 'center',
    	);
     
    	$widget_text->tagConfigure(
    		'fnoir',
    		-background => '#D9FDFD',
    		-font      => '{Simplified Arabic} 10', # Français 10 noir
    		-justify    => 'center',
    	);
     
    	$widget_text->tagConfigure(
    		'froug',
    		-background => '#D9FDFD',
    		-foreground => '#FF0000',
    		-font      => '{Simplified Arabic} 10', # Français 10 rouge
    		-justify    => 'center',
    	);
     
    	$widget_text->tagConfigure(
    		'frougs',
    		-background => '#D9FDFD',
    		-foreground => '#FF0000',
    		-font      => '{Simplified Arabic} 10', # Français 10 rouge souligné
    		-underline => 1,
    		-justify    => 'center',
    	);
     
    	$widget_text->tagConfigure(
    		'fvert',
    		-background => '#D9FDFD',
    		-foreground => '#00CC00',
    		-font      => '{Simplified Arabic} 10', # Français 10 vert traduction
    		-justify    => 'center',
    	);
     
    	$widget_text->tagConfigure(
    		'fbleu',
    		-background => '#D9FDFD',
    		-foreground => '#3914AF',
    		-font      => '{Simplified Arabic} 12', # Français 12 bleu
    		-justify    => 'left',
    	);
     
    	$widget_text->tagConfigure(
    		'fbleus',
    		-background => '#D9FDFD',
    		-foreground => '#3914AF',
    		-font      => '{Simplified Arabic} 10', # Français 10 bleu souligné
    		-underline => 1,
    		-justify    => 'center',
    	);
     
    	return;
    }
     
    #######################################
    # Elimination des doublons d'un tableau
    sub doublons_grep {
      my ($ref_tabeau) = @_;
      my %hash_sans_doublon;
      return grep { !$hash_sans_doublon{$_}++ } @{$ref_tabeau};
    }
     
     
    #==============================================================
    # Pour avoir les accents sur la console DOS
    # http://perl.developpez.com/faq/perl/?page=Terminal#AccentsDOS
    #==============================================================
    sub ActiverAccentsDOS {
    	my $encodage;
    	# Windows
      	if ( lc($^O ) eq 'mswin32') {
    		eval {
    			my ($codepage) = ( `chcp` =~ m/:\s+(\d+)/ );
    			$encodage = "cp$codepage";
    			foreach my $h ( \*STDOUT, \*STDERR, \*STDIN, ) {
    				binmode $h, ":encoding($encodage)";
    			}
    		};	
    	}
    	else {
    		$encodage = `locale charmap`;
    		eval {
    			foreach my $h ( \*STDOUT, \*STDERR, \*STDIN, ) {
    				binmode $h, ":encoding($encodage)";
    			}
    		};	
    	}
      return $encodage;
    }
     
    #Sinon :
    #ü 	\x81 	à 	\x85 	è 	\x8A
    #é 	\x82 	ç 	\x87 	ï 	\x8B
    #â 	\x83 	ê 	\x88 	î 	\x8C
    #ä 	\x84 	ë 	\x89
    Pour quand tu auras le temps

    - Il faut juste installer le module Tk
    - Ça allonge un peu le code, mais ce qu'on avait fait n'a presque pas bougé, hormis les écritures
    - Ça impressionne un peu au départ mais ça se construit avec beaucoup de Copier/Coller, ça va assez vite
    + Juste 2 répertoires 1 pour Dictionnaires 1 pour Documents
    + Il tourne correctement, mais pas dit qu'il ne manque pas qq contrôles

    Il y a un très bon bouquin à télécharger en .pdf

    Au passage MERCI à djibril

    La météo s'annonce meilleure...
    Pour te donner envie :

  11. #31
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2016
    Messages
    74
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2016
    Messages : 74
    Points : 67
    Points
    67
    Par défaut
    Impressionnant
    Vraiment c’est très gentil de votre part ‘sincèrement je ne trouve pas les mots pour vous remerciez
    Je vais reprendre le travaille cette semaine sachant que (ca été très charge par les examens ce qui m’a empêché de connecter sur le forum et surtout que je n’ai pas fait attention au message)
    Tous mes remerciements

  12. #32
    Membre chevronné Avatar de dmganges
    Homme Profil pro
    Retraité. Ne recherche pas un emploi.
    Inscrit en
    Septembre 2011
    Messages
    1 392
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 71
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Retraité. Ne recherche pas un emploi.
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2011
    Messages : 1 392
    Points : 2 044
    Points
    2 044
    Par défaut
    Vous aviez fait l'essentiel, et vous aviez tout collé, on n'avait pas besoin de jouer au Devin ce qui n'est pas toujours le cas...
    Dans le code il y a des parties qui ne sont pas utilisées, notamment dans les tagConfigure que j'ai directement copié d'un autre programme, ici je n'utilise que 'fbleu'
    En remplaçant ça vous permettra de jouer avec les autres tags
    J'efface les images devenues inutiles.
    J'effacerai les fichiers du serveur dans la semaine.

    Bref, c'était donc peu de choses, de plus cela m'a permis de réviser
    Je suis encore votre obligé !

    Le Devin un SUPER Astérix pour étudier la crédulité de la nature humaine sans se prendre la tête

  13. #33
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2016
    Messages
    74
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2016
    Messages : 74
    Points : 67
    Points
    67
    Par défaut
    je viens de télécharger le pdf(400 pages ) il demande Un peux de lecture
    pour le module tk c’est bon je l’ai installé

+ Répondre à la discussion
Cette discussion est résolue.
Page 2 sur 2 PremièrePremière 12

Discussions similaires

  1. Comment chercher un mot dans un fichier texte et le modifier?
    Par Ange_1987 dans le forum VB 6 et antérieur
    Réponses: 8
    Dernier message: 13/05/2009, 19h24
  2. Trouver un mot dans un fichier texte
    Par spl0tch dans le forum Langage
    Réponses: 12
    Dernier message: 16/04/2007, 22h14
  3. Réponses: 10
    Dernier message: 29/04/2006, 11h40
  4. Trouver un mot dans un fichier texte
    Par godik dans le forum Entrée/Sortie
    Réponses: 9
    Dernier message: 10/03/2006, 15h31
  5. Comment changer des mots dans un fichier?
    Par ptitbonum dans le forum Linux
    Réponses: 5
    Dernier message: 08/04/2004, 00h42

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo