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 2013/01/12 18:15:31 UTC

svn commit: r1432476 - in /jena/Scratch/AFS/Dev/trunk: ./ src/main/java/projects/riot_writer/

Author: andy
Date: Sat Jan 12 17:15:31 2013
New Revision: 1432476

URL: http://svn.apache.org/viewvc?rev=1432476&view=rev
Log: (empty)

Added:
    jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/MainWriter.java
    jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/WriterConst.java
Modified:
    jena/Scratch/AFS/Dev/trunk/D.ttl
    jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/PROJECT_RiotWriter.java
    jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/TW2.java
    jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/TriGWriter.java
    jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/TurtleWriter2.java
    jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/TurtleWriterBlocks.java
    jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/TurtleWriterFlat.java

Modified: jena/Scratch/AFS/Dev/trunk/D.ttl
URL: http://svn.apache.org/viewvc/jena/Scratch/AFS/Dev/trunk/D.ttl?rev=1432476&r1=1432475&r2=1432476&view=diff
==============================================================================
--- jena/Scratch/AFS/Dev/trunk/D.ttl (original)
+++ jena/Scratch/AFS/Dev/trunk/D.ttl Sat Jan 12 17:15:31 2013
@@ -7,5 +7,14 @@
 :s ns:p3 [] .
 :s a :T .
 
+:s ns:p4 "a","b" .
+
 :z :p1 _:a .
 :z :p2 _:a .
+
+:a :q1 (1 2 3) .
+:a :q2 () .
+
+<http://example2/LONGSUBJECT_URI> :p "foo" .
+:s1 <http://example2/LONGPREDICATE_URI>  "foo" .
+:s1 <http://example2/VERYVERY_VERY_VERY_LONGPREDICATE_URI>  "foo" .
\ No newline at end of file

