franz inc logo  
  download learning center franz inc search franz inc resources franz inc          

allegrograph
racer
tbc
services
support
  Learning Center
  Documentation
  Updates
     Info
  FAQ
about

RSS Feeds

AllegroServe at opensource.franz.com

AGLoadRDF.java

package com.franz.ag.examples;

import com.franz.ag.*;

import org.openrdf.model.URI;

public class AGLoadRDF {

    /**
     * Demonstrates loading a triple store from files in RDF/XML format.
     * 
     * @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 a fresh triple store.
        AllegroGraph ts = ags.renew("loadRDF", AGPaths.TRIPLE_STORES);

        // Load a server-side file in RDF/XML format into the store's default graph.
        loadRDFWithTiming(ts, AGPaths.dataSources("rdf-axioms.rdf"));

        // Get some triples from the default graph and show them.
        Cursor cc = ts.getStatements(null, null, null);
        AGUtils.showTriples(cc, 20);
        
        // Load RDF data into a named graph
        URI g = ts.createURI("http://example.org/wilburwine");
        loadRDFWithTiming(ts, AGPaths.dataSources("wilburwine.rdf"), g);

        // Get some triples from the named graph g and show them.
        cc = ts.getStatements(null, null, null, g);
        AGUtils.showTriples(cc, 20);
        
        // Load RDF/XML from a URL into a graph named by the URL
        ts.loadRDF("http://www.w3.org/TR/owl-guide/wine.rdf","source");
            
        // Get some triples from the named graph and show them.
        cc = ts.getStatements(null, null, null,"<http://www.w3.org/TR/owl-guide/wine.rdf>");
        AGUtils.showTriples(cc, 20);
        
        // If you have a number of files to load, it is more efficient to
        // provide an array of filenames rather than loading them separately.
        String[] files = { 
                AGPaths.dataSources("Geonames_v2.0_Lite.rdf"),
                AGPaths.dataSources("iswc-aswc-2007-complete.rdf")
        };
        System.out.println("Loading multiple files ...");
        long n = ts.loadRDF(files);
        System.out.println("Loaded " + n + " triples.");
        
        // Close the triple store and disconnect from the server.
        ts.closeTripleStore();
        ags.disable();
    }
    
    public static void loadRDFWithTiming(AllegroGraph ts, String rdfFile) throws AllegroGraphException {
        loadRDFWithTiming(ts, rdfFile, "");
    }
    
    public static void loadRDFWithTiming(AllegroGraph ts, String rdfFile, Object graph) throws AllegroGraphException {
        System.out.println("Loading RDF from " + rdfFile);
        long start = System.currentTimeMillis();
        long n = ts.loadRDF(rdfFile, graph);
        System.out.println("Done loading " + n + " triples in " + AGUtils.elapsedTime(start));
    }
}

Up | Next

 

© 2008 Franz Inc - Privacy Statement
[ Consulting Services | Franz | TopQuadrant | Racer Systems ]