How to convert a Trig file to a Turtle file so that i can upload it in Sesame?

888 views Asked by At
{
    ex:repository ex:createdBy ex:repOwner; ex:title “Rep_1”.

}
ex:books 
{
    ex:book_1 a ex:Science; ex:size “100”; ex:title “Science book 1”.
    ex:book_2 a ex:Science; ex:size “1000”; ex:title “Science book 2”. 
    ex:book_3 a ex:Fantasy; ex:size “100”; ex:title “Fantasy book 1”.
}
1

There are 1 answers

0
Jeen Broekstra On

It is not necessary to convert a TriG file to Turtle to upload it to Sesame, as Sesame supports the TriG format.

Moreover, conversion from TriG to Turtle loses data: TriG is a format that can record quads, so you can put several named graphs in one file, while Turtle only records triples. If you convert TriG to Turtle, you will remove all the named graph information.

Having said all that, conversion from one format to another is simple in Sesame:

// writing to System.out as an example, change to a fileoutputstream to write to file
RDFWriter turtleWriter = Rio.createWriter(RDFFormat.TURTLE, System.out);
RDFParser trigParser = Rio.createParser(RDFFormat.TRIG);

// link the parser with the writer
trigParser.setRDFHandler(turtleWriter);

File trigFile = new File("/path/to/file.trig");

trigParser.parse(new FileInputStream(trigFile), trigFile.getAbsolutePath());