]> matita.cs.unibo.it Git - helm.git/blob - helm/metadata/create_V7_mowgli/invert.pl
New version for the new DTD.
[helm.git] / helm / metadata / create_V7_mowgli / invert.pl
1 #!/usr/bin/perl
2
3 my $inputfile = $ARGV[0];
4
5 print "Now splitting file $inputfile\n";
6 open(IN, "<$inputfile") or die "Error opening file $inputfile";
7 $dummy = <IN>;  # <?xml version="1.0" encoding="ISO-8859-1"?>
8 $dummy = <IN>;  #
9 $dummy = <IN>;  # <rdf:RDF .../>
10 $where = <IN>;  # <h:Object rdf:about="...">
11 chomp($where);
12 $where =~ s/^[^"]*"([^"]*)">$/$1/;
13 while(($line1 = <IN>) && not ($line1 =~ /<\/h:Object>/)) {
14   $line2 = <IN>; # <h:Occurrence>
15   $line3 = <IN>; # <h:position>value</h:position>
16   $line4 = <IN>; # <h:occurrence>value</h:occurrence>
17   $line5 = <IN>; # </h:Occurrence>
18   $line6 = <IN>; # </refObj>
19   $uri = $line4;
20   chomp($uri);
21   $uri =~ s/^[ \t]*<h:occurrence>([^<]*)<\/h:occurrence>$/$1/;
22   $who = $uri;
23   $who =~ s/^cic:/backward/;
24   $who =~ s/#xpointer\(1\/([^\/]*)\/([^\/]*)\)/,$1,$2/;
25   $who =~ s/#xpointer\(1\/([^\/]*)\)/,$1/;
26   $line4 =~ s/\Q$uri\E/$where/;
27    
28   open(OUT, ">>$who") or die "Error opening file $who";
29   print OUT "\t\t<h:backPointer>\n";
30   print OUT $line2;
31   print OUT $line3;
32   print OUT $line4;
33   print OUT $line5;
34   print OUT "\t\t</h:backPointer>\n";
35   close(OUT);
36 }
37 close(IN);