#!/usr/bin/perl

my $inputfile = $ARGV[0];

#print "Now splitting file $inputfile\n";
open(IN, "<$inputfile") or die "Error opening file $inputfile";
while(($skip = <IN>) && not ($skip =~ /<rdf:RDF/)) {}
while(($line0 = <IN>) && not ($line0 =~ /<\/rdf:RDF>/)) { # <h:Object
  chomp($line0);
  $line0 =~ s/^[^"]*"([^"]*)">$/$1/;
  $line1 = <IN>; #<h:refRel..
  $obj = $line1;
  $line2 = <IN>; # <h:position rdf:resource="&hns;value"/>
  $position = $line2;
  chomp($position);
  $position =~ s/^[ \t]*[^"]*"&hns;([^"]*)"\/>/$1/;
  $position = "http://www.cs.unibo.it/helm/schemas/schema-helm#$position";
  $line3 = <IN>;#<h:sort..
  $sort = $line3; 
  chomp($sort);
  $sort =~ s/^[ \t]*[^"]*"&hns;([^"]*)"\/>/$1/;
  $sort = "http://www.cs.unibo.it/helm/schemas/schema-helm#$sort";
  $line4 = <IN>; #<h:depth..
  $depth = $line4;
  chomp($depth);
  $depth =~ s/^[ \t]*<h:depth>([^<]*)<\/h:depth>$/$1/;
  $line5 = <IN>; # </h:refRel
  $line6 = <IN>; # </h:Object>
   
  $line0 =~ s/'/\\'/g; 
  $position =~ s/'/\\'/g;
  $depth =~ s/'/\\'/g;
  $sort =~ s/'/\\'/g;
  print "insert into hrefSort values ('$line0', '$position', '$sort', $depth);\n\n";
}
close(IN);
