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

AGSparqlGraphs.java

package com.franz.ag.examples;

import com.franz.ag.*;
import org.openrdf.model.URI;

public class AGSparqlGraphs {

    /**
     * Demonstrates how to perform named graph queries in SPARQL.
     * 
     * @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("sparqlnamedgraphs", AGPaths.TRIPLE_STORES);
        
        // Load N-Triples data into a named graph
        URI g = ts.createURI("http://example.org/kennedy/");
        long n = ts.loadNTriples(AGPaths.dataSources("kennedy.ntriples"), g);
        System.out.println("Loaded " + n + " triples.");
        
        // Get some triples from a given graph g and show them.
        Cursor cc = ts.getStatements(null, null, ts.createLiteral("Arnold"), g);
        AGUtils.showTriples(cc);
        
        // Query for the first 20 place names ordered by name 
        String query =
        "PREFIX ex: <http://example.org/kennedy/> " +
        "SELECT ?name " +
        "FROM NAMED <http://example.org/kennedy/> " +
        "WHERE { GRAPH ex: { " +
          "?place ex:name ?name " +
        "}} " +
        "ORDER BY ?name " +
        "LIMIT 20";

        AGUtils.doSparqlSelect(ts, query);

        // Close the store and disconnect from the server.
        ts.closeTripleStore();
        ags.disable();
    }

}

Up | Next

 

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