/* * (c) Copyright 2007, 2008, 2009 Hewlett-Packard Development Company, LP * All rights reserved. * [See end of file] */ package dev; import java.io.FileInputStream ; import java.io.IOException ; import java.io.InputStream ; import perf.Performance ; import atlas.iterator.Filter ; import atlas.lib.Tuple ; import atlas.logging.Log ; import com.hp.hpl.jena.graph.Node ; import com.hp.hpl.jena.query.Dataset ; import com.hp.hpl.jena.riot.JenaReaderTurtle2 ; import com.hp.hpl.jena.tdb.TDB ; import com.hp.hpl.jena.tdb.TDBFactory ; import com.hp.hpl.jena.tdb.nodetable.NodeTable ; import com.hp.hpl.jena.tdb.store.DatasetGraphTDB ; import com.hp.hpl.jena.tdb.store.NodeId ; import com.hp.hpl.jena.tdb.sys.SystemTDB ; public class RunTDB { static { Log.setLog4j() ; } static String divider = "----------" ; static String nextDivider = null ; static void divider() { if ( nextDivider != null ) System.out.println(nextDivider) ; nextDivider = divider ; } public static void main(String ... args) throws IOException { if ( args.length == 0 ) args = new String[]{"/home/afs/Datasets/BSBM/bsbm-1m.nt.gz"} ; //Performance.tokenizer(args[0]) ; System.exit(0) ; Performance.turtle(args[0]) ; System.exit(0) ; tdb.turtle.main("D.ttl") ; System.exit(0) ; DevCmds.tdbquery("--tdb=tdb.ttl", "--set=tdb:logExec=info", "SELECT * {GRAPH ?g { ?s ?p ?o}}") ; System.exit(0) ; } static void tupleFilter() { Dataset ds = TDBFactory.createDataset("DB") ; DatasetGraphTDB dsg = (DatasetGraphTDB)(ds.asDatasetGraph()) ; final NodeTable nodeTable = dsg.getQuadTable().getNodeTupleTable().getNodeTable() ; final NodeId target = nodeTable.getNodeIdForNode(Node.createURI("http://example/graph2")) ; System.out.println("Filter: "+target) ; Filter> filter = new Filter>() { public boolean accept(Tuple item) { // Reverse the lookup as a demo Node n = nodeTable.getNodeForNodeId(target) ; //System.err.println(item) ; if ( item.size() == 4 && item.get(0).equals(target) ) { System.out.println("Reject: "+item) ; return false ; } System.out.println("Accept: "+item) ; return true ; } } ; TDB.getContext().set(SystemTDB.symTupleFilter, filter) ; String qs = "SELECT * { { ?s ?p ?o } UNION { GRAPH ?g { ?s ?p ?o } }}" ; //String qs = "SELECT * { GRAPH ?g { ?s ?p ?o } }" ; DevCmds.tdbquery("--tdb=tdb.ttl", qs) ; } public static void turtle2() throws IOException { // Also tdb.turtle. // TDB.init(); // RDFWriter w = new JenaWriterNTriples2() ; // Model model = FileManager.get().loadModel("D.ttl") ; // w.write(model, System.out, null) ; // System.exit(0) ; InputStream input = new FileInputStream("D.ttl") ; JenaReaderTurtle2.parse(input) ; System.out.println("END") ; System.exit(0) ; } } /* * (c) Copyright 2007, 2008, 2009 Hewlett-Packard Development Company, LP * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */