-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnormalise.pl
More file actions
executable file
·75 lines (66 loc) · 1.94 KB
/
Copy pathnormalise.pl
File metadata and controls
executable file
·75 lines (66 loc) · 1.94 KB
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
#!/usr/bin/perl -w
use strict;
use warnings;
use open qw(:std :utf8);
use Lingua::Stem;
if($#ARGV+1 != 4){
print "Vous devez renseigner les deux arguments\n $0 input.fon output.lemm langue stemmer\n";
exit(0);
}
# Vérification de la langue donnée en paramètre.
my @languages_allow = ('eng', 'fra');
if(!in_array(\@languages_allow, $ARGV[2])){
print "Le paramètre de langue doit être eng ou fra\n";
exit(0);
}
# Vérification de la langue donnée en paramètre.
my @stemmer_allow = (1, 2);
if(!in_array(\@stemmer_allow, $ARGV[3])){
print "Le paramètre du choix de stemmer doit être 1 pour un ultra stemming ou 2 pour l'utilisation de l'algorithme de Porter\n";
exit(0);
}
open(FILER,"<$ARGV[0]") or die("Fichier introuvable ou Impossible d'ouvrir le fichier en lecture");
open(FILEW,">$ARGV[1]") or die("Fichier introuvable ou Impossible d'ouvrir le fichier en ecriture");
my (@words,$word, $final_row, $isset, $stopword);
if($ARGV[3]==1){
while( defined( my $row = <FILER> ) ) {
$final_row = "";
$row =~ s/[0-9]//g; # Suppression des chiffres.
chomp($row);
@words = split(' ',$row);
foreach $word (@words){
$final_row .= lc(substr($word, 0, 1)) . " ";
}
chomp($final_row);
print( FILEW "$final_row\n");
}
}
else{
my $stemmer;
#Définition de la variable de langue pour le stemmer.
if($ARGV[2] eq "eng"){
$stemmer = Lingua::Stem->new(-locale => 'EN-UK');
}
else{
$stemmer = Lingua::Stem->new(-locale => 'FR');
}
while( defined( my $row = <FILER> ) ) {
$final_row = "";
chomp($row);
@words = split(' ',$row);
foreach $word (@words){
$final_row .= $stemmer->stem($word)->[0] . " ";
}
chomp($final_row);
print( FILEW "$final_row\n");
}
}
close(FILER);
close(FILEW);
# Fonction de verification de la presence d'une chaine dans un tableau.
sub in_array
{
my ($arr,$search_for) = @_;
my %items = map {$_ => 1} @$arr;
return (exists($items{$search_for}))?1:0;
}