You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2016/10/23 17:16:17 UTC

[2/4] jena git commit: Code, not active, to write "[ :p obj ] ." as [] :p obj .

Code, not active, to write "[ :p obj ] ." as [] :p obj .

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

Branch: refs/heads/master
Commit: 26fcbc51417db49a7c2c08fe007b6635b1f373fb
Parents: 52fa6e9
Author: Andy Seaborne <an...@apache.org>
Authored: Sun Oct 23 15:47:50 2016 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Sun Oct 23 15:47:50 2016 +0100

----------------------------------------------------------------------
 .../apache/jena/riot/writer/TurtleShell.java    | 32 +++++++++++++++-----
 1 file changed, 24 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/26fcbc51/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleShell.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleShell.java b/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleShell.java
index 041386f..a40cf6d 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleShell.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleShell.java
@@ -586,9 +586,8 @@ public abstract class TurtleShell {
                     out.println() ;
                 first = false ;
                 if ( freeBnodes.contains(subj) ) {
-                    // Write in "[....]" form.
-                    writeNestedObject(subj) ;
-                    out.println(" .") ;
+                    // Top level: write in "[....]" on "[] :p" form.
+                    writeNestedObjectTopLevel(subj) ;
                     continue ;
                 }
 
@@ -598,18 +597,22 @@ public abstract class TurtleShell {
             return !first ;
         }
 
-        // Common subject
-        // Used by the blocks writer as well.
+        // A Cluster is a collection of triples with the same subject.
         private void writeCluster(Node subject, Collection<Triple> cluster) {
             if ( cluster.isEmpty() )
                 return ;
             writeNode(subject) ;
+            writeClusterPredicateObjectList(INDENT_PREDICATE, cluster) ;
+        }
+
+        // Write the PredicateObjectList fora subject already output.
+        // The subject may have been a "[]" or a URI - the indentation is passed in.
+        private void writeClusterPredicateObjectList(int indent, Collection<Triple> cluster) {
             write_S_P_Gap() ;
-            out.incIndent(INDENT_PREDICATE) ;
+            out.incIndent(indent) ;
             out.pad() ;
             writePredicateObjectList(cluster) ;
-            out.decIndent(INDENT_PREDICATE) ;
-            // End of cluster.
+            out.decIndent(indent) ;
             print(" .") ;
             println() ;
         }
@@ -753,6 +756,19 @@ public abstract class TurtleShell {
             return x.size() ;
         }
 
+        // [ :p "abc" ] .  or    [] : "abc" .
+        private void writeNestedObjectTopLevel(Node subject) {
+            if ( true ) {
+                writeNestedObject(subject) ;
+                out.println(" .") ;
+            } else {
+                // Alternative.
+                Collection<Triple> cluster = triplesOfSubject(subject) ;
+                print("[]") ;
+                writeClusterPredicateObjectList(0, cluster) ;
+            }
+        }
+        
         private void writeNestedObject(Node node) {
             Collection<Triple> x = triplesOfSubject(node) ;