0

When loading a N3 RDF file with the below format into Sesame Repository, is it possible to tell Sesame '|' as separator?

The below triple is separated by | :

http://article.com/1-3|http://relationship.com/wasGeneratedBy|http://edit.com/comment1-2
Jeen Broekstra
  • 21,642
  • 4
  • 51
  • 73
jd466
  • 547
  • 1
  • 6
  • 20
  • 4
    It should not be possible to say that for N3 because N3 doesn't allow different separators like that. What you have simply isn't an N3 file. You should probably just preprocess the text as text and then load it as what ever format you've converted it to. And note that in your case, even if you replace | with space, it's still not N3; you'd need to wrap those IRIs with angle brackets, and add a period at the end of the triple. – Joshua Taylor May 08 '16 at 22:17

1 Answers1

3

As also indicated in the comments: the format you have simply is not N3 syntax, so you can't upload this using Sesame's N3 parser. Nor is it in any other standardized format, so there is no parser available for handling it.

However, it would be fairly simple to process a file in this format "manually" and add it to Sesame yourself. This will likely do the trick:

   try (RepositoryConnection conn = rep.getConnection()) {
      ValueFactory vf = conn.getValueFactory(); 

      File file = new File("/path/to/weirdlyformattedrdffile.txt");

      // open the file for reading
      try (BufferedReader br = new BufferedReader(new FileReader(file))) {
         String line;

         // start a transaction
         conn.begin();

         // read the file line-by-line
         while ((line = br.readLine()) != null) {
            // each line is an RDF triple with a subject, predicate, and object
            String[] triple = line.split("|");

            IRI subject = vf.createIRI(triple[0]);
            IRI predicate = vf.createIRI(triple[1]);
            IRI object = vf.createIRI(triple[2]);

            // add the triple to the database
            conn.add(subject, predicate, object);
         }                   
         // commit the txn when all lines are read
         conn.commit();
      }
   }

Of course if your file also contains other things than IRIs (for example literals or blank nodes), you will have to include some logic to distinguish these, rather than just blindly creating IRIs for everything. But that's the price you pay for not using a standardized syntax format.

Jeen Broekstra
  • 21,642
  • 4
  • 51
  • 73