Added: jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/MainWriter.java
URL: http://svn.apache.org/viewvc/jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/MainWriter.java?rev=1432476&view=auto
==============================================================================
--- jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/MainWriter.java (added)
+++ jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/MainWriter.java Sat Jan 12 17:15:31 2013
@@ -0,0 +1,65 @@
+/**
+ * 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 projects.riot_writer;
+
+import java.io.ByteArrayInputStream ;
+import java.io.ByteArrayOutputStream ;
+
+import org.apache.jena.atlas.lib.StrUtils ;
+import org.apache.jena.riot.RDFDataMgr ;
+
+import com.hp.hpl.jena.query.Dataset ;
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.rdf.model.ModelFactory ;
+
+public class MainWriter
+{
+    public static void main(String ...args)
+    {
+        writeTTL() ;
+        //writeTriG() ;
+    }
+    
+    public static void writeTriG()
+    {
+        Dataset ds = RDFDataMgr.loadDataset("D.trig") ;
+        TriGWriter.write(System.out, ds) ;
+    }
+    
+    public static void writeTTL()
+    {
+        Model m = RDFDataMgr.loadModel("D.ttl") ;
+        TurtleWriterFlat.write(System.out, m, m.getNsPrefixMap()) ;
+        System.out.println("----------------------------------") ;
+        
+        ByteArrayOutputStream out = new ByteArrayOutputStream() ;
+        TurtleWriter2.write(out, m) ;
+        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()) ;
+        String s = StrUtils.fromUTF8bytes(out.toByteArray()) ;
+        Model m2 = ModelFactory.createDefaultModel() ;
+        m2.read(in, null, "TTL") ;
+        if ( ! m.isIsomorphicWith(m2) )
+            System.out.println("**** DIFFERENT") ;
+        
+        m.write(System.out, "TTL") ;
+    }
+
+    
+}
+

Modified: jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/PROJECT_RiotWriter.java
URL: http://svn.apache.org/viewvc/jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/PROJECT_RiotWriter.java?rev=1432476&r1=1432475&r2=1432476&view=diff
==============================================================================
--- jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/PROJECT_RiotWriter.java (original)
+++ jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/PROJECT_RiotWriter.java Sat Jan 12 17:15:31 2013
@@ -20,7 +20,14 @@ package projects.riot_writer;
 
 public class PROJECT_RiotWriter
 {
+    // Turtle writers:
+    // Pretty
+    // Blocks - same subject blocks, no object nesting, no lists.
+    // flat - ntriples+prefixes+numbers 
+    
+    
     // TODO
+    // Turtle:
     // Order subjects to write
     //   ==> scan by subject, not triples
 
@@ -29,41 +36,15 @@ public class PROJECT_RiotWriter
     // Lists
     //   Do before embeddable objects because list take precedence.
     
-    // Subjects \ one-connected objects
-    
     // PredicateObjectLists
     //   type to front.
-            // Property order is:
-            // 1 - rdf:type (as "a")
-            // 2 - other rdf: rdfs: namespace items (sorted)
-            // 3 - all other properties, sorted by URI (not qname)  
-            //     same properties together.
-    //   use object lists
-    // Configuration.
-    
-    // Check old code for special cases.
-    // Use better output(Node) code.
+    // Property order is:
+    // 1 - rdf:type (as "a")
+    // 2 - other rdf: rdfs: namespace items (sorted)
+    // 3 - all other properties, sorted by URI (not qname)  
+    //     same properties together - with and without object lists
     
-    // Check legality of prefix names generated.
-    // use stream node output (??)
-    
-    // Generally, all padding should level dependent.
-    
-    // OLD
-    // Width of property before wrapping.
-    // This is not necessarily a control of total width
-    // e.g. the pretty writer may be writing properties inside indented one ref bNodes 
-//    protected int widePropertyLen = getIntValue("widePropertyLen", 20) ;
-//    
-//    // Column for property when an object follows a property on the same line
-//    protected int propertyCol = getIntValue("propertyColumn", 8) ;
-//    
-//    // Minimum gap from property to object when object on a new line.
-//    protected int indentObject = propertyCol ;
-//    
-//    // If a subject is shorter than this, the first property may go on same line.
-//    protected int subjectColumn = getIntValue("subjectColumn", indentProperty) ; 
-//    // Require shortSubject < subjectCol (strict less than)
-
+    // TriG:
+    // Turtle plus
 }
 

Modified: jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/TW2.java
URL: http://svn.apache.org/viewvc/jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/TW2.java?rev=1432476&r1=1432475&r2=1432476&view=diff
==============================================================================
--- jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/TW2.java (original)
+++ jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/TW2.java Sat Jan 12 17:15:31 2013
@@ -18,23 +18,70 @@
 
 package projects.riot_writer;
 
-import java.util.Collection ;
-import java.util.HashSet ;
-import java.util.Set ;
+import static projects.riot_writer.WriterConst.PREFIX_IRI ;
 
+import java.util.* ;
+import java.util.Map.Entry ;
+
+import org.apache.jena.atlas.io.IndentedWriter ;
 import org.apache.jena.atlas.lib.Pair ;
 
 import com.hp.hpl.jena.graph.Graph ;
 import com.hp.hpl.jena.graph.Node ;
 import com.hp.hpl.jena.graph.Triple ;
+import com.hp.hpl.jena.sparql.util.FmtUtils ;
 import com.hp.hpl.jena.util.iterator.ExtendedIterator ;
+import com.hp.hpl.jena.vocabulary.RDF ;
 
 /** Support code for the RIOT TurtleWriter */ 
 public class TW2
 {
-    static final boolean recordObjectMisses = true ; 
-    
+    static void writePrefixes(IndentedWriter out, Map<String, String> prefixMap)
+    {
+        if ( ! prefixMap.isEmpty() )
+        {
+            // prepare?
+            for ( Map.Entry <String, String> e : prefixMap.entrySet() )
+            {
+                TW2.print(out, "@prefix ") ;
+                TW2.print(out, e.getKey()) ;
+                TW2.print(out, ": ") ;
+                TW2.pad(out, PREFIX_IRI) ;
+                TW2.print(out, "<") ;
+                TW2.print(out, e.getValue()) ;   // Check?
+                TW2.print(out, ">") ;
+                TW2.print(out, " .") ;
+                out.println() ;
+            }
+        }
+    }
+
     // Single, multi-function, pass over the graph 
+    // It alread scans all objects.
+
+    /** Find all well-formed lists */  
+    static Set<Triple> findLists(Graph graph)
+    {
+        
+        Set<Triple> listTriples = new HashSet<Triple>() ;
+        // Find the tail triple. 
+        ExtendedIterator<Triple> tails = graph.find(Node.ANY, RDF.Nodes.rest, RDF.Nodes.nil) ;
+        for ( ; tails.hasNext() ; )
+        {
+            Triple t = tails.next() ;
+            // Well formed?
+            // has exactly one rdf:first and one rdf:rest and nothing else.
+            
+            Node x = t.getSubject() ;
+            // ...
+        }
+        tails.close();
+        
+        return null ;
+    }
+
+    
+    static final boolean recordObjectMisses = true ; 
     
     /** Find all embeddable objects */  
     @SuppressWarnings("null")
@@ -94,5 +141,54 @@ public class TW2
             acc.add(iter.next()) ;
         iter.close() ;
     }
