public static void main(String... argv) { String queryString = "SELECT * { ?s ?p ?o }"; Query query = QueryFactory.create(queryString); Store store = SDBFactory.connectStore("sdb.ttl"); // Must be a DatasetStore to trigger the SDB query engine. // Creating a graph from the Store, and adding it to a general // purpose dataset will not necesarily exploit full SQL generation. // The right answers will be obtained but slowly. Dataset ds = DatasetStore.create(store); QueryExecution qe = QueryExecutionFactory.create(query, ds); try { ResultSet rs = qe.execSelect(); ResultSetFormatter.out(rs); } finally { qe.close(); } // Close the SDB conenction which also closes the underlying JDBC connection. store.getConnection().close(); store.close(); }
public static void main(String[] args) { try { Model schema = null; Store store = null; SDBConnection conn = null; if (args.length == 1) { store = ExtendedSDBFactory.connectStore(args[0]); store.getTableFormatter().create(); schema = ExtendedSDBFactory.connectPagedDefaultModel(store); } else { StoreDesc storeDesc = new StoreDesc(args[0], args[1]); Class.forName(args[2]); String jdbcURL = args[3] + args[4]; conn = new SDBConnection(jdbcURL, args[5], args[6]); store = ExtendedSDBFactory.connectStore(conn, storeDesc); store.getTableFormatter().create(); schema = ExtendedSDBFactory.connectPagedNamedModel(store, args[7]); } long startTime = System.currentTimeMillis(), endTime = 0L, count = 0L; schema.read("http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl"); OntModel m = ExtendedModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC, schema); String sInputDirectory = args[8]; File inputDirectory = new File(sInputDirectory); String[] sFilenames = inputDirectory.list(new OWLFilenameFilter()); for (int i = 0; i < sFilenames.length; i++) { InputStream in = FileManager.get().open(sInputDirectory + sFilenames[i]); if (in == null) { throw new IllegalArgumentException("File: " + sFilenames[i] + " not found"); } m.read(in, "http://www.utdallas.edu/benchmark-test#", "RDF/XML-ABBREV"); in.close(); } endTime = System.currentTimeMillis(); System.out.println("time to read the model = " + (endTime - startTime) / 1000 + " seconds."); startTime = System.currentTimeMillis(); String queryString = " PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + " PREFIX ub: <http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl#> " + " SELECT * WHERE " + " { " + " ?x rdf:type ub:GraduateStudent . " + " ?x ub:takesCourse <http://www.Department0.University0.edu/GraduateCourse0> . " + " }"; Query query = QueryFactory.create(queryString); QueryExecution qexec = QueryExecutionFactory.create(query, m); ResultSet rs = qexec.execSelect(); while (rs.hasNext()) { count++; rs.nextSolution(); } qexec.close(); endTime = System.currentTimeMillis(); System.out.println("count = " + count); System.out.println("time to query = " + (endTime - startTime) + " milliseconds."); store.close(); conn.close(); } catch (Exception e) { e.printStackTrace(); } }