rim_enis j'aime ENIS | bonoir gilou ,
j'ai encore des problèmes avec perl , merci de m'aider SVP ,
voici mon programme perl :
Code :
- use strict;
- use warnings;
- use autodie;
- use XML::TreeBuilder;
- my %h1;
- my $tree = XML::TreeBuilder->new();
- $tree->parse_file('/home/hp/Bureau/Master/fic2.xml');
- my @mots = $tree->find('mot');
- foreach (@mots) {
- s/^\s+|\s+$//g;
- next if (/^$/);
- my ($synonyme, $etiquette);
- foreach ($_->descendants()) {
- my $tag = $_->tag();
- if ($tag ~~ "synonyme" ) {
- $synonyme = ($_->content_list())[0];
- next if (ref($synonyme));
- $synonyme =~ s/^\s+|\s+$//g;
- next if ($synonyme ~~ /^$/);
- }
- if ($tag ~~ "etiquette" ) {
- $etiquette = ($_->content_list())[0];
- next if (ref($etiquette));
- $etiquette =~ s/^\s+|\s+$//g;
- next if ($etiquette ~~ /^$/);
- $h1{$synonyme} = $etiquette;
- }
- }
- }
- $tree->delete;
- my %h2;
- $tree = XML::TreeBuilder->new();
- $tree->parse_file('/home/hp/Bureau/Master/fic3.xml');
- my @classes = $tree->find('classe');
- foreach (@classes) {
- s/^\s+|\s+$//g;
- next if (/^$/);
- #my $synonyme = $_->{'synonyme'};
- # next if (ref($synonyme));
- my ($nom, $etiquette);
- foreach ($_->descendants()) {
- my $tag = $_->tag();
- if ($tag ~~ "nom" ) {
- $nom = ($_->content_list())[0];
- next if (ref($nom));
- $nom =~ s/^\s+|\s+$//g;
- next if ($nom ~~ /^$/);
- }
- if ($tag ~~ /^etiquette\d+$/) {
- $etiquette = ($_->content_list())[0];
- next if (ref($etiquette));
- $etiquette =~ s/^\s+|\s+$//g;
- next if ($etiquette ~~ /^$/);
- $h2{$etiquette}= $nom;
- }
- }
- }
- $tree->delete;
- open my $fh, "<:utf8 ", '/home/hp/Bureau/Master/sortie2.txt';
- open my $fh1, ">:utf8", '/home/hp/Bureau/Master/sortie3.txt';
- my $linenum = 0;
- my (@bloc, @words);
- my $Appelation="";
- my $Obligation="";
- my $Ville="";
- my $Comparaison="";
- my $MotOutil="";
- my $AutreMots="";
- my $Autre="";
- my $Disponibilite="";
- my $Nombre="";
- my $Annees="";
- my $MoyenTransport="";
- my $Action="";
- my $Etat="";
- my $Certitude="";
- my $Jure="";
- my $Demande="";
- my $Politesse="";
- my $OutilQuestion="";
- my $Lieu="";
- my $Amorce="";
- my $Salutation="";
- my $TypeTrain="";
- my $ClasseTrain="";
- my $Mois="";
- my $Jour="";
- my $Horaires="";
- my $Nomination="";
- my $Hesitation="";
- my $Reponse="";
- my $Monnaie="";
- my $Pronom="";
- my $Quantite="";
- my $Promotion="";
- my $Billet="";
- my $Voyageur="";
- my $Carte="";
- my $Possibilite="";
-
- foreach(<$fh> ) {
- unless ($linenum++ or not /^\x{feff}/) {
- s/^\x{feff}// ;
- }
- if (/^\s*$/) {
- if (0+@bloc) {
- #print $fh1 join(" ", @bloc), "\n";
- @bloc = ();
- }
- }
- else {
- chomp;
- s/^\s+|\s+$//g;
- @words = split /\s+/;
- if (defined($h1{$words[0]}) and defined($h2{$h1{$words[0]}})) {
-
- if ($h2{$h1{$words[0]}} ~~ "Appelation" ) {
-
- $Appelation .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Obligation" ) {
-
- $Obligation .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Ville" ) {
-
- $Ville .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Comparaison" ) {
-
- $Comparaison .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Mot-Outil" ) {
-
- $MotOutil .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Autre-Mots" ) {
-
- $AutreMots .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Autre" ) {
-
- $Autre .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Disponibilite" ) {
-
- $Disponibilite .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Nombre" ) {
-
- $Nombre .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Annees" ) {
-
- $Annees .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Moyen-Transport" ) {
-
- $MoyenTransport .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Possibilite" ) {
-
- $Possibilite .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Action" ) {
-
- $Action .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Etat" ) {
-
- $Etat .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Certitude" ) {
-
- $Certitude .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Jure" ) {
-
- $Jure .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Demande" ) {
-
- $Demande .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Politesse" ) {
-
- $Politesse .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Outil-Question" ) {
-
- $OutilQuestion .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Etat" ) {
-
- $Etat .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Etat" ) {
-
- $Etat .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Lieu" ) {
-
- $Lieu .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Amorce" ) {
-
- $Amorce .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Salutation" ) {
-
- $Salutation .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Type-Train" ) {
-
- $TypeTrain .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Classe-Train" ) {
-
- $ClasseTrain .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Mois" ) {
-
- $Mois .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Jour" ) {
-
- $Jour .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Horaires" ) {
-
- $Horaires .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Nomination" ) {
-
- $Nomination .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Hesitation" ) {
-
- $Hesitation .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Reponse" ) {
-
- $Reponse .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Monnaie" ) {
-
- $Monnaie .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Pronom" ) {
-
- $Pronom .= " $words[0]";
- }
-
- }
- if ($h2{$h1{$words[0]}} ~~ "Quantite" ) {
-
- $Quantite .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Promotion" ) {
-
- $Promotion .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Billet" ) {
-
- $Billet .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Voyageur" ) {
-
- $Voyageur .= " $words[0]";
- }
- if ($h2{$h1{$words[0]}} ~~ "Carte" ) {
-
- $Carte .= " $words[0]";
- }
- }
- }
- push @bloc, " Appelation ".$Appelation;
- push @bloc, "\n";
- push @bloc, "Obligation ".$Obligation;
- push @bloc, "\n";
- push @bloc, "Ville ".$Ville;
- push @bloc, "\n";
- push @bloc, "Comparaison ".$Comparaison;
- push @bloc, "\n";
- push @bloc, "Mot-Outil ".$MotOutil;
- push @bloc, "\n";
- push @bloc, "Autre-Mots ".$AutreMots;
- push @bloc, "\n";
- push @bloc, "Autre ".$Autre;
- push @bloc, "\n";
- push @bloc, "Disponibilite ".$Disponibilite;
- push @bloc, "\n";
- push @bloc, "Nombre ".$Nombre;
- push @bloc, "\n";
- push @bloc, "Annees ".$Annees;
- push @bloc, "\n";
- push @bloc, "Moyen-Transport ".$MoyenTransport;
- push @bloc, "\n";
- push @bloc, "Action ".$Action;
- push @bloc, "\n";
- push @bloc, "Etat ".$Etat;
- push @bloc, "\n";
- push @bloc, "Certitude ".$Certitude;
- push @bloc, "\n";
- push @bloc, "Jure ".$Jure;
- push @bloc, "\n";
- push @bloc, "Demande ".$Demande;
- push @bloc, "\n";
- push @bloc, "Politesse ".$Politesse;
- push @bloc, "\n";
- push @bloc, "Outil-Question ".$OutilQuestion;
- push @bloc, "\n";
- push @bloc, "Lieu ".$Lieu;
- push @bloc, "\n";
- push @bloc, "Amorce ".$Amorce;
- push @bloc, "\n";
- push @bloc, "Salutation ".$Salutation;
- push @bloc, "\n";
- push @bloc, "Type-Train ".$TypeTrain;
- push @bloc, "\n";
- push @bloc, "Classe-Train ".$ClasseTrain;
- push @bloc, "\n";
- push @bloc, "Mois ".$Mois;
- push @bloc, "\n";
- push @bloc, "Jour ".$Jour;
- push @bloc, "\n";
- push @bloc, "Horaires ".$Horaires;
- push @bloc, "\n";
- push @bloc, "Nomination ".$Nomination;
- push @bloc, "\n";
- push @bloc, "Hesitation ".$Hesitation;
- push @bloc, "\n";
- push @bloc, "Reponse ".$Reponse;
- push @bloc, "\n";
- push @bloc, "Monnaie ".$Monnaie;
- push @bloc, "\n";
- push @bloc, "Pronom".$Pronom;
- push @bloc, "\n";
- push @bloc, "Quantite ".$Quantite;
- push @bloc, "\n";
- push @bloc, "Promotion ".$Promotion;
- push @bloc, "\n";
- push @bloc, "Billet ".$Billet;
- push @bloc, "\n";
- push @bloc, "Voyageur ".$Voyageur;
- push @bloc, "\n";
- push @bloc, "Carte ".$Carte;
- push @bloc, "\n";
- if (0+@bloc) {
- print $fh1 join(" ", @bloc), "\n";
- }
|
avec fic2.xml :
<mot>
<synonyme>أُصْرُفْ</synonyme>
<etiquette>Marqueur-Payement</etiquette>
</mot>
<mot>
<synonyme>نْخَلِّيكْ</synonyme>
<etiquette>Mot</etiquette>
</mot>
<mot>
<synonyme>تَرْجَعْلي</synonyme>
<etiquette>Mot</etiquette>
</mot>
fic3.xml <classe>
<nom>Certitude</nom>
<etiquette1>Incertitude</etiquette1>
<etiquette2>Certitude</etiquette2>
</classe>
<classe>
<nom>Jure</nom>
<etiquette1>Jure</etiquette1>
</classe>
<classe>
<nom>Reponse</nom>
<etiquette1>Confirmation</etiquette1>
<etiquette2>Negation</etiquette2>
<etiquette3>Reponse</etiquette3>
</classe>
et sortie2.txt :
تْفَضَّلْ
خُويَا
مْعَ
وَقْتَاشْ
بِاللهْ
التْرَانْ
يِمْشِي
مَاضِي
سَاعَةْ
وَ
أَرْبْعَةْ
مَا
ثَمَّاشْ
وَاحِدْ
mon but est faire un programme dont la sortie est la suivante : nom de classe mot1 mot2 mot3 ....
avec nom de classe est le nom de classe du fichier fic3.txt et word1 word2 etc sont le mots ds sortie.txt tout en utilisant la base fic2.xml
mon problème et que je constate qu'il ya des mots ds sortie2 qui non pas classé , peut etre c'est un problème des espaces
|