AGIndexAllTriples.java
package com.franz.agbase.examples;
import com.franz.agbase.*;
public class AGIndexAllTriples {
@param
@throws
public static void main(String[] args) throws AllegroGraphException {
AllegroGraphConnection ags = new AllegroGraphConnection();
try {
ags.enable();
} catch (Exception e) {
throw new AllegroGraphException("Server connection problem", e);
}
AllegroGraph ts = ags.renew("wilburwine", AGPaths.TRIPLE_STORES);
String ntripleFile = AGPaths.dataSources("wilburwine.ntriples");
System.out.println("Loading N-Triples " + ntripleFile);
AGLoadNtriples.loadNTriplesWithTiming(ts,ntripleFile);
ts.registerNamespace("wine", "http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#");
System.out.println("Triples with Subject: CabernetSauvignonGrape");
long t0 = System.nanoTime();
TriplesIterator cc = ts.getStatements("!wine:CabernetSauvignonGrape",null, null);
AGUtils.showTriples(cc);
long t1 = System.nanoTime();
System.out.println("Query (before indexing) took " + (long)(t1-t0) + " nanoseconds");
ts.indexAllTriples();
System.out.println("Triples with Subject: CabernetSauvignonGrape");
long t2 = System.nanoTime();
cc = ts.getStatements("!wine:CabernetSauvignonGrape",null, null);
AGUtils.showTriples(cc);
long t3 = System.nanoTime();
System.out.println("Query (after indexing) took " + (long)(t3-t2) + " nanoseconds");
ts.closeTripleStore();
ags.disable();
}
public static void indexAllTriplesWithTiming(AllegroGraph ts) throws AllegroGraphException {
System.out.print("Indexing...");
long start = System.currentTimeMillis();
ts.indexAllTriples(true);
System.out.println("done in " + AGUtils.elapsedTime(start));
}
}
Up |
Next