package com.franz.agbase.examples; import com.franz.agbase.*; public class CSC8711_Presentation { /** *Create for Presentation of CSC8711 Spring 2011 */ public static void main(String[] args) throws AllegroGraphException { // Connect to the default server, which must already be running. AllegroGraphConnection ags = new AllegroGraphConnection(); try { //System.out.println("Attempting to connect to the server on port " + ags.getPort()); ags.enable(); } catch (Exception e) { throw new AllegroGraphException("Server connection problem -- please ensure the server is running.", e); } //Creating Triple store System.out.println("Attempting to create a triple store."); try { AllegroGraph ts = ags.renew("ts_CSC8711", AGPaths.TRIPLE_STORES); System.out.println("Triple store created."); // Load a file in N-Triples format String ntripleFile = AGPaths.dataSources("kennedy.ntriples"); System.out.println("Loading N-Triples " + ntripleFile); ts.loadNTriples(ntripleFile); System.out.println("Loaded " + ts.numberOfTriples() + " triples."); // Get all triples from the default graph and show them. TriplesIterator it = ts.getStatements("", null, null); AGUtils.showTriples(it); String query = "SELECT ?person ?fname WHERE { ?person ; ?fname . FILTER ( ?fname = ) }"; // Query the store and show the results SPARQLQuery sq = new SPARQLQuery(); sq.setTripleStore(ts); sq.setQuery(query); AGSparqlSelect.doSparqlSelect(sq); //add triple ts.addStatement("", "", ""); System.out.println("\nOne Triple has been added ... \n"); String query2 = "SELECT ?person ?fname WHERE { ?person ; ?fname . FILTER ( ?fname = ) }"; // Query the store and show the results SPARQLQuery sq2 = new SPARQLQuery(); sq2.setTripleStore(ts); sq2.setQuery(query2); AGSparqlSelect.doSparqlSelect(sq2); // Close the triple store System.out.println("Closing the triple store."); ts.closeTripleStore(); } catch (Exception e) { System.out.println(e.getMessage()); } // Disconnect from the server //System.out.println("Disconnecting from the server."); ags.disable(); System.out.println("Done."); } // main ends /** * Load a single NTriples file into the default graph and time the load. * * @param ts A triple store * @param ntriplesFile A server-accessible NTriples file * @throws AllegroGraphException */ public static void loadNTriplesWithTiming(AllegroGraph ts, String ntriplesFile) throws AllegroGraphException { AGLoadNtriples.loadNTriplesWithTiming(ts, ntriplesFile, ""); } /** * Load a single NTriples file into the specified graph and time the load. * * @param ts A triple store * @param ntriplesFile A server-accessible NTriples file * @param graph The context to load * @throws AllegroGraphException */ public static void loadNTriplesWithTiming(AllegroGraph ts, String ntriplesFile, String graph) throws AllegroGraphException { System.out.println("Loading N-Triples from " + ntriplesFile); long start = System.currentTimeMillis(); long n = ts.loadNTriples(ntriplesFile,graph,false,null,null); System.out.println("Loaded " + n + " triples in " + AGUtils.elapsedTime(start)); } /** * Load an array of NTriples files into the specified graph and time the load. * * @param ts A triple store * @param ntriplesFiles An array of server-accessible NTriples files * @param graph The context to load * @return * @throws AllegroGraphException */ public static long loadNTriplesWithTiming(AllegroGraph ts, String[] ntriplesFiles, String graph) throws AllegroGraphException { System.out.println("Loading " + ntriplesFiles.length + " N-Triples files."); long start = System.currentTimeMillis(); long n = ts.loadNTriples(ntriplesFiles,graph,false,null,null); System.out.println("Loaded " + n + " triples in " + AGUtils.elapsedTime(start)); return n; } } //class ends