+
+    static void writeNode(IndentedWriter out, Node node, Map<String, String> prefixMap)
+    {
+        // See RIOT NodeFormatter
+        if ( node.isURI() )
+        {
+            String iri = node.getURI() ;
+            // Crude.
+            String x = abbreviate(iri, prefixMap) ;
+            if ( x != null )
+            {
+                print(out, x) ;
+                return ;
+            }
+        }
+        print(out, FmtUtils.stringForNode(node)) ;
+    }
+
+    /** Abbreviate an IRI or return null */
+    private static String abbreviate(String uriStr, Map<String, String> prefixMap)
+    {
+        for ( Entry<String, String> e : prefixMap.entrySet())
+        {
+            String prefix = e.getValue().toString() ;
+            
+            if ( uriStr.startsWith(prefix) )
+            {
+                String ln = uriStr.substring(prefix.length()) ;
+                if ( strSafeFor(ln, '/') && strSafeFor(ln, '#') && strSafeFor(ln, ':') )
+                    return e.getKey()+":"+ln ;
+            }
+        }
+        return null ;
+    }
+
+    static boolean strSafeFor(String str, char ch) { return str.indexOf(ch) == -1 ; }
+
+    private static void flush(IndentedWriter out) { out.flush() ; }
+
+    static void print(IndentedWriter out, String string)
+    {
+        out.print(string) ;
+        flush(out) ;
+    }
+
+    static void pad(IndentedWriter out, int col)
+    {
+        out.pad(col, true) ;
+    }
 }
 

Modified: jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/TriGWriter.java
URL: http://svn.apache.org/viewvc/jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/TriGWriter.java?rev=1432476&r1=1432475&r2=1432476&view=diff
==============================================================================
--- jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/TriGWriter.java (original)
+++ jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/TriGWriter.java Sat Jan 12 17:15:31 2013
@@ -18,40 +18,19 @@
 
 package projects.riot_writer;
 
-import java.io.FileInputStream ;
-import java.io.FileNotFoundException ;
 import java.io.OutputStream ;
 import java.util.Iterator ;
 import java.util.Map ;
 
 import org.apache.jena.atlas.io.IndentedWriter ;
-import org.apache.jena.riot.RDFLanguages ;
-import org.apache.jena.riot.RiotReader ;
-import org.apache.jena.riot.system.StreamRDF ;
-import org.apache.jena.riot.system.StreamRDFLib ;
-import org.apache.jena.riot.tokens.Tokenizer ;
-import org.apache.jena.riot.tokens.TokenizerFactory ;
 
 import com.hp.hpl.jena.graph.Graph ;
 import com.hp.hpl.jena.graph.Node ;
 import com.hp.hpl.jena.query.Dataset ;
-import com.hp.hpl.jena.query.DatasetFactory ;
 import com.hp.hpl.jena.sparql.core.DatasetGraph ;
-import com.hp.hpl.jena.sparql.core.DatasetGraphFactory ;
 
 public class TriGWriter
 {
-    public static void main(String ... argv) throws FileNotFoundException
-    {
-        DatasetGraph dsg = DatasetGraphFactory.createMem() ; 
-        
-        Tokenizer tokenizer = TokenizerFactory.makeTokenizerUTF8(new FileInputStream("D.trig")) ;
-        
-        StreamRDF sink = StreamRDFLib.dataset(dsg) ;
-        RiotReader.createParser(tokenizer,  RDFLanguages.TRIG, null, sink).parse() ;
-        write(System.out, DatasetFactory.create(dsg)) ;
-    }
-    
     public static final int GRAPH_INDENT = 4 ;
     
     public static void write(OutputStream out, Dataset dataset)
@@ -73,14 +52,13 @@ public class TriGWriter
             writeGraph(iOut, gn, dsg.getGraph(gn),  prefixMap) ;
         }
         iOut.flush() ;
