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/05/13 13:51:33 UTC

[4/4] jena git commit: JENA-1179: Don't put {...} around the default graph.

JENA-1179: Don't put {...} around the default graph.

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

Branch: refs/heads/master
Commit: 3756902d4b162e5f14974624b7a8c0b7d9d17e2c
Parents: 3da5cde
Author: Andy Seaborne <an...@apache.org>
Authored: Fri May 13 14:45:49 2016 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Fri May 13 14:45:49 2016 +0100

----------------------------------------------------------------------
 .../org/apache/jena/riot/writer/TriGWriter.java | 16 ++++++++++---
 .../apache/jena/riot/writer/WriterConst.java    | 24 +++++++++++---------
 2 files changed, 26 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/3756902d/jena-arq/src/main/java/org/apache/jena/riot/writer/TriGWriter.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/writer/TriGWriter.java b/jena-arq/src/main/java/org/apache/jena/riot/writer/TriGWriter.java
index b0d5afc..534db4e 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/writer/TriGWriter.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/writer/TriGWriter.java
@@ -18,6 +18,7 @@
 
 package org.apache.jena.riot.writer;
 
+import static org.apache.jena.riot.writer.WriterConst.GDFT_BRACE ;
 import static org.apache.jena.riot.writer.WriterConst.INDENT_GDFT ;
 import static org.apache.jena.riot.writer.WriterConst.INDENT_GNMD ;
 import static org.apache.jena.riot.writer.WriterConst.NL_GDFT_END ;
@@ -70,6 +71,18 @@ public class TriGWriter extends TriGWriterBase
         /** Return true if anything written */
         private boolean writeGraphTriG(DatasetGraph dsg, Node name) {
             boolean dftGraph =  ( name == null || name == Quad.defaultGraphNodeGenerated  ) ;
+            
+            if ( dftGraph && dsg.getDefaultGraph().isEmpty() )
+                return false ;
+            
+            if ( dftGraph && ! GDFT_BRACE ) {
+                // Non-empty default graph, no braces.
+                // No indenting.
+                writeGraphTTL(dsg, name) ;
+                return true ;
+            }
+            
+            // The graph will go in braces, whether non-empty default graph or a named graph. 
             boolean NL_START =  ( dftGraph ? NL_GDFT_START : NL_GNMD_START ) ; 
             boolean NL_END =    ( dftGraph ? NL_GDFT_END : NL_GNMD_END ) ; 
             int INDENT_GRAPH =  ( dftGraph ? INDENT_GDFT : INDENT_GNMD ) ; 
@@ -77,9 +90,6 @@ public class TriGWriter extends TriGWriterBase
             if ( !dftGraph ) {
                 writeNode(name) ;
                 out.print(" ") ;
-            } else {
-                if ( dsg.getDefaultGraph().isEmpty() )
-                    return false ;
             }
 
             out.print("{") ;

http://git-wip-us.apache.org/repos/asf/jena/blob/3756902d/jena-arq/src/main/java/org/apache/jena/riot/writer/WriterConst.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/writer/WriterConst.java b/jena-arq/src/main/java/org/apache/jena/riot/writer/WriterConst.java
index 082fd1a..dd82ce3 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/writer/WriterConst.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/writer/WriterConst.java
@@ -51,12 +51,6 @@ public class WriterConst
     /** Column for start of object */
     public static final int INDENT_OBJECT   = 8 ;
 
-    /** Indent for triples in default graph blocks */
-    public static final int INDENT_GDFT          = 2 ;
-    /** Indent for trinples in named graph blocks */
-    public static final int INDENT_GNMD          = 4 ;
-
-    
     /** Minimum gap from S to P and from P to O */
     public static final int MIN_GAP         = 2 ;
 
@@ -65,17 +59,25 @@ public class WriterConst
     /** Minimum gap from P to O */
     public static final int GAP_P_O         = MIN_GAP ;  
     
+    // TriG constants.
+    /** Whether to put in {} for the default graph when pretty writing */   
+    public static final boolean GDFT_BRACE      =  false ;
+    
     /** Whether to put in a newline after the opening { of a default graph block */   
-    public static final boolean NL_GDFT_START    =  false ;
+    public static final boolean NL_GDFT_START   =  false ;
     /** Whether to put in a newline after the opening { of a named graph block */   
-    public static final boolean NL_GNMD_START    =  true ;
+    public static final boolean NL_GNMD_START   =  true ;
     
     /** Whether to put the closing } of a default graph block on a newline */
-    public static final boolean NL_GDFT_END      =  true ;
+    public static final boolean NL_GDFT_END     =  true ;
     /** Whether to put the closing } of a named graph block on a newline */
-    public static final boolean NL_GNMD_END      =  true ;
+    public static final boolean NL_GNMD_END     =  true ;
+
+    /** Indent for triples in default graph blocks if inside {} */
+    public static final int INDENT_GDFT          = 2 ;
+    /** Indent for trinples in named graph blocks */
+    public static final int INDENT_GNMD          = 4 ;
 
-    
     // Constants.
     public static final String rdfNS        = RDF.getURI() ;
     public static final Node RDF_type       = RDF.Nodes.type ;