Search code examples
triplestorerdf4j

How can I decrypt the Triplestore files of an RDF4J database?


I am currently trying to read the files of an RDF4J triplestore from the universAAL platform and put them into an InfluxDB to merge the data from different smart living systems. However, I have noticed that the individual index files of the Native repository are encrypted/unreadable (See image below). Is there any experience from the community on how to get human readable content out of the RDF4J files (namespace, triples.prop, triples-cosp, triples-posc, triples-spoc, values.hash, values.dat, values.id) and merge them into another database? The documentation of RDF4J did not help me here, so I could not create a decent export.

Encrypted File from Triplestore


Solution

  • The files are not encrypted, they're simply a binary format, optimized for efficient storage and retrieval, used by RDF4J's Native Store database implementation. They're not meant for direct manipulation.

    The easiest way to convert them to readable RDF is to spin up a Native Store on top of them and then use the RDF4J API to query/export its data. Assuming you have a complete set of data files it should be as simple as something like this:

    Repository rep = new SailRepository(new NativeStore(new File("/path/to/datafiles/");
    
    try(RepositoryConnection conn = rep.getConnection()) {
        conn.export(Rio.createWriter(RDFFormat.TURTLE, System.out));
    }
    finally {
        rep.shutDown();
    }
    

    Obviously, replace System.out with a FileOutputstream if you want to write the data to file rather than the console. And change RDFFormat.TURTLE to something else if you want a different syntax format.