-        
     }
     
-    public static void writeGraph(IndentedWriter out, Node name, Graph graph,  Map<String, String> prefixMap)
+    private static void writeGraph(IndentedWriter out, Node name, Graph graph,  Map<String, String> prefixMap)
     {
         if ( name != null )
         {
-            TurtleWriter2.writeNode(out, name, prefixMap) ;
+            TW2.writeNode(out, name, prefixMap) ;
             out.print("  ") ;
         }
         out.println("{") ;

Modified: jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/TurtleWriter2.java
URL: http://svn.apache.org/viewvc/jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/TurtleWriter2.java?rev=1432476&r1=1432475&r2=1432476&view=diff
==============================================================================
--- jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/TurtleWriter2.java (original)
+++ jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/TurtleWriter2.java Sat Jan 12 17:15:31 2013
@@ -18,73 +18,28 @@
 
 package projects.riot_writer;
 
+import static projects.riot_writer.WriterConst.INDENT_OBJECT ;
+import static projects.riot_writer.WriterConst.INDENT_PREDICATE ;
+import static projects.riot_writer.WriterConst.LONG_PREDICATE ;
+import static projects.riot_writer.WriterConst.LONG_SUBJECT ;
+import static projects.riot_writer.WriterConst.MIN_GAP ;
+import static projects.riot_writer.WriterConst.iriType ;
+import static projects.riot_writer.WriterConst.rdfNS ;
 
-import java.io.ByteArrayInputStream ;
-import java.io.ByteArrayOutputStream ;
 import java.io.OutputStream ;
 import java.util.* ;
-import java.util.Map.Entry ;
 
 import org.apache.jena.atlas.io.IndentedWriter ;
 import org.apache.jena.atlas.lib.Pair ;
-import org.apache.jena.atlas.lib.StrUtils ;
-import org.apache.jena.riot.IO_Jena ;
 import projects.viewgraph.GLib ;
 
 import com.hp.hpl.jena.graph.Graph ;
 import com.hp.hpl.jena.graph.Node ;
 import com.hp.hpl.jena.graph.Triple ;
 import com.hp.hpl.jena.rdf.model.Model ;
-import com.hp.hpl.jena.rdf.model.ModelFactory ;
-import com.hp.hpl.jena.sparql.util.FmtUtils ;
-import com.hp.hpl.jena.util.FileManager ;
-import com.hp.hpl.jena.vocabulary.RDF ;
 
 public class TurtleWriter2
 {
-    public static void main(String ... args)
-    {
-        IO_Jena.wireIntoJena() ;
-        Model m = FileManager.get().loadModel("D.ttl") ;
-        
-        write(System.out, m) ;
-        System.out.println("----------------------------------") ;
-        
-        
-        ByteArrayOutputStream out = new ByteArrayOutputStream() ;
-        write(out, m) ;
-        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()) ;
-        String s = StrUtils.fromUTF8bytes(out.toByteArray()) ;
-        Model m2 = ModelFactory.createDefaultModel() ;
-        m2.read(in, null, "TTL") ;
-        if ( ! m.isIsomorphicWith(m2) )
-            System.out.println("**** DIFFERENT") ;
-        
-        m.write(System.out, "TTL") ;
-    }
-    
-    private static final int LONG_SUBJECT = 20 ;
-    private static final int LONG_PREDICATE = 30 ;
-    private static final int PREFIX_IRI = 15;
-    
-    // Column widths.
-    private static int COLW_SUBJECT = 6 ;
-    private static int COLW_PREDICATE = 8 ;
-    
-    
-    // Column for start of predicate  
-    private static final int INDENT_PREDICATE = 8 ;
-    
-    // Column for start of object  
-    // Usually this is exceeded and predicate, objects are print with min gap. 
-    private static final int INDENT_OBJECT = 8 ;
-    
-    
-    private static final String iriType = RDF.type.getURI() ;
-    
-    private static final int MIN_GAP = 2 ;
-    
-    private static final String rdfNS = RDF.getURI() ;
 
     // Prepare prefixes.
     // Need fast String=>prefix.
@@ -99,46 +54,35 @@ public class TurtleWriter2
         IndentedWriter iOut = new IndentedWriter(out, false) ;
         write(iOut, graph, prefixMap) ;
     }
