NQUADS -> TRIG … A Noddy Perl Script
I keep coming across nquads files, and libraptor doesn’t support this serialisation, it only supports quad-based TriG format. I knocked together a dirty perl file which will parse a nquads file to TriG if ever need be.
You can find the perl file on my site :
http://mmt.me.uk/examples/perl/nquads_to_trig.pl
#!/usr/bin/perl
use strict;
my $files = scalar(@ARGV);
if ($files != 1) {
print "NQuads importer. ./nquads_importer nquads_file\n";
exit();
}
my $input_filename = @ARGV[0];
open (INPUT,$input_filename) || die { print "Input file does not exist\n"};
open (OUTPUT,">$input_filename.trig") || die { print "Failed to open output file\n"};
my $line = "";
my $model_uri = "";
my $triple = "";
my $count = 0;
my %quads = ();
while (<INPUT>) {
$line = $_;
if ($line =~ m/^(.*?)(<[^>]+>?)\s*\.$/) {
$model_uri = $2;
$triple = $1.".\n";
$quads{$model_uri} .= $triple;
} else {
print ERROR "boo this nquad doesn't pass regex\n$line\n*************\n";
}
$count++;
}
foreach my $forth (keys %quads) {
print OUTPUT "$forth { ".$quads{$forth}." }\n";
}
print "Finished\n";
close(INPUT);
close(OUTPUT);
# vi:set ts=8 sts=4 sw=4 et:

October 22nd, 2010 at 6:09 pm
It supports it now! http://github.com/dajobe/raptor/commit/f01ff7a37ffba7be59581f31a18a0a543d5e3e3c
October 26th, 2010 at 11:36 am
Am guessing that is raptor2, will wait for Steve to make 4store raptor2 compatible, and then i can chuck my perl away for good