jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [2/4] jena git commit: Allow quads for (daatset) content.
Date Wed, 11 Nov 2015 20:32:02 GMT
Allow quads for (daatset) content.

Reformat.


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/7839dbe2
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/7839dbe2
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/7839dbe2

Branch: refs/heads/master
Commit: 7839dbe237a4fc5c1111f3e2b8b22658f089d9cd
Parents: 4f846d8
Author: Andy Seaborne <andy@apache.org>
Authored: Wed Nov 11 18:30:47 2015 +0000
Committer: Andy Seaborne <andy@apache.org>
Committed: Wed Nov 11 18:30:47 2015 +0000

----------------------------------------------------------------------
 .../jena/sparql/sse/builders/BuilderGraph.java  | 252 +++++++++----------
 1 file changed, 116 insertions(+), 136 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/7839dbe2/jena-arq/src/main/java/org/apache/jena/sparql/sse/builders/BuilderGraph.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/sse/builders/BuilderGraph.java
b/jena-arq/src/main/java/org/apache/jena/sparql/sse/builders/BuilderGraph.java
index 4d33e3a..23766b7 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/sse/builders/BuilderGraph.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/sse/builders/BuilderGraph.java
@@ -18,7 +18,6 @@
 
 package org.apache.jena.sparql.sse.builders;
 
-
 import org.apache.jena.graph.Graph ;
 import org.apache.jena.graph.Node ;
 import org.apache.jena.graph.Triple ;