-    
+
     // Call from TriG as well.
     static void write(IndentedWriter out, Graph graph, Map<String, String> prefixMap)
     {
+        write$(out, graph, prefixMap) ;
+        out.flush() ;
+    }
+    
+    // Call from TriG as well.
+    static void write$(IndentedWriter out, Graph graph, Map<String, String> prefixMap)
+    {
         // Configuration.
         Pair<Set<Node>, Set<Triple>> p = TW2.findOneConnectedBNodeObjects(graph) ;
         Set<Node> bNodesObj1 = p.getLeft() ;
         Set<Triple> triplesObj1 = p.getRight() ;
         
         // Lists
-        writePrefixes(out, prefixMap) ;
+        
+        
+        // Prefixes
+        TW2.writePrefixes(out, prefixMap) ;
+        if ( ! prefixMap.isEmpty() )
+            out.println();
 
         // Or - listSubjects and sort.
         Iterator<Node> subjects = GLib.listSubjects(graph) ;
         writeBySubject(out, graph, subjects, bNodesObj1, triplesObj1, new HashSet<Object>(), prefixMap) ;
-        out.flush() ;
     }
     
-    static void writePrefixes(IndentedWriter out, Map<String, String> prefixMap)
-    {
-        if ( ! prefixMap.isEmpty() )
-        {
-            // prepare?
-            for ( Map.Entry <String, String> e : prefixMap.entrySet() )
-            {
-                print(out, "@prefix ") ;
-                print(out, e.getKey()) ;
-                print(out, ": ") ;
-                pad(out, PREFIX_IRI) ;
-                print(out, "<") ;
-                print(out, e.getValue()) ;   // Check?
-                print(out, ">") ;
-                print(out, " .") ;
-                println(out) ;
-            }
-            // Blank line.
-            println(out) ;
-        }
-    }
-
     static void writeBySubject(IndentedWriter out, Graph graph, 
                                Iterator<Node> subjects, 
                                Collection<Node> nestedObjects, Collection<Triple> skip, 
@@ -165,7 +109,7 @@ public class TurtleWriter2
         //int OFFSET = out.getIndent() ;
         
         if ( cluster.isEmpty() ) return ;
-        writeNode(out, subject, prefixMap) ;
+        TW2.writeNode(out, subject, prefixMap) ;
         
         if ( out.getCol() > LONG_SUBJECT )
             println(out) ;
@@ -175,7 +119,7 @@ public class TurtleWriter2
         out.pad() ;
         writePredicateObjectList(out, graph, cluster, nestedObjects, prefixMap) ;
         out.decIndent(INDENT_PREDICATE) ;
-        print(out, " .") ;  // Not perfect
+        TW2.print(out, " .") ;  // Not perfect
         println(out) ; 
         println(out) ;
     }
@@ -202,7 +146,7 @@ public class TurtleWriter2
                 first = false ;
             else
             {
-                print(out, " ;") ;
+                TW2.print(out, " ;") ;
                 println(out) ;
             }
             
@@ -212,9 +156,9 @@ public class TurtleWriter2
             if ( ! prefixMap.containsValue(rdfNS) &&
                 triple.getPredicate().getURI().equals(iriType) )
                 // I prefer rdf:type when available.
-                print(out, "a") ;
+                TW2.print(out, "a") ;
             else
-                writeNode(out, triple.getPredicate(), prefixMap) ;
+                TW2.writeNode(out, triple.getPredicate(), prefixMap) ;
             int colPredicateFinish = out.getCol() ;
             int wPredicate = (colPredicateFinish-colPredicateStart) ;
             
