]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/metadata/create2/invert.pl
New procedure to create metadata committed and old procedure removed.
[helm.git] / helm / metadata / create2 / invert.pl
diff --git a/helm/metadata/create2/invert.pl b/helm/metadata/create2/invert.pl
new file mode 100755 (executable)
index 0000000..5616177
--- /dev/null
@@ -0,0 +1,31 @@
+#!/usr/bin/perl
+
+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="...">
+chomp($where);
+$where =~ s/^[^"]*"([^"]*)">$/$1/;
+while(($line1 = <IN>) && not ($line1 =~ /<\/h:Object>/)) {
+  $line2 = <IN>;
+  $line3 = <IN>; # </refObj>
+  $uri = $line2;
+  chomp($uri);
+  $uri =~ s/^ *<h:Occurrence rdf:about="[^"]*" rdf:value="([^"]*)"\/>$/$1/;
+  $who = $uri;
+  $who =~ s/^cic:/backward/;
+  $who =~ s/#xpointer\(1\/([^\/]*)\/([^\/]*)\)/,$1,$2/;
+  $who =~ s/#xpointer\(1\/([^\/]*)\)/,$1/;
+  $line2 =~ s/\Q$uri\E/$where/;
+   
+  open(OUT, ">>$who") or die "Error opening file $who";
+  print OUT "    <h:backpointer>\n";
+  print OUT $line2;
+  print OUT "    </h:backpointer>\n";
+  close(OUT);
+}
+close(IN);