]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/metadata/create_V7_mowgli/invert.pl
Initial revision
[helm.git] / helm / metadata / create_V7_mowgli / invert.pl
index df345064965eef4048f339c0df172b63a23878b0..9024799209851620fcff0d03064221b3d96abe42 100755 (executable)
@@ -4,21 +4,23 @@ my $inputfile = $ARGV[0];
 
 print "Now splitting file $inputfile\n";
 open(IN, "<$inputfile") or die "Error opening file $inputfile";
-$dummy = <IN>;  # <?xml version="1.0" encoding="ISO-8859-1"?>
-$dummy = <IN>;  #
-$dummy = <IN>;  # <rdf:RDF .../>
-$where = <IN>;  # <h:Object rdf:about="...">
+my $where;
+while(($where = <IN>) && not ($where =~ /<h:Object/)) {}
 chomp($where);
 $where =~ s/^[^"]*"([^"]*)">$/$1/;
-while(($line1 = <IN>) && not ($line1 =~ /<\/h:Object>/)) {
-  $line2 = <IN>; # <h:Occurrence>
-  $line3 = <IN>; # <h:position>value</h:position>
-  $line4 = <IN>; # <h:occurrence>value</h:occurrence>
-  $line5 = <IN>; # </h:Occurrence>
-  $line6 = <IN>; # </refObj>
+while(($line1 = <IN>) && not ($line1 =~ /<\/h:Object>/)) { # <h:refObj
+  $line2 = <IN>; # <h:position rdf:resource="&hns;value"/>
+  $position = $line2;
+  chomp($position);
+  $position =~ s/^[ \t]*[^"]*"&hns;([^"]*)"\/>/$1/;
+  if ($position eq 'MainHypothesis' || $position eq 'MainConclusion') {
+     $line3 = <IN>; # <h:depth>value</h:depth>
+  }
+  $line4 = <IN>; # <h:occurrence><h:Object rdf:about="value"/></h:occurrence>
+  $line5 = <IN>; # </h:refObj>
   $uri = $line4;
   chomp($uri);
-  $uri =~ s/^[ \t]*<h:occurrence>([^<]*)<\/h:occurrence>$/$1/;
+  $uri =~ s/^[ \t]*<h:occurrence><h:Object rdf:about="([^"]*)"\/><\/h:occurrence>$/$1/;
   $who = $uri;
   $who =~ s/^cic:/backward/;
   $who =~ s/#xpointer\(1\/([^\/]*)\/([^\/]*)\)/,$1,$2/;
@@ -26,11 +28,12 @@ while(($line1 = <IN>) && not ($line1 =~ /<\/h:Object>/)) {
   $line4 =~ s/\Q$uri\E/$where/;
    
   open(OUT, ">>$who") or die "Error opening file $who";
-  print OUT "\t\t<h:backPointer>\n";
+  print OUT "\t\t<h:backPointer rdf:parseType="Resource">\n";
   print OUT $line2;
-  print OUT $line3;
+  if ($position eq 'MainHypothesis' || $position eq 'MainConclusion') {
+     print OUT $line3;
+  }
   print OUT $line4;
-  print OUT $line5;
   print OUT "\t\t</h:backPointer>\n";
   close(OUT);
 }