@@ -231,7 +175,7 @@ public class TurtleWriter2
             if ( nestedObjects.contains(obj) )
                 nestedObject(out, graph, obj, nestedObjects, prefixMap) ;
             else
-                writeNode(out, triple.getObject(), prefixMap) ;
+                TW2.writeNode(out, triple.getObject(), prefixMap) ;
             out.decIndent(INDENT_OBJECT) ;
         }
     }
@@ -243,22 +187,22 @@ public class TurtleWriter2
         
         if ( x.isEmpty() )
         {
-            print(out, "[] ") ;
+            TW2.print(out, "[] ") ;
             return ;
         }
 
         if ( x.size() == 1 )
         {
-            print(out, "[ ") ;
+            TW2.print(out, "[ ") ;
             // Includes nested object in triple.
             writePredicateObjectList(out, graph, x, nestedObjects, prefixMap) ;
-            print(out, " ]") ;
+            TW2.print(out, " ]") ;
             return ;
         }
 
         // Two or more.
         int here = out.getCol() ; // before "["
-        print(out, "[") ;
+        TW2.print(out, "[") ;
         int i1 = out.getIndent() ;
         out.setAbsoluteIndent(here) ;
         // Inline: println(out) ;
@@ -268,77 +212,28 @@ public class TurtleWriter2
         if ( true )
         {
             println(out) ; // Newline for "]"
-            print(out, "]") ;
+            TW2.print(out, "]") ;
         }
         else
         {   // Compact
-            print(out, " ]") ;
+            TW2.print(out, " ]") ;
         }
         out.setAbsoluteIndent(i1) ;
     }
     
-    static void writeNode(IndentedWriter out, Node node, Map<String, String> prefixMap)
-    {
-        // See RIOT NodeFormatter
-        if ( node.isURI() )
-        {
-            String iri = node.getURI() ;
-            // Crude.
-            String x = abbreviate(iri, prefixMap) ;
-            if ( x != null )
-            {
-                print(out, x) ;
-                return ;
-            }
-        }
-        
-        print(out, FmtUtils.stringForNode(node)) ;
-    }
-    
-    /** Abbreviate an IRI or return null */
-    private static String abbreviate(String uriStr, Map<String, String> prefixMap)
-    {
-        for ( Entry<String, String> e : prefixMap.entrySet())
-        {
-            String prefix = e.getValue().toString() ;
-            
-            if ( uriStr.startsWith(prefix) )
-            {
-                String ln = uriStr.substring(prefix.length()) ;
-                if ( strSafeFor(ln, '/') && strSafeFor(ln, '#') && strSafeFor(ln, ':') )
-                    return e.getKey()+":"+ln ;
-            }
-        }
-        return null ;
-    }
-    
-    private static boolean strSafeFor(String str, char ch) { return str.indexOf(ch) == -1 ; } 
+     
     
     // flush aggressively (debugging)
     
-    private static void flush(IndentedWriter out) { out.flush() ; } 
-    
-    private static void print(IndentedWriter out, String string)
-    {
-        out.print(string) ;
-        flush(out) ;
-    }
-    
     private static void gap(IndentedWriter out)
     {
         out.print(' ', MIN_GAP) ;
     }
     
-    private static void pad(IndentedWriter out, int col)
-    {
-        out.pad(col, true) ;
-    }
-    
     private static void println(IndentedWriter out)
     {
         out.println() ;
-        flush(out) ;
-        //System.err.println(out.getIndent()) ;
+        out.flush() ;
     }
 
     

Modified: jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/TurtleWriterBlocks.java
URL: http://svn.apache.org/viewvc/jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/TurtleWriterBlocks.java?rev=1432476&r1=1432475&r2=1432476&view=diff
==============================================================================
--- jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/TurtleWriterBlocks.java (original)
+++ jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/TurtleWriterBlocks.java Sat Jan 12 17:15:31 2013
@@ -46,7 +46,9 @@ public class TurtleWriterBlocks
     static void write(IndentedWriter out, Graph graph, Map<String, String> prefixMap)
     {
         // Lists
-        TurtleWriter2.writePrefixes(out, prefixMap) ;
+        TW2.writePrefixes(out, prefixMap) ;
+        if ( ! prefixMap.isEmpty() )
+            out.println();
         writeTriples(out, graph, graph.find(Node.ANY, Node.ANY, Node.ANY), prefixMap) ;
     }
     

