jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1461087 - in /jena/trunk/jena-tdb/src-examples/tdb/examples: ExQuadFilter.java ExTDB3.java ExTDB5.java ExTDB6.java ExTDB_Txn2.java
Date Tue, 26 Mar 2013 12:36:45 GMT
Author: andy
Date: Tue Mar 26 12:36:44 2013
New Revision: 1461087

URL: http://svn.apache.org/r1461087
Log:
JENA-2 : Example of TDB + JENA API.

+ some general cleaning of examples (more needed!)

Added:
    jena/trunk/jena-tdb/src-examples/tdb/examples/ExTDB6.java
Modified:
    jena/trunk/jena-tdb/src-examples/tdb/examples/ExQuadFilter.java
    jena/trunk/jena-tdb/src-examples/tdb/examples/ExTDB3.java
    jena/trunk/jena-tdb/src-examples/tdb/examples/ExTDB5.java
    jena/trunk/jena-tdb/src-examples/tdb/examples/ExTDB_Txn2.java

Modified: jena/trunk/jena-tdb/src-examples/tdb/examples/ExQuadFilter.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src-examples/tdb/examples/ExQuadFilter.java?rev=1461087&r1=1461086&r2=1461087&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src-examples/tdb/examples/ExQuadFilter.java (original)
+++ jena/trunk/jena-tdb/src-examples/tdb/examples/ExQuadFilter.java Tue Mar 26 12:36:44 2013
@@ -18,10 +18,10 @@
 
 package tdb.examples;
 
-import org.openjena.atlas.iterator.Filter ;
-import org.openjena.atlas.lib.Tuple ;
+import org.apache.jena.atlas.iterator.Filter ;
+import org.apache.jena.atlas.lib.Tuple ;
 
-import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.graph.NodeFactory ;
 import com.hp.hpl.jena.query.* ;
 import com.hp.hpl.jena.sparql.core.DatasetGraph ;
 import com.hp.hpl.jena.sparql.core.Quad ;