@@ -36,63 +35,57 @@ import org.apache.jena.util.FileManager ;
 
 public class BuilderGraph
 {
-    public static Graph buildGraph(Item item)
-    { 
-        Graph graph = GraphFactory.createDefaultGraph() ;
-        buildGraph(graph, item) ;
-        return graph ;
+    public static Graph buildGraph(Item item) {
+        Graph graph = GraphFactory.createDefaultGraph();
+        buildGraph(graph, item);
+        return graph;
     }
     
-    public static Graph buildGraph(ItemList itemList)
-    { 
-        Graph graph = GraphFactory.createDefaultGraph() ;
-        buildGraph(graph, itemList) ;
-        return graph ;
+    public static Graph buildGraph(ItemList itemList) {
+        Graph graph = GraphFactory.createDefaultGraph();
+        buildGraph(graph, itemList);
+        return graph;
     }
     
-    public static void buildGraph(Graph graph, Item item)
-    {
-        if (item.isNode() )
-            BuilderLib.broken(item, "Attempt to build graph from a plain node") ;
+    public static void buildGraph(Graph graph, Item item) {
+        if ( item.isNode() )
+            BuilderLib.broken(item, "Attempt to build graph from a plain node");
 
-        if (item.isSymbol() )
-            BuilderLib.broken(item, "Attempt to build graph from a bare symbol") ;
+        if ( item.isSymbol() )
+            BuilderLib.broken(item, "Attempt to build graph from a bare symbol");
 
-        if ( item.isTagged(Tags.tagGraph) )
-        {
-            buildGraph(graph, item.getList()) ;
-            return ;
+        if ( item.isTagged(Tags.tagGraph) ) {
+            buildGraph(graph, item.getList());
+            return;
         }
-        
-        if ( item.isTagged(Tags.tagLoad) )
-        {
-           loadGraph(graph, item.getList()) ;
-           return ;
+
+        if ( item.isTagged(Tags.tagLoad) ) {
+            loadGraph(graph, item.getList());
+            return;
         }
-        
-        BuilderLib.broken(item, "Wanted ("+Tags.tagGraph+"...) or ("+Tags.tagLoad+"...)");
+
+        BuilderLib.broken(item, "Wanted (" + Tags.tagGraph + "...) or (" + Tags.tagLoad +
"...)");
     }
     
-    public static Graph buildGraph(Graph graph, ItemList list)
-    {
-        if ( ! list.isEmpty() && list.get(0).isSymbol() )
-        {
+    public static Graph buildGraph(Graph graph, ItemList list) {
+        if ( !list.isEmpty() && list.get(0).isSymbol() ) {
             if ( list.get(0).isSymbol(Tags.tagGraph) )
                 list = list.cdr();
         }
-        
-        for (Item item : list)
-        {
-            BuilderLib.checkList(item) ;
-            Triple triple = buildTriple(item.getList()) ;
-            graph.add(triple) ;
+
+        for ( Item item : list ) {
+            BuilderLib.checkList(item);
+            Triple triple = buildTriple(item.getList());
+            graph.add(triple);
         }
-        return graph ;
+        return graph;
     }
     
     /** Format:
      * (dataset
      *    (graph ...))
+     *    (quad ...)
+     *    (g s p o)
      *    (graph IRIa ...))
      *    (graph IRIb ...))
      *    )
@@ -117,132 +110,119 @@ public class BuilderGraph
         if (item.isSymbol() )
             BuilderLib.broken(item, "Attempt to build dataset from a bare symbol") ;
 
-        if ( item.isTagged(Tags.tagGraph) )
-        {
-            Graph g = BuilderGraph.buildGraph(item.getList()) ;
-            return DatasetGraphFactory.create(g) ;
+        if ( item.isTagged(Tags.tagGraph) ) {
+            Graph g = BuilderGraph.buildGraph(item.getList());
+            return DatasetGraphFactory.create(g);
         }
-        
+
         if ( ! item.isTagged(Tags.tagDataset) )
             BuilderLib.broken(item, "Wanted ("+Tags.tagDataset+"...)" );
         return buildDataset(dsg, item.getList()) ;
     }
     
-    public static DatasetGraph buildDataset(DatasetGraph dsg, ItemList list)
-    {
-        BuilderLib.checkTag(list, Tags.tagDataset) ;
+    public static DatasetGraph buildDataset(DatasetGraph dsg, ItemList list) {
+        BuilderLib.checkTag(list, Tags.tagDataset);
         list = list.cdr();
-        
-        for (Item item : list)
-        {
-            if ( ! item.isTagged(Tags.tagGraph) )
-                BuilderLib.broken(item, "Expected (graph ...) as elements of a dataset")
;
-            
-            Node name = null ;
+
+        for ( Item item : list ) {
+            if ( !item.isTagged(Tags.tagGraph) ) {
+                // Not (graph ...) so it's (quad), short form quad or an error.
+                Quad q = BuilderGraph.buildQuad(item.getList(), "Expected (graph ...) or
a quad () as elements of a dataset");
+                dsg.add(q);
+                continue;
+            }
+
+            Node name = null;
             ItemList graphContent = item.getList().cdr();
 
-            if ( !graphContent.isEmpty() && graphContent.car().isNode() )
-            {
+            if ( !graphContent.isEmpty() && graphContent.car().isNode() ) {
                 name = graphContent.car().getNode();
-                graphContent = graphContent.cdr() ;
+                graphContent = graphContent.cdr();
             }
-            
-            Graph g ;
-            if ( name == null )
-            {
-                g = dsg.getDefaultGraph() ;
-                if ( g == null )
-                {
-                    g = GraphFactory.createDefaultGraph() ;
-                    dsg.setDefaultGraph(g) ;
+
+            Graph g;
+            if ( name == null ) {
+                g = dsg.getDefaultGraph();
+                if ( g == null ) {
+                    g = GraphFactory.createDefaultGraph();
+                    dsg.setDefaultGraph(g);
                 }
-            }
-            else
-            {
-                g = dsg.getGraph(name) ;
-                if ( g == null )
-                {
-                    g = GraphFactory.createDefaultGraph() ;
-                    dsg.addGraph(name, g) ;
+            } else {
+                g = dsg.getGraph(name);
+                if ( g == null ) {
+                    g = GraphFactory.createDefaultGraph();
+                    dsg.addGraph(name, g);
                 }
             }
-            BuilderGraph.buildGraph(g, graphContent) ;
+            BuilderGraph.buildGraph(g, graphContent);
         }
-        return dsg ;
+        return dsg;
     }
     
-    
-    private static void loadGraph(Graph graph, ItemList list)
-    {
-        BuilderLib.checkLength(2, list, Tags.tagLoad ) ;
-        Item item = list.get(1) ;
-        if ( ! item.isNode() )
-            BuilderLib.broken(item, "Expected: ("+Tags.tagLoad+" 'filename')") ;
-        String s = NodeUtils.stringLiteral(item.getNode()) ;
+    private static void loadGraph(Graph graph, ItemList list) {
+        BuilderLib.checkLength(2, list, Tags.tagLoad);
+        Item item = list.get(1);
+        if ( !item.isNode() )
+            BuilderLib.broken(item, "Expected: ("+Tags.tagLoad+" 'filename')");
+        String s = NodeUtils.stringLiteral(item.getNode());
         if ( s == null )
-            BuilderLib.broken(item, "Expected: ("+Tags.tagLoad+" 'filename')") ;
-        Model model = ModelFactory.createModelForGraph(graph) ;
-        FileManager.get().readModel(model, s) ;
+            BuilderLib.broken(item, "Expected: ("+Tags.tagLoad+" 'filename')");
+        Model model = ModelFactory.createModelForGraph(graph);
+        FileManager.get().readModel(model, s);
     }
-    
-    public static Triple buildTriple(ItemList list)
-    {
+
+    public static Triple buildTriple(ItemList list) {
         if ( list.size() != 3 && list.size() != 4 )
-            BuilderLib.broken(list, "Not a triple", list) ;
-        if ( list.size() == 4 )
-        {
-            if ( ! list.get(0).isSymbol(Tags.tagTriple) )
-                BuilderLib.broken(list, "Not a triple") ;
-            list = list.cdr() ;
+            BuilderLib.broken(list, "Not a triple", list);
+        if ( list.size() == 4 ) {
+            if ( !list.get(0).isSymbol(Tags.tagTriple) )
+                BuilderLib.broken(list, "Not a triple");
+            list = list.cdr();
         }
-        return _buildNode3(list) ;
+        return _buildNode3(list);
     }
 
-    public static Triple buildNode3(ItemList list)
-    {
-        BuilderLib.checkLength(3, list, null) ;
-        return _buildNode3(list) ;
+    public static Triple buildNode3(ItemList list) {
+        BuilderLib.checkLength(3, list, null);
+        return _buildNode3(list);
     }
-    
-    private static Triple _buildNode3(ItemList list)
-    {
-        Node s = BuilderNode.buildNode(list.get(0)) ;
-        Node p = BuilderNode.buildNode(list.get(1)) ;
-        Node o = BuilderNode.buildNode(list.get(2)) ;
-        return new Triple(s, p, o) ; 
+
+    private static Triple _buildNode3(ItemList list) {
+        Node s = BuilderNode.buildNode(list.get(0));
+        Node p = BuilderNode.buildNode(list.get(1));
+        Node o = BuilderNode.buildNode(list.get(2));
+        return new Triple(s, p, o);
     }
-   
-    public static Quad buildQuad(ItemList list)
-    {
+
+    public static Quad buildQuad(ItemList list) {
+        return buildQuad(list, "Not a quad") ;
+    }
+    
+    public static Quad buildQuad(ItemList list, String errMsg) {
         if ( list.size() != 4 && list.size() != 5 )
-            BuilderLib.broken(list, "Not a quad") ;
-        if ( list.size() == 5 )
-        {
-            if ( ! list.get(0).isSymbol(Tags.tagQuad) )
-                BuilderLib.broken(list, "Not a quad") ;
-            list = list.cdr() ;
+            BuilderLib.broken(list, errMsg);
+        if ( list.size() == 5 ) {
+            if ( !list.get(0).isSymbol(Tags.tagQuad) )
+                BuilderLib.broken(list, errMsg);
+            list = list.cdr();
         }
-        return _buildNode4(list) ;
+        return _buildNode4(list);
     }
-    
-    public static Quad buildNode4(ItemList list)
-    {
-        BuilderLib.checkLength(4, list, null) ;
-        return _buildNode4(list) ;
+
+    public static Quad buildNode4(ItemList list) {
+        BuilderLib.checkLength(4, list, null);
+        return _buildNode4(list);
     }
-    
-    private static Quad _buildNode4(ItemList list)
-    {
-        Node g = null ;
-        if ( list.get(0).equals(Item.defaultItem)) 
-            g = Quad.defaultGraphNodeGenerated ;
+
+    private static Quad _buildNode4(ItemList list) {
+        Node g = null;
+        if ( list.get(0).equals(Item.defaultItem) )
+            g = Quad.defaultGraphNodeGenerated;
         else
-            g = BuilderNode.buildNode(list.get(0)) ;
-        Node s = BuilderNode.buildNode(list.get(1)) ;
-        Node p = BuilderNode.buildNode(list.get(2)) ;
-        Node o = BuilderNode.buildNode(list.get(3)) ;
-        return new Quad(g, s, p, o) ; 
+            g = BuilderNode.buildNode(list.get(0));
+        Node s = BuilderNode.buildNode(list.get(1));
+        Node p = BuilderNode.buildNode(list.get(2));
+        Node o = BuilderNode.buildNode(list.get(3));
+        return new Quad(g, s, p, o);
     }
-
-
 }


Mime
View raw message