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 :


use strict;

my $files = scalar(@ARGV);
if ($files != 1) {
  print "NQuads importer. ./nquads_importer nquads_file\n";

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";

foreach my $forth (keys %quads) {
  print OUTPUT "$forth { ".$quads{$forth}." }\n";

print "Finished\n";

# vi:set ts=8 sts=4 sw=4 et:


Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.