@@ -71,7 +71,7 @@ public class ExQuadFilter
     {
         // Filtering operates at a very low level: 
         // Need to know the internal identifier for the graph name. 
-        final NodeId target = TDBInternal.getNodeId(ds, Node.createURI(graphToHide)) ;
+        final NodeId target = TDBInternal.getNodeId(ds, NodeFactory.createURI(graphToHide))
;
 
         System.out.println("Hide graph: "+graphToHide+" --> "+target) ;
         

Modified: jena/trunk/jena-tdb/src-examples/tdb/examples/ExTDB3.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src-examples/tdb/examples/ExTDB3.java?rev=1461087&r1=1461086&r2=1461087&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src-examples/tdb/examples/ExTDB3.java (original)
+++ jena/trunk/jena-tdb/src-examples/tdb/examples/ExTDB3.java Tue Mar 26 12:36:44 2013
@@ -18,20 +18,17 @@
 
 package tdb.examples;
 
-import com.hp.hpl.jena.query.Dataset ;
-import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.rdf.model.Resource;
-
-import com.hp.hpl.jena.util.FileManager;
-
-import com.hp.hpl.jena.assembler.Assembler;
-import com.hp.hpl.jena.shared.JenaException;
+import org.apache.jena.riot.RDFDataMgr ;
 
-import com.hp.hpl.jena.sparql.core.assembler.DatasetAssemblerVocab;
-import com.hp.hpl.jena.sparql.util.TypeNotUniqueException;
-import com.hp.hpl.jena.sparql.util.graph.GraphUtils;
-
-import com.hp.hpl.jena.tdb.assembler.VocabTDB;
+import com.hp.hpl.jena.assembler.Assembler ;
+import com.hp.hpl.jena.query.Dataset ;
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.rdf.model.Resource ;
+import com.hp.hpl.jena.shared.JenaException ;
+import com.hp.hpl.jena.sparql.core.assembler.DatasetAssemblerVocab ;
+import com.hp.hpl.jena.sparql.util.TypeNotUniqueException ;
+import com.hp.hpl.jena.sparql.util.graph.GraphUtils ;
+import com.hp.hpl.jena.tdb.assembler.VocabTDB ;
 
 /** 
  * Examples of finding an assembler for a TDB model in a larger collection
@@ -44,7 +41,7 @@ public class ExTDB3
         String assemblerFile = "Store/tdb-assembler.ttl" ;
         
         // Find a particular description in the file where there are several: 
-        Model spec = FileManager.get().loadModel(assemblerFile) ;
+        Model spec = RDFDataMgr.loadModel(assemblerFile) ;
 
         // Find the right starting point for the description in some way.
         Resource root = null ;

Modified: jena/trunk/jena-tdb/src-examples/tdb/examples/ExTDB5.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src-examples/tdb/examples/ExTDB5.java?rev=1461087&r1=1461086&r2=1461087&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src-examples/tdb/examples/ExTDB5.java (original)
+++ jena/trunk/jena-tdb/src-examples/tdb/examples/ExTDB5.java Tue Mar 26 12:36:44 2013
@@ -35,6 +35,8 @@ import com.hp.hpl.jena.tdb.TDBFactory ;
  *  All the Jena APIs work on the model.
  *   
  *  Calling TDBFactory is the only place TDB-specific code is needed.
+ *  
+ *  See also ExTDB_Txn1 for use with transactions.
  */
 
 public class ExTDB5

Added: jena/trunk/jena-tdb/src-examples/tdb/examples/ExTDB6.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src-examples/tdb/examples/ExTDB6.java?rev=1461087&view=auto
==============================================================================
--- jena/trunk/jena-tdb/src-examples/tdb/examples/ExTDB6.java (added)
+++ jena/trunk/jena-tdb/src-examples/tdb/examples/ExTDB6.java Tue Mar 26 12:36:44 2013
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tdb.examples;
+
+import static java.lang.System.out ;
+
+import java.util.Iterator ;
+
+import org.apache.jena.iri.IRIFactory ;
+
+import com.hp.hpl.jena.graph.Graph ;
+import com.hp.hpl.jena.query.* ;
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.rdf.model.Property ;
+import com.hp.hpl.jena.rdf.model.Resource ;
+import com.hp.hpl.jena.rdf.model.Statement ;
+import com.hp.hpl.jena.tdb.TDB ;
+import com.hp.hpl.jena.tdb.TDBFactory ;
+
+/** Example of single threaded use of TDB workign with the Jena RDF API */
+public class ExTDB6
+{
+    /// observe the non-http "protocol", because it is a bad precident
+    /// to only use http IRI when there is no http protocol involved
+    public static final String MY_NS =
+        "x-ns://example.org/ns1/";
+
+    public static void main(String[] args) throws Exception {
+        /// turn off the "No BGP optimizer warning"
+        TDB.setOptimizerWarningFlag(false);
+
+        final IRIFactory iriFactory = IRIFactory.semanticWebImplementation();
+
+        final String DATASET_DIR_NAME = "data0";
+        final Dataset data0 = TDBFactory.createDataset( DATASET_DIR_NAME );
+
+        // show the currently registered names
+        for (Iterator<String> it = data0.listNames(); it.hasNext(); ) {
+            out.println("NAME="+it.next());
+        }
+
+        out.println("getting named model...");
+        /// this is the OWL portion
+        final Model model = data0.getNamedModel( MY_NS );
+        out.println("Model := "+model);
+
+        out.println("getting graph...");
+        /// this is the DATA in that MODEL
+        final Graph graph = model.getGraph();
+        out.println("Graph := "+graph);
+
+        if (graph.isEmpty()) {
+            final Resource product1 = model.createResource(
+                    iriFactory.construct( MY_NS +"product/1" )
+                        .toString() );
+
+            final Property hasName = model.createProperty( MY_NS, "#hasName");
+            final Statement stmt = model.createStatement(
+                    product1, hasName, model.createLiteral("Beach Ball","en") );
+            out.println("Statement = " + stmt);
+
+            model.add(stmt);
+
+            // just for fun
+            out.println("Triple := " + stmt.asTriple().toString());
+        } else {
+            out.println("Graph is not Empty; it has "+graph.size()+" Statements");
+            long t0, t1;
+            t0 = System.currentTimeMillis();
+            final Query q = QueryFactory.create(
+                    "PREFIX exns: <"+MY_NS+"#>\n"+
+                    "PREFIX exprod: <"+MY_NS+"product/>\n"+
+                    " SELECT * "
+                    // if you don't provide the Model to the
+                    // QueryExecutionFactory below, then you'll need
+                    // to specify the FROM;
+                    // you *can* always specify it, if you want
+                    // +" FROM <"+MY_NS+">\n"
+                    // +" WHERE { ?node <"+MY_NS+"#hasName> ?name }"
+                    // +" WHERE { ?node exns:hasName ?name }"
+                    // +" WHERE { exprod:1 exns:hasName ?name }"
+                    +" WHERE { ?res ?pred ?obj }"
+                    );
+            out.println("Query := "+q);
+            t1 = System.currentTimeMillis();
+            out.println("QueryFactory.TIME="+(t1 - t0));
+
+            t0 = System.currentTimeMillis();
+            final QueryExecution qExec = QueryExecutionFactory
+                    // if you query the whole DataSet,
+                    // you have to provide a FROM in the SparQL
+                    //.create(q, data0);
+                    .create(q, model);
+            t1 = System.currentTimeMillis();
+            out.println("QueryExecutionFactory.TIME="+(t1 - t0));
+
+            try {
+                t0 = System.currentTimeMillis();
+                ResultSet rs = qExec.execSelect();
+                t1 = System.currentTimeMillis();
+                out.println("executeSelect.TIME="+(t1 - t0));
+                while (rs.hasNext()) {
+                    QuerySolution sol = rs.next();
+                    out.println("Solution := "+sol);
+                    for (Iterator<String> names = sol.varNames(); names.hasNext();
) {
+                        final String name = names.next();
+                        out.println("\t"+name+" := "+sol.get(name));
+                    }
+                }
+            } finally {
+                qExec.close();
+            }
+        }
+        out.println("closing graph");
+        graph.close();
+        out.println("closing model");
+        model.close();
+        //out.println("closing DataSetGraph");
+        //dsg.close();
+        out.println("closing DataSet");
+        data0.close();
+    }
+}

Modified: jena/trunk/jena-tdb/src-examples/tdb/examples/ExTDB_Txn2.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src-examples/tdb/examples/ExTDB_Txn2.java?rev=1461087&r1=1461086&r2=1461087&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src-examples/tdb/examples/ExTDB_Txn2.java (original)
+++ jena/trunk/jena-tdb/src-examples/tdb/examples/ExTDB_Txn2.java Tue Mar 26 12:36:44 2013
@@ -18,7 +18,7 @@
 
 package tdb.examples;
 
-import org.openjena.atlas.lib.StrUtils ;
+import org.apache.jena.atlas.lib.StrUtils ;
 
 import com.hp.hpl.jena.query.Dataset ;
 import com.hp.hpl.jena.query.ReadWrite ;



Mime
View raw message