tagLem2xml.pl
1022 Bytes
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
#!/usr/bin/perl
if($#ARGV != 1){
print("usage : ./tagLemm2xml <fichier.tagLem> <fichier.doc.xml>");
exit(1);
}
open(TAG, "<$ARGV[0]");
open(XML, ">$ARGV[1]");
print XML "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<!DOCTYPE Segmentation>\n<Segmentation>\n<seg>\n";
$chaineLem = "";
$newshow = 0;
while(<TAG>){
$line = $_;
chomp($line);
@tempo=split(/ /, $line);
if($tempo[2] !~ m/#[0-9]*/){
print XML "$tempo[0] ";
$newseg=0;
if($tempo[1] !~ m/MOTINC/){
if($tempo[1] =~ m/^X.*/){
$poids = 10;
}
else{
$poids = 1;
}
$chaineLem .= "\t\t<lem poids=\"". $poids ."\"> ".$tempo[2]." </lem>\n" ;
}
else{
$chaineLem .=" ";
}
}
else{
if($chaineLem ne "" || $newshow == 1){
print XML ".\n\t</wd>\n$chaineLem</phr>\n<phr>\n\t<wd>\n\t\t$tempo[2] ";
}
else{
print XML "$chaineLem<phr>\n\t<wd>\n\t\t$tempo[2] ";
$newshow=1;
}
$chaineLem="";
}
}
print XML "\n\t</wd>\n$chaineLem</phr>\n</seg>\n</Segmentation>";
close(XML);
close(TAG);