jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1509324 - in /jena/trunk/jena-tdb/src: main/java/com/hp/hpl/jena/tdb/store/bulkloader/BulkLoader.java test/java/com/hp/hpl/jena/tdb/store/TestLoader.java
Date Thu, 01 Aug 2013 16:43:29 GMT
Author: andy
Date: Thu Aug  1 16:43:28 2013
New Revision: 1509324

URL: http://svn.apache.org/r1509324
Log:
JENA-496 : Record prefixes in bulk loader.

Modified:
    jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/bulkloader/BulkLoader.java
    jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestLoader.java

Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/bulkloader/BulkLoader.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/bulkloader/BulkLoader.java?rev=1509324&r1=1509323&r2=1509324&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/bulkloader/BulkLoader.java
(original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/bulkloader/BulkLoader.java
Thu Aug  1 16:43:28 2013
@@ -29,6 +29,7 @@ import org.slf4j.Logger ;
 
 import com.hp.hpl.jena.graph.Node ;
 import com.hp.hpl.jena.graph.Triple ;
+import com.hp.hpl.jena.shared.PrefixMapping ;
 import com.hp.hpl.jena.sparql.core.Quad ;
 import com.hp.hpl.jena.sparql.util.Utils ;
 import com.hp.hpl.jena.tdb.TDB ;
@@ -96,8 +97,7 @@ public class BulkLoader
 
     private static BulkStreamRDF destinationDefaultGraph(DatasetGraphTDB dsg, boolean showProgress)
     {
-        NodeTupleTable ntt = dsg.getTripleTable().getNodeTupleTable() ;
-        return destinationGraph(dsg, ntt, showProgress) ;
+        return destinationGraph(dsg, null, showProgress) ;
     }
 
     /** Load into named graph */
@@ -127,7 +127,6 @@ public class BulkLoader
         BulkStreamRDF dest = destinationDataset(dsg, showProgress) ;
         loadQuads$(dest, input) ;
     }
-    
 
     /** Load into a graph */
     private static void loadTriples$(BulkStreamRDF dest, List<String> urls)
@@ -175,10 +174,7 @@ public class BulkLoader
     {
         if ( graphName == null )
             return destinationDefaultGraph(dsg,showProgress) ;
-        
-        NodeTupleTable ntt = dsg.getQuadTable().getNodeTupleTable() ;
-        NodeTupleTable ntt2 = new NodeTupleTableView(ntt, graphName) ;
-        return destinationGraph(dsg, ntt2, showProgress) ;
+        return destinationGraph(dsg, graphName, showProgress) ;
     }
 
     public static LoadMonitor createLoadMonitor(DatasetGraphTDB dsg, String itemName, boolean
showProgress)
@@ -194,9 +190,9 @@ public class BulkLoader
         return new DestinationDSG(dsg, showProgress) ;
     }
     
-    private static BulkStreamRDF destinationGraph(DatasetGraphTDB dsg, NodeTupleTable nodeTupleTable,
boolean showProgress)
+    private static BulkStreamRDF destinationGraph(DatasetGraphTDB dsg, Node graphNode, boolean
showProgress)
     {
-        return new DestinationGraph(dsg, nodeTupleTable, showProgress) ;
+        return new DestinationGraph(dsg, graphNode, showProgress) ;
     }
 
     // Load triples and quads into a dataset.