Modified: jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/TurtleWriterFlat.java
URL: http://svn.apache.org/viewvc/jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/TurtleWriterFlat.java?rev=1432476&r1=1432475&r2=1432476&view=diff
==============================================================================
--- jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/TurtleWriterFlat.java (original)
+++ jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/TurtleWriterFlat.java Sat Jan 12 17:15:31 2013
@@ -18,13 +18,16 @@
 
 package projects.riot_writer;
 
+import java.io.OutputStream ;
 import java.util.Iterator ;
+import java.util.Map ;
 
 import org.apache.jena.atlas.io.IndentedWriter ;
 
 import com.hp.hpl.jena.graph.Graph ;
 import com.hp.hpl.jena.graph.Node ;
 import com.hp.hpl.jena.graph.Triple ;
+import com.hp.hpl.jena.rdf.model.Model ;
 
 /** Write Turtle as one line of prefixed names */   
 public class TurtleWriterFlat
@@ -33,26 +36,45 @@ public class TurtleWriterFlat
     static public final int predCol = 8 ;
     static public final int objCol = 8+predCol ;
     
-    public static void write(IndentedWriter out, Graph graph) 
+    public static void write(OutputStream out, Model model, Map<String, String> prefixes)
     {
+        IndentedWriter iOut = new IndentedWriter(out) ;
+        write(iOut, model.getGraph(), prefixes) ;
+    }
+    
+    public static void write(IndentedWriter out, Model model, Map<String, String> prefixes)
+    {
+        write(out, model.getGraph(), prefixes) ;
+    }
+    
+    public static void write(IndentedWriter out, Graph graph, Map<String, String> prefixes) 
+    {
+        TW2.writePrefixes(out, prefixes) ;
+        if ( ! prefixes.isEmpty() )
+            out.println();
+        
         Iterator<Triple> iter = graph.find(Node.ANY, Node.ANY, Node.ANY) ;
         
         for ( ; iter.hasNext() ; )
         {
             Triple triple = iter.next() ;
             
-            triple.getSubject() ;
-            out.pad(predCol-1) ;
-            out.print(" ") ;
-            
+            Node s = triple.getSubject() ;
+            TW2.writeNode(out, s, prefixes) ;
             
-            triple.getPredicate() ;
-            out.pad(objCol-1) ;
+            Node p = triple.getPredicate() ;
+            //out.pad(predCol-1) ;
             out.print(" ") ;
+            TW2.writeNode(out, p, prefixes) ;
             
-            triple.getObject() ;
+            Node o = triple.getObject() ;
+            //out.pad(objCol-1) ;
+            out.print(" ") ;
+            TW2.writeNode(out, o, prefixes) ;
 
             out.println(" .") ; 
         }
+        
+        out.flush() ;
     }
 }

Added: jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/WriterConst.java
URL: http://svn.apache.org/viewvc/jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/WriterConst.java?rev=1432476&view=auto
==============================================================================
--- jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/WriterConst.java (added)
+++ jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_writer/WriterConst.java Sat Jan 12 17:15:31 2013
@@ -0,0 +1,47 @@
+/**
+ * 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 projects.riot_writer;
+
+import com.hp.hpl.jena.vocabulary.RDF ;
+
+public class WriterConst
+{
+    public static final int LONG_SUBJECT = 20 ;
+    public static final int LONG_PREDICATE = 30 ;
+    public static final int PREFIX_IRI = 15;
+    
+    // Column widths.
+    public static int COLW_SUBJECT = 6 ;
+    public static int COLW_PREDICATE = 8 ;
+    
+    // Column for start of predicate  
+    public static final int INDENT_PREDICATE = 8 ;
+    
+    // Column for start of object  
+    // Usually this is exceeded and predicate, objects are print with min gap. 
+    public static final int INDENT_OBJECT = 8 ;
+    
+    public static final String iriType = RDF.type.getURI() ;
+    
+    public static final int MIN_GAP = 2 ;
+    
+    public static final String rdfNS = RDF.getURI() ;
+
+}
+