AGSerializers.java

package com.franz.ag.examples;

import com.franz.ag.*;

public class AGSerializers {

    /**
     * Demonstrates how to load a triple store from an N-Triples file.
     * 
     * @param args unused
     * @throws AllegroGraphException
     */
    public static void main(String[] args) throws AllegroGraphException {
        // Connect to server, which must already be running.
        AllegroGraphConnection ags = new AllegroGraphConnection();
        try {
            ags.enable();
        } catch (Exception e) {
            throw new AllegroGraphException("Server connection problem", e);
        }

        // Create fresh triple-store.
        AllegroGraph ts = ags.renew("serializers", AGPaths.TRIPLE_STORES);
        
        // Load the file in N-Triples format
        String ntripleFile = AGPaths.dataSources("temporal.nt");        
        System.out.println("Loading N-Triples " + ntripleFile);
        ts.loadNTriples(ntripleFile);
        System.out.println("Loaded " + ts.numberOfTriples() + " triples.");
        
        NTriplesSerializer ntser = new NTriplesSerializer();
        ntser.setDestination(AGPaths.dataSources("temporal-serialized.nt"));
        ntser.setIfExists("supersede");
        ntser.run(ts);
        
        RDFSerializer rdfser = new RDFSerializer();
        rdfser.setDestination(AGPaths.dataSources("temporal-serialized.rdf"));
        rdfser.setIfExists("supersede");
        rdfser.run(ts);
        
        RDFN3Serializer rdfn3ser = new RDFN3Serializer();
        rdfn3ser.setDestination(AGPaths.dataSources("temporal-serialized.n3"));
        rdfn3ser.setIfExists("supersede");
        rdfn3ser.run(ts);
        
        RDFManifestSerializer rdfmanser = new RDFManifestSerializer();
        rdfmanser.setDestination(AGPaths.dataSources("temporal-serialized.manifest"));
        rdfmanser.run(ts);
        
        
        // Close the store and disconnect from the server.
        ts.closeTripleStore();
        ags.disable();
    }

}

Up | Next