@@ -295,8 +291,11 @@ public class BulkLoader
         public void tuple(Tuple<Node> tuple)    { throw new TDBException("Tuple encountered
while loading a dataset") ; }
         @Override
         public void base(String base)           {}
+        
         @Override
-        public void prefix(String prefix, String iri)   {} // TODO
+        public void prefix(String prefix, String iri)
+        { dsg.getPrefixes().getPrefixMapping().setNsPrefix(prefix, iri) ; }
+
         @Override
         public void finish()                    {}
     }
@@ -305,15 +304,27 @@ public class BulkLoader
     private static final class DestinationGraph implements BulkStreamRDF
     {
         final private DatasetGraphTDB dsg ;
+        final private Node graphName ;
         final private LoadMonitor monitor ;
         final private LoaderNodeTupleTable loaderTriples ;
         final private boolean startedEmpty ;
         private long count = 0 ;
         private StatsCollector stats ;
 
-        DestinationGraph(final DatasetGraphTDB dsg, NodeTupleTable nodeTupleTable, boolean
showProgress)
+        // Graph node is null for default graph.
+        DestinationGraph(final DatasetGraphTDB dsg, Node graphNode, boolean showProgress)
         {
             this.dsg = dsg ;
+            this.graphName = graphNode ;
+            
+            // Choose NodeTupleTable.
+            NodeTupleTable nodeTupleTable ;
+            if ( graphNode == null || Quad.isDefaultGraph(graphNode) )
+                nodeTupleTable = dsg.getTripleTable().getNodeTupleTable() ;
+            else {
+                NodeTupleTable ntt = dsg.getQuadTable().getNodeTupleTable() ;
+                nodeTupleTable = new NodeTupleTableView(ntt, graphName) ;
+            }
             startedEmpty = dsg.isEmpty() ;
             monitor = createLoadMonitor(dsg, "triples", showProgress) ;
             loaderTriples = new LoaderNodeTupleTable(nodeTupleTable, "triples", monitor)
;
@@ -364,7 +375,19 @@ public class BulkLoader
         @Override
         public void base(String base)           { }
         @Override
-        public void prefix(String prefix, String iri)  { } // TODO
+        public void prefix(String prefix, String iri)
+        { 
+            if ( graphName != null && graphName.isBlank() ) {  
+                loadLogger.warn("Prefixes for blank node graphs not stored") ;
+                return ;
+            }
+                
+            PrefixMapping pmap =
+                ( graphName == null )
+                ? dsg.getPrefixes().getPrefixMapping()
+                : dsg.getPrefixes().getPrefixMapping(graphName.getURI()) ;
+            pmap.setNsPrefix(prefix, iri) ;
+        }
         @Override
         public void finish()                    {}
     }

Modified: jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestLoader.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestLoader.java?rev=1509324&r1=1509323&r2=1509324&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestLoader.java (original)
+++ jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestLoader.java Thu Aug  1
16:43:28 2013
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-package com.hp.hpl.jena.tdb.store;
+package com.hp.hpl.jena.tdb.store ;
 
 import java.io.InputStream ;
 import java.util.List ;
@@ -39,61 +39,80 @@ import com.hp.hpl.jena.tdb.TDBLoader ;
 import com.hp.hpl.jena.tdb.base.file.Location ;
 import com.hp.hpl.jena.tdb.sys.TDBMaker ;
 
-public class TestLoader extends BaseTest
-{
+public class TestLoader extends BaseTest {
     private static final String DIR = "testing/Loader/" ;
-    private static final Node g = NodeFactory.createURI("g") ;
-    private static final Node s = NodeFactory.createURI("s") ;
-    private static final Node p = NodeFactory.createURI("p") ;
-    private static final Node o = NodeFactory.createURI("o") ;
-    
-    @BeforeClass static public void beforeClass()   { Log.disable(ARQ.logExecName) ; Log.disable(TDB.logLoaderName)
; }
-    @AfterClass  static public void afterClass()    { Log.enable(ARQ.logExecName) ; Log.enable(TDB.logLoaderName)
; }
-    
-    static DatasetGraphTDB fresh() { return TDBMaker.createDatasetGraphTDB(Location.mem())
; }
-    
-    @Test public void load_dataset_01()
-    {
+    private static final Node   g   = NodeFactory.createURI("g") ;
+    private static final Node   s   = NodeFactory.createURI("s") ;
+    private static final Node   p   = NodeFactory.createURI("p") ;
+    private static final Node   o   = NodeFactory.createURI("o") ;
+
+    @BeforeClass
+    static public void beforeClass() {
+        Log.disable(ARQ.logExecName) ;
+        Log.disable(TDB.logLoaderName) ;
+    }
+
+    @AfterClass
+    static public void afterClass() {
+        Log.enable(ARQ.logExecName) ;
+        Log.enable(TDB.logLoaderName) ;
+    }
+
+    static DatasetGraphTDB fresh() {
+        return TDBMaker.createDatasetGraphTDB(Location.mem()) ;
+    }
+
+    @Test
+    public void load_dataset_01() {
         DatasetGraphTDB dsg = fresh() ;
-        TDBLoader.load(dsg, DIR+"data-1.nq", false) ;
+        TDBLoader.load(dsg, DIR + "data-1.nq", false) ;
         assertTrue(dsg.getDefaultGraph().isEmpty()) ;
         assertEquals(1, dsg.getGraph(g).size()) ;
     }
 
-    @Test public void load_dataset_02()
-    {
+    @Test
+    public void load_dataset_02() {
         DatasetGraphTDB dsg = fresh() ;
-        InputStream in = IO.openFile(DIR+"data-1.nq") ;
+        InputStream in = IO.openFile(DIR + "data-1.nq") ;
         TDBLoader.load(dsg, in, false) ;
         assertTrue(dsg.getDefaultGraph().isEmpty()) ;
         assertEquals(1, dsg.getGraph(g).size()) ;
     }
 
-    @Test public void load_graph_01()
-    {
+    @Test
+    public void load_dataset_03() {
+        DatasetGraphTDB dsg = fresh() ;
+        TDBLoader.load(dsg, DIR + "data-3.trig", false) ;
+        String uri = dsg.getDefaultGraph().getPrefixMapping().getNsPrefixURI("") ;
+        assertEquals("http://example/", uri) ;
+    }
+    
+
+    @Test
+    public void load_graph_01() {
         DatasetGraphTDB dsg = fresh() ;
-        TDBLoader.load(dsg, DIR+"data-2.nt", false) ;
+        TDBLoader.load(dsg, DIR + "data-2.nt", false) ;
         assertEquals(1, dsg.getDefaultGraph().size()) ;
     }
 
-    @Test public void load_graph_02()
-    {
+    @Test
+    public void load_graph_02() {
         DatasetGraphTDB dsg = fresh() ;
-        TDBLoader.load(dsg.getDefaultGraphTDB(), DIR+"data-2.nt", false) ;
+        TDBLoader.load(dsg.getDefaultGraphTDB(), DIR + "data-2.nt", false) ;
         assertEquals(1, dsg.getDefaultGraph().size()) ;
     }
 
-    @Test public void load_graph_03()
-    {
+    @Test
+    public void load_graph_03() {
         DatasetGraphTDB dsg = fresh() ;
-        TDBLoader.load(dsg.getGraphTDB(g), DIR+"data-2.nt", false) ;
+        TDBLoader.load(dsg.getGraphTDB(g), DIR + "data-2.nt", false) ;
         assertEquals(0, dsg.getDefaultGraph().size()) ;
         assertEquals(1, dsg.getGraph(g).size()) ;
-        
+
         // Check indexes.
-        List<Triple> x = Iter.toList(dsg.getDefaultGraph().find(null, null, null))
; 
+        List<Triple> x = Iter.toList(dsg.getDefaultGraph().find(null, null, null))
;
         assertEquals(0, x.size()) ;
-            
+
         x = Iter.toList(dsg.getGraph(g).find(null, null, null)) ;
         assertEquals(1, x.size()) ;
         x = Iter.toList(dsg.getGraph(g).find(s, null, null)) ;
@@ -102,7 +121,7 @@ public class TestLoader extends BaseTest
         assertEquals(1, x.size()) ;
         x = Iter.toList(dsg.getGraph(g).find(null, null, o)) ;
         assertEquals(1, x.size()) ;
-        
+
         List<Quad> z = Iter.toList(dsg.find(null, null, null, null)) ;
         assertEquals(1, z.size()) ;
         z = Iter.toList(dsg.find(g, null, null, null)) ;
@@ -114,4 +133,32 @@ public class TestLoader extends BaseTest
         z = Iter.toList(dsg.find(null, null, null, o)) ;
         assertEquals(1, z.size()) ;
     }
+
+    @Test
+    public void load_graph_04() {
+        DatasetGraphTDB dsg = fresh() ;
+        TDBLoader.load(dsg, DIR + "data-4.ttl", false) ;
+        String uri = dsg.getDefaultGraph().getPrefixMapping().getNsPrefixURI("") ;
+        assertEquals("http://example/", uri) ;
+    }
+
+    @Test
+    public void load_graph_05() {
+        DatasetGraphTDB dsg = fresh() ;
+        GraphTDB graph = dsg.getDefaultGraphTDB() ;
+        TDBLoader.load(graph, DIR + "data-4.ttl", false) ;
+        String uri = dsg.getDefaultGraph().getPrefixMapping().getNsPrefixURI("") ;
+        assertEquals("http://example/", uri) ;
+    }
+    
+    @Test
+    public void load_graph_06() {
+        DatasetGraphTDB dsg = fresh() ;
+        GraphTDB graph = dsg.getGraphTDB(g) ;
+        TDBLoader.load(graph, DIR + "data-4.ttl", false) ;
+        String uri1 = dsg.getGraph(g).getPrefixMapping().getNsPrefixURI("") ;
+        assertEquals("http://example/", uri1) ;
+        String uri2 = dsg.getDefaultGraph().getPrefixMapping().getNsPrefixURI("") ;
+        assertNull(uri2) ;
+    }
 }



Mime
View raw message