]> matita.cs.unibo.it Git - helm.git/blob - helm/metadata/create_V7_mowgli/invert.pl
- the mathql interpreter is not helm-dependent any more
[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 my $where;
8 while(($where = <IN>) && not ($where =~ /<h:Object/)) {}
9 chomp($where);
10 $where =~ s/^[^"]*"([^"]*)">$/$1/;
11 while(($line1 = <IN>) && not ($line1 =~ /<\/h:Object>/)) { # <h:refObj
12   $line2 = <IN>; # <h:position rdf:resource="&hns;value"/>
13   $position = $line2;
14   chomp($position);
15   $position =~ s/^[ \t]*[^"]*"&hns;([^"]*)"\/>/$1/;
16   if ($position eq 'MainHypothesis' || $position eq 'MainConclusion') {
17      $line3 = <IN>; # <h:depth>value</h:depth>
18   }
19   $line4 = <IN>; # <h:occurrence><h:Object rdf:about="value"/></h:occurrence>
20   $line5 = <IN>; # </h:refObj>
21   $uri = $line4;
22   chomp($uri);
23   $uri =~ s/^[ \t]*<h:occurrence><h:Object rdf:about="([^"]*)"\/><\/h:occurrence>$/$1/;
24   $who = $uri;
25   $who =~ s/^cic:/backward/;
26   $who =~ s/#xpointer\(1\/([^\/]*)\/([^\/]*)\)/,$1,$2/;
27   $who =~ s/#xpointer\(1\/([^\/]*)\)/,$1/;
28   $line4 =~ s/\Q$uri\E/$where/;
29    
30   open(OUT, ">>$who") or die "Error opening file $who";
31   print OUT "\t\t<h:backPointer rdf:parseType="Resource">\n";
32   print OUT $line2;
33   if ($position eq 'MainHypothesis' || $position eq 'MainConclusion') {
34      print OUT $line3;
35   }
36   print OUT $line4;
37   print OUT "\t\t</h:backPointer>\n";
38   close(OUT);
39 }
40 close(IN);