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
|
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) {
my ($synonyme, $etiquette);
foreach ($_->descendants()) {
my $tag = $_->tag();
if ($tag ~~ "synonyme" ) {
$synonyme = ($_->content_list())[0];
}
if ($tag ~~ "etiquette" ) {
$etiquette = ($_->content_list())[0];
$h1{$synonyme} = $etiquette;
}
}
}
$tree->delete;
open my $fh, "<:utf8", '/home/hp/Bureau/Master/toto.txt';
open my $fh1, ">:utf8", '/home/hp/Bureau/Master/resultatML.txt';
open my $fh2, ">:utf8", '/home/hp/Bureau/Master/essai10.txt';
my $linenum = 0;
my (@bloc, @words);
foreach(<$fh> ) {
unless ($linenum++ or not /^\x{feff}/) {
s/^\x{feff}// ;
}
if (/^\s*$/) {
if (0+@bloc) {
#print $fh2 join(" + ", @bloc), "\n";
@bloc = ();
}
}
#sinon
else {
#On vire les espaces en début et en fin
s/^\s+|\s+$//g;
#On découpe la ligne comme des mots séparés par des espaces
@words = split /\s+/;
if (defined($h1{$words[0]}) and defined($h2{$h1{$words[0]}})) {
if ( $h1{$words[0]} ~~ "Mot-Chef" ) {
push @bloc, "$words[0]\n";
}
}
else {
# push @bloc, "???";
}
}
}
if (0+@bloc) {
print $fh2 join("\n", @bloc), "\n";
}
close $fh; |
Partager