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
|
open(fid_doc,"corpus.txt") || die ("couldn't open corpus.txt!");
while (<fid_doc>)
{
push(@file_doc,$_); #Files constituting the corpus
}
close(fid_doc);
$N_doc = $#file_doc + 1;
foreach $i (0..$#file_doc)
{
&occurrence($file_doc[$i]);
#print $file_doc[$i]. "\n";
}
open(fid_req,"requete.txt") || die ("couldn't open requete.txt!");
while (<fid_req>)
{
push(@file_req,$_); #Files constituting the queries
}
close(fid_req);
$N_req = $#file_req + 1;
foreach $i (0..$#file_req)
{
&occurrence_req($file_req[$i],$i);
#print $file_req[$i]. "\n";
}
#**************************************************************
display(corpus_traited_word,terms_traited_word,graphe_word,\%occurrence_matrix);
#**************************************************************
#
#**************************************************************
# occurrence procedure
#**************************************************************
sub occurrence
{
my @word_list;
open(fid,$_[0]) || die ("couldn't open file.txt!");
while (<fid>)
{
@word_list = (@word_list,split(/[\n\*]/,$_));
}
close(fid);
#**************************************************************
foreach $word (@word_list)
{
@{$occurrence_matrix{$word}}[$_[1]]++;
#print $word;
}
delete $occurrence_matrix{""};
}
#**************************************************************
#**************************************************************
# occurrence_req procedure
#**************************************************************
sub occurrence_req
{
my @word_list;
open(fid,$_[0]) || die ("couldn't open file.txt!");
while (<fid>)
{
@word_list = (@word_list,split(/[\*\n]/,$_));
}
close(fid);
$i = 0;
while ($i<$#word_list)
{
if(@{$occurrence_matrix{$word_list[$i]}} != undef)
{
@{$occurrence_matrix{$word_list[$i]}}[$_[1]]= $word_list[$i+1] ;
print $word_list[0];
}
$i=$i+2
}
delete $occurrence_matrix{""};
}
#**************************************************************
# Displaying the Results
#**************************************************************
sub display
{
open(fid,">$_[0].txt") || die ("couldn't open corpus_traited.txt!");
open(fid_t,">$_[1].txt") || die ("couldn't open terms_traited.txt!");
open(fid_g,">$_[2].txt") || die ("couldn't open graphe.txt!");
my $ref_occurrence_matrix;
$ref_occurrence_matrix = $_[3];
@key = keys(%{$ref_occurrence_matrix});
foreach $i (0..$#key)
{
if (length(@key[$i]) == 2)
{
delete $$ref_occurrence_matrix{@key[$i]};
}
}
@key = sort(keys(%{$ref_occurrence_matrix}));
$N_mot = $#key + 1;
print fid "nombre de documents: $N_doc", "\n";
print fid "nombre de requetes: $N_req", "\n";
print fid "nombre de mots: $N_mot", "\n";
print fid_g "$N_doc $N_req $N_mot", "\n";
foreach $i (0..$#key)
{
print fid @key[$i];
print fid_t @key[$i];
for($j = 0;$j <= ($#file_doc + $N_req);$j ++)
{
print fid "\t";
if(${$$ref_occurrence_matrix{@key[$i]}}[$j] == undef)
{
print fid "0";
print fid_g "0 ";
}
else
{
print fid ${$$ref_occurrence_matrix{@key[$i]}}[$j];
print fid_g "${$$ref_occurrence_matrix{@key[$i]}}[$j] ";
}
}
print fid "\n";
print fid_t "\n";
print fid_g "\n";
}
close(fid);
close(fid_t);
close(fid_g);
} |
Partager