Accueil | BàO 1 | BàO 2 | BàO 3 | BàO 4 | Conclusion

Pour cette boîte à outils, nous devons nous servir des fichiers précédement étiquetés dans la BàO2: le fichier texte Talismane que nous allons au préalable transformer en xml grâce à un script Perl fourni par nos professeurs, et le fichier xml Tree-tagger. (vous pouvez télécharger ici les fichiers xml talismane ainsi que le script utilisé)

Les patrons morphosyntaxiques que nous allons chercher sont donc:

NOM ADJECTIF

ADJECTIF NOM

VERBE DETERMINANT NOM

NOM PREPOSITION NOM PREPOSITION

Et pour mener cette étape à bien, 3 méthodes s'offrent à nous :

METHODE PERL

Pour cette méthode, nous avons besoin du script écrit en cours avec Mr Daube, du fichier Talismane sous forme texte, et d'un fichier termino.txt contenant les motifs souhaités. L'avantage de cette méthode est que nous pouvons rechercher tous nos motifs avec un seul script, en une seule fois.

Voici le programme pour l'extraction de patron en Perl (programme de Jean-Michel Daube) :

			
#!/usr/bin/perl
use utf8;
use Time::HiRes qw(gettimeofday tv_interval);
my $timepg = [gettimeofday];
my $filetalismane=$ARGV[0];
my $filetermino=$ARGV[1];
open my $fileT,"<:encoding(UTF-8)",$filetalismane;
open my $fileTer,"<:encoding(UTF-8)",$filetermino;
my @TERMINO=<$fileTer>,
close $fileTer;
my %dicotmp=();
my %dicoPatron=();
my $nbTerme=0;
my $nbMotInPhrase=0;
while (my $ligne=<$fileT>) {
	next if (($ligne=~/^1\t££/) or ($ligne=~/^\#\#/) or ($ligne=~/^$/));
	if ($ligne!~/^\d+\t§/) {
		$ligne=~/^\d+\t(.+)$/;
		#my $cle=$1;
		my $reste=$1;
		$nbMotInPhrase++;
		my $cle=$nbMotInPhrase;
		my @listereste=split(/\t/,$reste);
		$dicotmp{$cle}=\@listereste;
	}
	else {
		#------------------------
		# extraction termino....
		my $phrase=" ";
		my $longueur = scalar (keys %dicotmp);
		for (my $i=1;$i<=$longueur;$i++) {
			my $LISTE=$dicotmp{$i};
			my @listedeferencee = @$LISTE;
			my $mot=$listedeferencee[0];
			my $pos=$listedeferencee[2];
			$phrase=$phrase.$mot."/".$pos." ";
		}
		foreach my $patron (@TERMINO) {
			my $patron2=$patron;
			chomp($patron2);
			$patron2=~s/([^ ]+)/\[\^ \]\+\/\\b$1/g;
			#print $patron2,"\n";
			#print $phrase,"\n";
			#my $rep=<STDIN>;
			while ($phrase=~/(?=\s($patron2))/g) { 
				my $terme=$1;
				#print $terme,"\n";
				$terme=~s/\/[^ ]+//g;
				#print "$terme\n";
				#my $rep=<STDIN>;
				$dicoPatron{$patron}->{$terme}++;
				$nbTerme++;
			}
		}
		%dicotmp=();
		$nbMotInPhrase=0;
	}
}
close($fileT);

open my $fileResu,">:encoding(UTF-8)","perlIsTheBigOneOne.txt";
print $fileResu "$nbTerme éléments trouvés\n";
foreach my $patron (keys %dicoPatron) {
	print $fileResu "\nType de pattern: ".$patron." \n\n";
	foreach my $terme (sort {$dicoPatron{$patron}->{$b} <=> $dicoPatron{$patron}->{$a} } keys %{$dicoPatron{$patron}}) {
		print $fileResu $dicoPatron{$patron}->{$terme}."\t".$terme."\n";
	}
}
print $fileResu "\nScript execution time: " . tv_interval($timepg) . " seconds.";
close($fileResu);

				
			

Voici le fichier termino qui contient les patrons recherchés.

et voici les sorties :

< Perl | Xquery > | XSLT >> | HAUT

PARTIE XQuery

Pour cette méthode, nous avons d'abord besoin des fichiers étiquetés par Talismane dans la BAO2, en format xml. Nous nous servons ainsi du programme BaseX: celui-ci fonctionne par requêtes XQUERY ou XPATH. Nous procédons donc à l'extraction des patrons demandés:

											
	PATRON NOM-ADJ

	for $art in doc("TALISMANE-3232.xml")//p
	for $elt in $art/item
	let $nextElt := $elt/following-sibling::item[1]
	where $elt/a[4] = "NC" and $nextElt/a[4] = "ADJ"
	return <NOMADJ>{$elt/a[2]/text(), " ", $nextElt/a[2]/text()}</NOMADJ>


	PATRON NOM-PREP-NOM
	
	for $art in doc("TALISMANE-3232.xml")//p
	for $elt in $art/item
	let $nextElt := $elt/following-sibling::item[1]
	let $nextnextElt := $nextElt/following-sibling::item[1]
	where $elt/a[4] = "NC" and $nextElt/a[4] = "P" and $nextnextElt/a[4] = "NC"
	return <NOMPREPNOM>{$elt/a[2]/text(), " ", $nextElt/a[2]/text(), " ",  $nextnextElt/a[2]/text()}</NOMPREPNOM>
											
										

Voici les résultats sous forme d'archive pour chaque rubrique:

Ensuite, nous appliquons la méthode sur les fichiers Tree-tagger cette fois

											
	PATRON NOM-ADJ

	for $art in doc("sortie-3236-regexp.xml")//article
	for $elt in $art//element
	let $nextElt := $elt/following-sibling::element[1]
	where $elt/data[1] = "NOM" and $nextElt/data[1] = "ADJ"
	return <NOMADJ>{$elt/data[2]/text(), " ", $nextElt/data[2]/text()}</NOMADJ>


	PATRON NOM-PREP-NOM
	
	for $art in doc("sortie-3260-regexp.xml")//article
	for $elt in $art//element
	let $nextElt := $elt/following-sibling::element[1]
	let $nextnextElt := $nextElt/following-sibling::element[1]
	where $elt/data[1] = "NOM" and $nextElt/data[1] = "PRP" and $nextnextElt/data[1] = "NOM"
	return <NOMPRPNOM>{$elt/data[2]/text(), " ", $nextElt/data[2]/text(), " ", $nextnextElt/data[2]/text()}</NOMPRPNOM>
											
										

Voici les résultats sous forme d'archive pour chaque rubrique:

Cette fois, nous voulons extraire tous les patrons simultanément, sur Talismane

											
	TOUS LES PATRONS SIMULTANEMENT

	for $art in collection("talismane")//p
	for $elt in $art/item
	let $conc2 :=
	  if (($elt/a[4]/text()="NC") and ($elt/following-sibling::item[1]/a[4]/text()="P") and ($elt/following-sibling::item[2]/a[4]/text()="NC") and ($elt/following-sibling::item[3]/a[4]/text()="P") and ($elt/following-sibling::item[4]/a[4]/text()="NC")) then (
		concat($elt/a[2]/text()," ",$elt/following-sibling::item[1]/a[2]/text()," ",$elt/following-sibling::item[2]/a[2]/text()," ",$elt/following-sibling::item[3]/a[2]/text()," ",$elt/following-sibling::item[4]/a[2]/text())
	  )
	  else if (($elt/a[4]/text()="NC") and ($elt/following-sibling::item[1]/a[4]/text()="ADJ")) then (
		   concat($elt/a[2]/text()," ",$elt/following-sibling::item[1]/a[2]/text())
	  )
	  else if (($elt/a[4]/text()="ADJ") and ($elt/following-sibling::item[1]/a[4]/text()="NC")) then (
		   concat($elt/a[2]/text()," ",$elt/following-sibling::item[1]/a[2]/text())
	  )
	  else if (($elt/a[4]/text()="V") and ($elt/following-sibling::item[1]/a[4]/text()="DET") and ($elt/following-sibling::item[2]/a[4]/text()="NC")) then (
		   concat($elt/a[2]/text()," ",$elt/following-sibling::item[1]/a[2]/text()," ",$elt/following-sibling::item[2]/a[2]/text())
	  )
	  else (
		"
"
	  )
	where $conc2 != "
"
	return $conc2

	TOUS LES PATRONS SIMULTANEMENT AVEC TRI ET COMPTAGE

	declare variable $count as xs:integer := 0;
	for $art in collection("talismane")//p

	for $elt in $art/item
	let $conc2 :=
	  if (($elt/a[4]/text()="NC") and ($elt/following-sibling::item[1]/a[4]/text()="P") and ($elt/following-sibling::item[2]/a[4]/text()="NC") and ($elt/following-sibling::item[3]/a[4]/text()="P") and ($elt/following-sibling::item[4]/a[4]/text()="NC")) then (
		concat($elt/a[2]/text()," ",$elt/following-sibling::item[1]/a[2]/text()," ",$elt/following-sibling::item[2]/a[2]/text()," ",$elt/following-sibling::item[3]/a[2]/text()," ",$elt/following-sibling::item[4]/a[2]/text())
	  )
	  else if (($elt/a[4]/text()="NC") and ($elt/following-sibling::item[1]/a[4]/text()="ADJ")) then (
		   concat($elt/a[2]/text()," ",$elt/following-sibling::item[1]/a[2]/text())
	  )
	  else if (($elt/a[4]/text()="ADJ") and ($elt/following-sibling::item[1]/a[4]/text()="NC")) then (
		   concat($elt/a[2]/text()," ",$elt/following-sibling::item[1]/a[2]/text())
	  )
	  else if (($elt/a[4]/text()="V") and ($elt/following-sibling::item[1]/a[4]/text()="DET") and ($elt/following-sibling::item[2]/a[4]/text()="NC")) then (
		   concat($elt/a[2]/text()," ",$elt/following-sibling::item[1]/a[2]/text()," ",$elt/following-sibling::item[2]/a[2]/text())
	  )
	  else (
	      "
"
		  )
	where $conc2 != "
"
	group by $g:= $conc2
	order by count($conc2) descending 
	return string-join(($g,count($conc2)), "	")
											
										

Voici les résultats pour chaque rubrique:

<< Perl | < Xquery | XSLT > | HAUT

PARTIE XSLT

Pour cette dernière méthode, nous utilisons les fichiers Tree-tagger sous format xml. Avec Notepad ++ ou Oxygen, il faut donc créer des feuilles de style pour faire sortir les patrons demandés.

										
		<?xml version="1.0" encoding="utf-8"?>
		<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
		<xsl:output method="text" encoding="utf-8"/>
		<xsl:template match="/">
		<xsl:apply-templates select=".//article"/>
		</xsl:template>


		<xsl:template match="article">
		<xsl:for-each select="element">
			<xsl:if test="(./data[1][starts-with(text(),'VER')])">
			  <xsl:variable name="p1" select="./data[3]/text()"/>
				<xsl:if test="following-sibling::element[1][./data[1][contains(text(),'DET')]]">
						<xsl:variable name="p2" select="following-sibling::element[1]/data[3]/text()"/>    
						<xsl:if test="following-sibling::element[2][./data[1][contains(text(),'NOM')]]">
							<xsl:variable name="p3" select="following-sibling::element[2]/data[3]/text()"/>    
							<xsl:value-of select="$p1"/><xsl:text> </xsl:text><xsl:value-of select="$p2"/><xsl:text> </xsl:text><xsl:value-of select="$p3"/><xsl:text>
							</xsl:text>
						</xsl:if>
				 </xsl:if>
			 </xsl:if>
		</xsl:for-each>
		</xsl:template>
		</xsl:stylesheet>

			
		

Voici les feuilles de style XSLT et les résultats, sous forme d'archive

haut de page