Boite à Outils - Série 3
Extraction de patronsNous avons ici extrait des patrons morpho-syntaxiques à partir de nos fichiers étiquetés, soit les fichiers.cnr et les fichiers.xml étiquetés par la Boite à Outils 2.
Nous avons procédé de trois manières différentes.
1. Première méthode - avec fichier patron
#!/usr/bin/perl
use utf8;
binmode STDOUT, ":utf8";
open (FIC, "<:encoding(utf-8)", $ARGV[0]);
open (MOTIF, "<:encoding(utf-8)", $ARGV[1]);
my @PATRON = <MOTIF>;
my @TOKEN=();
my @ETIQ=();
while (my $ligne = <FIC>)
{
$ligne=~s/\r//;
chomp($ligne);
if ($ligne=~/^([^\t]+)\t([^\t]+)\t([^\t]+)$/)
{
if ($ligne!~/^PCTF/)
{
chomp($ligne);
my @LISTE = split(/\t/, $ligne);
push(@TOKEN,$token[0]);
push(@ETIQ,$etiq[2]);
}
else
{
&routine
@TOKEN = ();
@ETIQ = ();
}
}
}
close FIC;
close MOTIF;
#-----------------------------------------------------
sub routine {
my ($first,$second)=@_;
my @TOKEN=@$first;
my @ETIQ=@$second;
foreach my $patron (@LISTEPATRON) {
$patron=~s/\r//;
chomp $patron;
my $texte_des_pos=join(" ",@ETIQ);
while ($texte_des_pos=~/$patron/g)
{
my $contextebefore=$`;
my $compteespace=0;
while ($contextebefore=~/\t/g)
{
$compteespace++;
}
my @PATRONENCOURS=split(/ /, $patron);
my $longueurpatron=$#PATRONENCOURS;
my $total = $compteurblanc + $longueurpatron;
print "@TOKEN[$compteurblanc..$total] \n";
}
}
}
La sortie correspond ici au fichier patron suivant : NCFS PREP NCFS / NCMS PREP NCFS / NCMS ADJMS