Added: jena/Experimental/riot-output/src/main/java/riot/writer/TriGWriterFlat.java URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/TriGWriterFlat.java?rev=1441178&view=auto ============================================================================== --- jena/Experimental/riot-output/src/main/java/riot/writer/TriGWriterFlat.java (added) +++ jena/Experimental/riot-output/src/main/java/riot/writer/TriGWriterFlat.java Thu Jan 31 20:20:49 2013 @@ -0,0 +1,25 @@ +/** + * 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 riot.writer; + +public class TriGWriterFlat +{ + +} +
Added: jena/Experimental/riot-output/src/main/java/riot/writer/TurtleWriter2.java URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/TurtleWriter2.java?rev=1441178&view=auto ============================================================================== --- jena/Experimental/riot-output/src/main/java/riot/writer/TurtleWriter2.java (added) +++ jena/Experimental/riot-output/src/main/java/riot/writer/TurtleWriter2.java Thu Jan 31 20:20:49 2013 @@ -0,0 +1,334 @@ +/** + * 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 riot.writer; + +import static riot.writer.WriterConst.INDENT_OBJECT ; +import static riot.writer.WriterConst.INDENT_PREDICATE ; +import static riot.writer.WriterConst.LONG_PREDICATE ; +import static riot.writer.WriterConst.LONG_SUBJECT ; +import static riot.writer.WriterConst.MIN_GAP ; +import static riot.writer.WriterConst.RDF_First ; +import static riot.writer.WriterConst.RDF_Rest ; +import static riot.writer.WriterConst.iriType ; +import static riot.writer.WriterConst.rdfNS ; + +import java.io.OutputStream ; +import java.util.* ; +import java.util.Map.Entry ; + +import org.apache.jena.atlas.io.IndentedWriter ; +import org.apache.jena.riot.out.NodeToLabel ; +import org.apache.jena.riot.system.PrefixMap ; +import org.apache.jena.riot.system.PrefixMapFactory ; +import riot.other.GLib ; +import riot.out.NodeFormatterTTL ; + +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 ; + +public class TurtleWriter2 +{ + + // Prepare prefixes. + // Need fast String=>prefix. + + public static void write(OutputStream cxt, Model model) + { + write(cxt, model.getGraph(), model.getNsPrefixMap()) ; + } + + public static void write(OutputStream out, Graph graph, Map<String, String> prefixMap) + { + 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) + { + WriterContext cxt = new WriterContext() ; + PrefixMap pmap = PrefixMapFactory.create() ; + for ( Entry<String, String> e : prefixMap.entrySet() ) + pmap.add(e.getKey(), e.getValue()) ; + + cxt.out = out ; + cxt.prefixMap = prefixMap ; + cxt.nodeFmt = new NodeFormatterTTL(null, pmap, NodeToLabel.createScopeByDocument()) ; + cxt.graph = graph ; + + // TW2 -> hereas + + // Configuration. + TW2.findOneConnectedBNodeObjects(cxt) ; + + // Lists + TW2.findLists(cxt) ; + + // TODO Right check? + // Stop head of lists printed as triples going all the way to the good part. + cxt.nestedObjects.removeAll(cxt.listElts) ; + + // Prefixes + TW2.writePrefixes(cxt, prefixMap) ; + if ( ! prefixMap.isEmpty() ) + out.println(); + + // Or - listSubjects and sort. + Iterator<Node> subjects = GLib.listSubjects(graph) ; + boolean b = writeBySubject(cxt, subjects) ; + + if ( ! cxt.nLinkedLists.isEmpty() ) + { + // Print carefully - need a label for the first cell. + // So we write out the first element of the list in triples, then put + // the remainer as a pretty lst. + + if ( b ) out.println() ; + b = false ; + + for ( Node n : cxt.nLinkedLists.keySet() ) + { + + + List<Node> x = cxt.nLinkedLists.get(n) ; + + // ---- DRY : writeCluster + TW2.writeNode(cxt, n) ; + + if ( out.getCol() > LONG_SUBJECT ) + println(cxt) ; + else + gap(cxt) ; + out.incIndent(INDENT_PREDICATE) ; + // ---- + out.pad() ; + TW2.writeNode(cxt, RDF_First) ; + TW2.print(cxt, " ") ; + TW2.writeNode(cxt, x.get(0)) ; + TW2.print(cxt, " ;") ; + println(cxt) ; + TW2.writeNode(cxt, RDF_Rest) ; + TW2.print(cxt, " ") ; + x = x.subList(1, x.size()) ; + list(cxt, x) ; + TW2.print(cxt, " .") ; + println(cxt) ; + } + } + //else out.println("# No NNNN") ; + + if ( ! cxt.freeLists.isEmpty() ) + { + if ( b ) out.println() ; + out.println("# >> 0000") ; + // Write free lists. + for ( Node n : cxt.freeLists.keySet() ) + { + list(cxt, cxt.freeLists.get(n)) ; + out.println(" .") ; + } + //out.println() ; + } + //else out.println("# No 0000") ; + } + + // return true if did write something. + static boolean writeBySubject(WriterContext cxt, Iterator<Node> subjects) + { + boolean first = true ; + for ( ; subjects.hasNext() ; ) + { + Node subj = subjects.next() ; + if ( cxt.nestedObjects.contains(subj) ) + continue ; + if ( cxt.listElts.contains(subj) ) + continue ; + if ( ! first ) + cxt.out.println() ; + first = false ; + + Collection<Triple> cluster = TW2.triplesOfSubject(cxt.graph, subj) ; + writeCluster(cxt, subj, cluster) ; + } + return !first ; + } + + + // Common subject + // Used by the blocks writer as well. + static void writeCluster(WriterContext cxt, Node subject, Collection<Triple> cluster) + { + if ( cluster.isEmpty() ) return ; + TW2.writeNode(cxt, subject) ; + + if ( cxt.out.getCol() > LONG_SUBJECT ) + cxt.out.println() ; + else + gap(cxt) ; + cxt.out.incIndent(INDENT_PREDICATE) ; + cxt.out.pad() ; + writePredicateObjectList(cxt, cluster) ; + cxt.out.decIndent(INDENT_PREDICATE) ; + TW2.print(cxt, " .") ; // Not perfect + cxt.out.println() ; + } + + // need to skip the triples nested. + + private static void writePredicateObjectList(WriterContext cxt, Collection<Triple> cluster) + { + boolean first = true ; + // Calc columns + + // Sort triples. + // rdf:type + // other rdf and rdfs + // properties together + // object lists? + // Find the colject pad column. + + + for ( Triple triple : cluster ) + { + if ( first ) + first = false ; + else + { + TW2.print(cxt, " ;") ; + println(cxt) ; + } + + // Write predicate. + int colPredicateStart = cxt.out.getCol() ; + + if ( ! cxt.prefixMap.containsValue(rdfNS) && + triple.getPredicate().getURI().equals(iriType) ) + // I prefer rdf:type when available. + TW2.print(cxt, "a") ; + else + TW2.writeNode(cxt, triple.getPredicate()) ; + int colPredicateFinish = cxt.out.getCol() ; + int wPredicate = (colPredicateFinish-colPredicateStart) ; + + // Needs to be relative? + if ( wPredicate > LONG_PREDICATE ) + println(cxt) ; + else + gap(cxt) ; + + // Secondary one should be less + cxt.out.incIndent(INDENT_OBJECT) ; + cxt.out.pad() ; + Node obj = triple.getObject() ; + writeObject(cxt, obj) ; + cxt.out.decIndent(INDENT_OBJECT) ; + } + } + + // --> write S or O?? + private static void writeObject(WriterContext cxt, Node obj) + { + // Order matters? - one connected objects may include list elements. + if ( cxt.lists.containsKey(obj) ) + list(cxt, cxt.lists.get(obj)) ; + else if ( cxt.nestedObjects.contains(obj) ) + nestedObject(cxt, obj) ; + else + TW2.writeNode(cxt, obj) ; + } + + private static void nestedObject(WriterContext cxt, Node obj) + { + Collection<Triple> x = TW2.triplesOfSubject(cxt.graph, obj) ; + + if ( x.isEmpty() ) + { + TW2.print(cxt, "[] ") ; + return ; + } + + if ( x.size() == 1 ) + { + TW2.print(cxt, "[ ") ; + // Includes nested object in triple. + writePredicateObjectList(cxt, x) ; + TW2.print(cxt, " ]") ; + return ; + } + + // Two or more. + int here = cxt.out.getCol() ; // before "[" + TW2.print(cxt, "[") ; + int i1 = cxt.out.getAbsoluteIndent() ; + cxt.out.setAbsoluteIndent(here) ; + // Inline: println(out) ; + cxt.out.incIndent(2) ; + writePredicateObjectList(cxt, x) ; + cxt.out.decIndent(2) ; + if ( true ) + { + println(cxt) ; // Newline for "]" + TW2.print(cxt, "]") ; + } + else + { // Compact + TW2.print(cxt, " ]") ; + } + cxt.out.setAbsoluteIndent(i1) ; + } + + + private static void list(WriterContext cxt, List<Node> elts) + { + TW2.print(cxt, "(") ; + for ( Node n : elts ) + { + TW2.print(cxt, " ") ; + writeObject(cxt, n) ; + } + + TW2.print(cxt, " )") ; + } + + + + private static void gap(WriterContext cxt) + { + cxt.out.print(' ', MIN_GAP) ; + } + + // flush aggressively (debugging) + private static void println(WriterContext cxt) + { + cxt.out.println() ; + //cxt.out.flush() ; + } + + +} + Added: jena/Experimental/riot-output/src/main/java/riot/writer/TurtleWriterBlocks.java URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/TurtleWriterBlocks.java?rev=1441178&view=auto ============================================================================== --- jena/Experimental/riot-output/src/main/java/riot/writer/TurtleWriterBlocks.java (added) +++ jena/Experimental/riot-output/src/main/java/riot/writer/TurtleWriterBlocks.java Thu Jan 31 20:20:49 2013 @@ -0,0 +1,63 @@ +/** + * 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 riot.writer; + +import java.io.OutputStream ; +import java.util.Iterator ; +import java.util.Map ; +import java.util.Map.Entry ; + +import org.apache.jena.atlas.io.IndentedWriter ; +import org.apache.jena.riot.system.StreamRDF ; + +import com.hp.hpl.jena.graph.Graph ; +import com.hp.hpl.jena.graph.Triple ; +import com.hp.hpl.jena.rdf.model.Model ; + +public class TurtleWriterBlocks +{ + public static void write(OutputStream out, Model model) + { + IndentedWriter iOut = new IndentedWriter(out) ; + write(iOut, model.getGraph(), model.getNsPrefixMap()) ; + } + + public static void write(IndentedWriter out, Model model) + { + write(out, model.getGraph(), model.getNsPrefixMap()) ; + } + + public static void write(IndentedWriter out, Graph graph, Map<String, String> prefixes) + { + StreamRDF dest = new WriterStreamRDFBlocks(out) ; + dest.start() ; + for ( Entry<String, String> e : prefixes.entrySet() ) + dest.prefix(e.getKey(), e.getValue()) ; + Iterator<Triple> iter = graph.find(null, null, null) ; + for ( ; iter.hasNext() ; ) + { + Triple t = iter.next() ; + dest.triple(t) ; + } + dest.finish() ; + } + + +} + Added: jena/Experimental/riot-output/src/main/java/riot/writer/TurtleWriterFlat.java URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/TurtleWriterFlat.java?rev=1441178&view=auto ============================================================================== --- jena/Experimental/riot-output/src/main/java/riot/writer/TurtleWriterFlat.java (added) +++ jena/Experimental/riot-output/src/main/java/riot/writer/TurtleWriterFlat.java Thu Jan 31 20:20:49 2013 @@ -0,0 +1,86 @@ +/** + * 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 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 +{ + static public final int colWidth = 8 ; + static public final int predCol = 8 ; + static public final int objCol = 8+predCol ; + + public static void write(OutputStream out, Model model) + { + IndentedWriter iOut = new IndentedWriter(out) ; + write(iOut, model.getGraph(), model.getNsPrefixMap()) ; + } + + public static void write(IndentedWriter out, Model model) + { + write(out, model.getGraph(), model.getNsPrefixMap()) ; + } + + public static void write(OutputStream out, Graph graph, Map<String, String> prefixes) + { + IndentedWriter iOut = new IndentedWriter(out) ; + write(iOut, graph, 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() ; + + Node s = triple.getSubject() ; + TW2.writeNode(out, prefixes, s) ; + + Node p = triple.getPredicate() ; + //out.pad(predCol-1) ; + out.print(" ") ; + TW2.writeNode(out, prefixes, p) ; + + Node o = triple.getObject() ; + //out.pad(objCol-1) ; + out.print(" ") ; + TW2.writeNode(out, prefixes, o) ; + + out.println(" .") ; + } + + out.flush() ; + } +} Added: jena/Experimental/riot-output/src/main/java/riot/writer/WriterConst.java URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/WriterConst.java?rev=1441178&view=auto ============================================================================== --- jena/Experimental/riot-output/src/main/java/riot/writer/WriterConst.java (added) +++ jena/Experimental/riot-output/src/main/java/riot/writer/WriterConst.java Thu Jan 31 20:20:49 2013 @@ -0,0 +1,52 @@ +/** + * 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 riot.writer; + +import com.hp.hpl.jena.graph.Node ; +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; + + public static final Node RDF_First = RDF.Nodes.first ; + public static final Node RDF_Rest = RDF.Nodes.rest ; + public static final Node RDF_Nil = RDF.Nodes.nil ; + + // 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() ; + +} + Added: jena/Experimental/riot-output/src/main/java/riot/writer/WriterContext.java URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/WriterContext.java?rev=1441178&view=auto ============================================================================== --- jena/Experimental/riot-output/src/main/java/riot/writer/WriterContext.java (added) +++ jena/Experimental/riot-output/src/main/java/riot/writer/WriterContext.java Thu Jan 31 20:20:49 2013 @@ -0,0 +1,46 @@ +/** + * 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 riot.writer; + +import java.util.Collection ; +import java.util.List ; +import java.util.Map ; +import java.util.Set ; + +import org.apache.jena.atlas.io.IndentedWriter ; +import riot.out.NodeFormatter ; + +import com.hp.hpl.jena.graph.Graph ; +import com.hp.hpl.jena.graph.Node ; + +// Package scope - a struct for holding all the details of the writing process. +final class WriterContext +{ + IndentedWriter out ; + Graph graph ; + NodeFormatter nodeFmt ; + Map<String, String> prefixMap ; + Set<Node> nestedObjects ; // Blank nodes that have one incoming triple + Map<Node, List<Node>> lists; // The head node in each well-formed lists -> list elements + Map<Node, List<Node>> freeLists; // List that do not have any incoming triples + Map<Node, List<Node>> nLinkedLists; // Lists that have more than one incoming triple + Collection<Node> listElts ; // All nodes that are part of list structures. + +} + Added: jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDFBlocks.java URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDFBlocks.java?rev=1441178&view=auto ============================================================================== --- jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDFBlocks.java (added) +++ jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDFBlocks.java Thu Jan 31 20:20:49 2013 @@ -0,0 +1,320 @@ +/** + * 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 riot.writer; + +import static org.apache.jena.atlas.lib.Lib.equal ; + +import java.io.OutputStream ; + +import org.apache.jena.atlas.io.IndentedWriter ; +import org.apache.jena.atlas.lib.Tuple ; +import org.apache.jena.riot.out.NodeToLabel ; +import org.apache.jena.riot.system.PrefixMap ; +import org.apache.jena.riot.system.PrefixMapFactory ; +import org.apache.jena.riot.system.StreamRDF ; +import riot.out.NodeFormatterTTL ; + +import com.hp.hpl.jena.graph.Node ; +import com.hp.hpl.jena.graph.Triple ; +import com.hp.hpl.jena.sparql.core.Quad ; + +/** An output of triples / quads that is streaming. + * It writes something that is easier to read than + * N-triples, N-quads but it's not full pretty printing + * which usually requires analysing the data before any output + * hence is not streaming. + * + * If fed only quads, the output is valid TriG. + * If fed only triples, the output is valid Turtle. + */ + +public class WriterStreamRDFBlocks implements StreamRDF +{ + // TODO + // Min width for properties? + // better layering and state machine + + // When false, gets + // :g1 { ... } + // :g2 { ... } + private static final boolean NL_GDFT_START = false ; // Newline after { of dft graph + private static final boolean NL_GNMD_START = true ; // same, but for named graphs + private static final boolean NL_GDFT_END = false ; // Whether the closing } is on a new line + private static final boolean NL_GNMD_END = false ; // Whether the closing } is on a new line + + private static final int INDENT_MIN_S = 4 ; // Range of subject indent + private static final int INDENT_MAX_S = 10 ; // i.e. offset of predicate. + + private static final int INDENT_GDFT = 2 ; // Default graph indent + private static final int INDENT_GNMD = 4 ; // Named graph indent + + private boolean lastWasTripleData = false ; + private boolean lastWasQuadData = false ; + private boolean lastWasDirective = false ; + + private final PrefixMap pMap ; + private final NodeFormatterTTL fmt ; + private final IndentedWriter out ; + + private Node lastSubject = null ; + private Node lastGraph = null ; // null -> unset : Quad. + + // --- Indent management. + private int currentGraphIndent = 0; + private int currentSubjectIndent = 0 ; + + private void setGraphIndent(int x) + { + currentGraphIndent = x ; + } + + private void setSubjectIndent(int x) + { + if ( x < INDENT_MIN_S ) x = INDENT_MIN_S ; + if ( x > INDENT_MAX_S ) x = INDENT_MAX_S ; + currentSubjectIndent = x ; + } + + private int graphIndent() { return currentGraphIndent ; } + private int subjectIndent() { return currentSubjectIndent ; } + // ---- + public WriterStreamRDFBlocks(OutputStream output) + { + this(new IndentedWriter(output)) ; + + } + public WriterStreamRDFBlocks(IndentedWriter output) + { + out = output ; + pMap = PrefixMapFactory.create() ; + fmt = new NodeFormatterTTL(null, pMap, NodeToLabel.createScopeByDocument()) ; + } + + + @Override + public void start() + { + reset() ; + } + + @Override + public void finish() + { + endData() ; + out.flush() ; + } + + @Override + public void triple(Triple triple) + { + Node s = triple.getSubject() ; + Node p = triple.getPredicate() ; + Node o = triple.getObject() ; + print(s,p,o) ; + } + + @Override + public void quad(Quad quad) + { + Node g = quad.getGraph() ; + Node s = quad.getSubject() ; + Node p = quad.getPredicate() ; + Node o = quad.getObject() ; + if ( g == null ) + // Don't have g as null for a triple. + g = Quad.defaultGraphNodeGenerated ; + print(g, s, p, o) ; + } + + @Override + public void tuple(Tuple<Node> tuple) + {} + + @Override + public void base(String base) + { + + } + + @Override + public void prefix(String prefix, String iri) + { + endData() ; + lastWasDirective = true ; + + out.print("@prefix ") ; + out.print(prefix) ; + out.print(": <") ; + out.print(iri) ; // Don't let it be abbreviated! + out.println("> .") ; + pMap.add(prefix, iri) ; + } + + private void outputNode(Node n) + { + fmt.format(out, n) ; + } + + private void reset() + { + lastWasTripleData = false ; + lastWasQuadData = false ; + lastWasDirective = false ; + lastSubject = null ; + lastGraph = null ; + // Shouldn't be necessary - if it is some other code is not managing inc/dec indents. + //out.setAbsoluteIndent(0) ; + } + + private void printPre() + { + // Directive -> data transition. + if ( lastWasDirective ) + { + reset() ; + out.print('\n') ; + } + } + + private void DEBUG(String fmt, Object...args) + { + int loc = out.getCol() ; // Absolute + int off = out.getAbsoluteIndent() ; + out.ensureStartOfLine(); + out.setAbsoluteIndent(0) ; + out.println(String.format(fmt, args)) ; + out.setAbsoluteIndent(off) ; + out.ensureStartOfLine(); + out.pad(loc, true) ; + } + + private void print(Node g, Node s, Node p, Node o) + { + printPre() ; + endGraph(g) ; + startGraph(g) ; + print$(s,p,o) ; + lastGraph = g ; + lastWasQuadData = true ; + } + + private void print(Node s, Node p, Node o) + { + printPre() ; + print$(s, p, o) ; + lastWasTripleData = true ; + } + + private void print$(Node s, Node p, Node o) + { + if ( equal(lastSubject, s) ) + out.println(" ;") ; + else { + // Change subject, same graph. + if ( lastSubject != null ) + endTriples() ; + + outputNode(s) ; + out.print(' ') ; + setSubjectIndent(out.getCurrentOffset()) ; + } + out.pad(subjectIndent()) ; + outputNode(p) ; + out.print(' ') ; + outputNode(o) ; + lastSubject = s ; + } + + private boolean dftGraph() { return lastGraph == Quad.defaultGraphNodeGenerated ; } + + private void endGraph(Node g) + { + if ( lastGraph == null ) + return ; + + // End of graph + if ( ! equal(lastGraph, g) ) + { + out.print(" .") ; + boolean nl = dftGraph() ? NL_GDFT_END : NL_GNMD_END ; + + if ( nl ) { + // } on a new line. + out.decIndent(graphIndent()) ; + out.println() ; + out.println("}") ; + } else { + // } on same line as last quad/triple. + out.println(" }") ; // Trailing NL + out.decIndent(graphIndent()) ; + out.println() ; + } + lastSubject = null ; + lastGraph = null ; + } + } + + private void startGraph(Node g) + { + // Start graph + if ( lastGraph == null ) + { + lastSubject = null ; + if ( g == Quad.defaultGraphNodeGenerated ) + { + out.print("{ ") ; + setGraphIndent(INDENT_GDFT) ; + if ( NL_GDFT_START ) + out.println(); + } + else + { + outputNode(g) ; + out.print(" { ") ; + if ( NL_GNMD_START ) + { + out.println() ; + setGraphIndent(INDENT_GNMD) ; + } + else + { + setGraphIndent(out.getCol()) ; + } + } + out.incIndent(graphIndent()) ; + } + lastGraph = g ; + } + + private void endTriples() + { + out.println(" .") ; + lastSubject = null ; + } + + private void endData() + { + if ( lastWasQuadData ) + endGraph(null) ; + if ( lastWasTripleData ) + endTriples() ; + reset() ; + } + +} Added: jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDFFlat.java URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDFFlat.java?rev=1441178&view=auto ============================================================================== --- jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDFFlat.java (added) +++ jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDFFlat.java Thu Jan 31 20:20:49 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 riot.writer; + +import org.apache.jena.atlas.lib.Tuple ; +import org.apache.jena.riot.system.StreamRDF ; + +import com.hp.hpl.jena.graph.Node ; +import com.hp.hpl.jena.graph.Triple ; +import com.hp.hpl.jena.sparql.core.Quad ; + +/** An output of triples / quads that is streaming. + * It writes N-triples/N-quads + prefixes. + * + * If fed only quads, the output is valid TriG (use Quad.defaultGraphIRI) + * If fed only triples, the output is valid Turtle. + */ + +public class WriterStreamRDFFlat implements StreamRDF +{ + + @Override + public void start() + {} + + @Override + public void triple(Triple triple) + {} + + @Override + public void quad(Quad quad) + {} + + @Override + public void tuple(Tuple<Node> tuple) + {} + + @Override + public void base(String base) + {} + + @Override + public void prefix(String prefix, String iri) + {} + + @Override + public void finish() + {} +} Added: jena/Experimental/riot-output/src/test/java/riot/writer/TestRIOTWriter.java URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/test/java/riot/writer/TestRIOTWriter.java?rev=1441178&view=auto ============================================================================== --- jena/Experimental/riot-output/src/test/java/riot/writer/TestRIOTWriter.java (added) +++ jena/Experimental/riot-output/src/test/java/riot/writer/TestRIOTWriter.java Thu Jan 31 20:20:49 2013 @@ -0,0 +1,87 @@ +/** + * 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 riot.writer; + +import java.io.ByteArrayInputStream ; +import java.io.ByteArrayOutputStream ; +import java.io.IOException ; + +import org.apache.jena.atlas.io.IO ; +import org.apache.jena.atlas.junit.BaseTest ; +import org.apache.jena.riot.Lang ; +import org.apache.jena.riot.RDFDataMgr ; +import org.junit.Test ; +import riot.writer.TurtleWriter2 ; + +import com.hp.hpl.jena.rdf.model.Model ; +import com.hp.hpl.jena.rdf.model.ModelFactory ; +import com.hp.hpl.jena.util.FileUtils ; + +public class TestRIOTWriter extends BaseTest +{ + // Round trip tests. + + static String DIR = "testing/RIOT/Writer" ; + + @Test public void writer00() { test("writer-rt-00.ttl") ; } + @Test public void writer01() { test("writer-rt-01.ttl") ; } + @Test public void writer02() { test("writer-rt-02.ttl") ; } + @Test public void writer03() { test("writer-rt-03.ttl") ; } + @Test public void writer04() { test("writer-rt-04.ttl") ; } + @Test public void writer05() { test("writer-rt-05.ttl") ; } + @Test public void writer06() { test("writer-rt-06.ttl") ; } + @Test public void writer07() { test("writer-rt-07.ttl") ; } + @Test public void writer08() { test("writer-rt-08.ttl") ; } + @Test public void writer09() { test("writer-rt-09.ttl") ; } + @Test public void writer10() { test("writer-rt-10.ttl") ; } + @Test public void writer11() { test("writer-rt-11.ttl") ; } + @Test public void writer12() { test("writer-rt-12.ttl") ; } + @Test public void writer13() { test("writer-rt-13.ttl") ; } + @Test public void writer14() { test("writer-rt-14.ttl") ; } + @Test public void writer15() { test("writer-rt-15.ttl") ; } + @Test public void writer16() { test("writer-rt-16.ttl") ; } + + private void test(String filename) + { + String fn = DIR + "/" + filename ; + Model m = RDFDataMgr.loadModel(fn) ; + + // check. + ByteArrayOutputStream out = new ByteArrayOutputStream() ; + TurtleWriter2.write(out, m) ; + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()) ; + + Model m2 = ModelFactory.createDefaultModel() ; + RDFDataMgr.read(m2, in, Lang.TURTLE) ; + boolean b = m.isIsomorphicWith(m2) ; + if ( !b ) + { + try { + System.out.println("---------------------------------------------------------") ; + System.out.println("#### file="+filename) ; + String s = FileUtils.readWholeFileAsUTF8(fn) ; + System.out.print(s) ; + } catch ( IOException ex) { IO.exception(ex) ; } + } + + assertTrue("Did not round-trip file="+filename, b) ; + } + +} + Added: jena/Experimental/riot-output/testing/RIOT/Writer/README.txt URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/testing/RIOT/Writer/README.txt?rev=1441178&view=auto ============================================================================== --- jena/Experimental/riot-output/testing/RIOT/Writer/README.txt (added) +++ jena/Experimental/riot-output/testing/RIOT/Writer/README.txt Thu Jan 31 20:20:49 2013 @@ -0,0 +1,4 @@ +writer-rt-*: + Round trip tests - read in M1, write out, read output M2, + and test models M1 and M2 are the same. + Added: jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-00.ttl URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-00.ttl?rev=1441178&view=auto ============================================================================== --- jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-00.ttl (added) +++ jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-00.ttl Thu Jan 31 20:20:49 2013 @@ -0,0 +1,15 @@ +@prefix : <http://example/> . +@prefix ns: <http://example/ns#> . +@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . + +# This is a well-formed list used in the later few tests. +:x :q _:x0 . + +_:x0 rdf:first "cell-0" . +_:x0 rdf:rest _:x1 . + +_:x1 rdf:first "cell-1" . +_:x1 rdf:rest _:x2 . + +_:x2 rdf:first "cell-2" . +_:x2 rdf:rest rdf:nil . \ No newline at end of file Added: jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-01.ttl URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-01.ttl?rev=1441178&view=auto ============================================================================== --- jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-01.ttl (added) +++ jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-01.ttl Thu Jan 31 20:20:49 2013 @@ -0,0 +1,5 @@ +@prefix : <http://example/> . +@prefix ns: <http://example/ns#> . +@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . + +# Empty. Added: jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-02.ttl URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-02.ttl?rev=1441178&view=auto ============================================================================== --- jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-02.ttl (added) +++ jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-02.ttl Thu Jan 31 20:20:49 2013 @@ -0,0 +1,9 @@ +@prefix : <http://example/> . +@prefix ns: <http://example/ns#> . +@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . + +# Simple stuff. +:s ns:p1 <http://other/planet> . +:s ns:p2 123 . +:s ns:p3 [] . +:s a :T . Added: jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-03.ttl URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-03.ttl?rev=1441178&view=auto ============================================================================== --- jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-03.ttl (added) +++ jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-03.ttl Thu Jan 31 20:20:49 2013 @@ -0,0 +1,7 @@ +@prefix : <http://example/> . +@prefix ns: <http://example/ns#> . +@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . + +# Shared bNode object. +:z :p1 _:a . +:z :p2 _:a . Added: jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-04.ttl URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-04.ttl?rev=1441178&view=auto ============================================================================== --- jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-04.ttl (added) +++ jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-04.ttl Thu Jan 31 20:20:49 2013 @@ -0,0 +1,9 @@ +@prefix : <http://example/> . +@prefix ns: <http://example/ns#> . +@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . + +# Well formed lists +:a :q1 (1 2 3) . +:a :q2 ( 1 ) . +:a :q3 () . +:a :q4 ( :s [ :p :o ] ) . Added: jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-05.ttl URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-05.ttl?rev=1441178&view=auto ============================================================================== --- jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-05.ttl (added) +++ jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-05.ttl Thu Jan 31 20:20:49 2013 @@ -0,0 +1,10 @@ +@prefix : <http://example/> . +@prefix ns: <http://example/ns#> . +@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . + +# Shared list. +:s1 :p _:b . +:s2 :p _:b . + + _:b rdf:first 9 ; + rdf:rest ( 8 ) . Added: jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-06.ttl URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-06.ttl?rev=1441178&view=auto ============================================================================== --- jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-06.ttl (added) +++ jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-06.ttl Thu Jan 31 20:20:49 2013 @@ -0,0 +1,16 @@ +@prefix : <http://example/> . +@prefix ns: <http://example/ns#> . +@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . + +# Shared list +:s1 :slist _:x1 . +:s2 :slist _:x2 . + +_:x1 rdf:first "A" ; + rdf:rest _:y . + +_:x2 rdf:first "B" ; + rdf:rest _:y . + +_:y rdf:first 9 ; + rdf:rest ( 8 7 ) . Added: jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-07.ttl URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-07.ttl?rev=1441178&view=auto ============================================================================== --- jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-07.ttl (added) +++ jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-07.ttl Thu Jan 31 20:20:49 2013 @@ -0,0 +1,9 @@ +@prefix : <http://example/> . +@prefix ns: <http://example/ns#> . +@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . + +# bad list +:x :p1 _:bad1 . +_:bad1 rdf:first 19 ; + rdf:first 18 ; + rdf:rest rdf:nil . Added: jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-08.ttl URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-08.ttl?rev=1441178&view=auto ============================================================================== --- jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-08.ttl (added) +++ jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-08.ttl Thu Jan 31 20:20:49 2013 @@ -0,0 +1,15 @@ +@prefix : <http://example/> . +@prefix ns: <http://example/ns#> . +@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . + +# bad list : no tail. +:x1 :q _:x0 . + +_:x0 rdf:first "cell-0" . +_:x0 rdf:rest _:x1 . + +_:x1 rdf:first "cell-1" . +_:x1 rdf:rest :wrongend . ## URI, not rdf:nil + +## _:x2 rdf:first "cell-2" . +## _:x2 rdf:rest rdf:nil . \ No newline at end of file Added: jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-09.ttl URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-09.ttl?rev=1441178&view=auto ============================================================================== --- jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-09.ttl (added) +++ jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-09.ttl Thu Jan 31 20:20:49 2013 @@ -0,0 +1,15 @@ +@prefix : <http://example/> . +@prefix ns: <http://example/ns#> . +@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . + +# bad list : no rdf:first +:x1 :q _:x0 . + +## _:x0 rdf:first "cell-0" . +_:x0 rdf:rest _:x1 . + +_:x1 rdf:first "cell-1" . +_:x1 rdf:rest _:x2 . + +_:x2 rdf:first "cell-2" . +_:x2 rdf:rest rdf:nil . Added: jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-10.ttl URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-10.ttl?rev=1441178&view=auto ============================================================================== --- jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-10.ttl (added) +++ jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-10.ttl Thu Jan 31 20:20:49 2013 @@ -0,0 +1,15 @@ +@prefix : <http://example/> . +@prefix ns: <http://example/ns#> . +@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . + +# bad list : no rdf first on last element. +:x1 :q _:x0 . + +_:x0 rdf:first "cell-0" . +_:x0 rdf:rest _:x1 . + +_:x1 rdf:first "cell-1" . +_:x1 rdf:rest _:x2 . + +## _:x2 rdf:first "cell-2" . +_:x2 rdf:rest rdf:nil . Added: jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-11.ttl URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-11.ttl?rev=1441178&view=auto ============================================================================== --- jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-11.ttl (added) +++ jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-11.ttl Thu Jan 31 20:20:49 2013 @@ -0,0 +1,15 @@ +@prefix : <http://example/> . +@prefix ns: <http://example/ns#> . +@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . + +# bad list : no rdf rest on element. +:x1 :q _:x0 . + +_:x0 rdf:first "cell-0" . +## _:x0 rdf:rest _:x1 . + +_:x1 rdf:first "cell-1" . +_:x1 rdf:rest _:x2 . + +_:x2 rdf:first "cell-2" . +_:x2 rdf:rest rdf:nil . Added: jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-12.ttl URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-12.ttl?rev=1441178&view=auto ============================================================================== --- jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-12.ttl (added) +++ jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-12.ttl Thu Jan 31 20:20:49 2013 @@ -0,0 +1,16 @@ +@prefix : <http://example/> . +@prefix ns: <http://example/ns#> . +@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . + +:x :q _:x0 . + +# bad list : 2 rdf:first on one cell. +_:x0 rdf:first "cell-0a" . +_:x0 rdf:first "cell-0b" . +_:x0 rdf:rest _:x1 . + +_:x1 rdf:first "cell-1" . +_:x1 rdf:rest _:x2 . + +_:x2 rdf:first "cell-2" . +_:x2 rdf:rest rdf:nil . \ No newline at end of file Added: jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-13.ttl URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-13.ttl?rev=1441178&view=auto ============================================================================== --- jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-13.ttl (added) +++ jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-13.ttl Thu Jan 31 20:20:49 2013 @@ -0,0 +1,17 @@ +@prefix : <http://example/> . +@prefix ns: <http://example/ns#> . +@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . + +:x :q _:x0 . + +# bad list : non-list property on a cell. + +_:x0 rdf:first "cell-0a" . +_:x0 ns:other "cell-0b" . +_:x0 rdf:rest _:x1 . + +_:x1 rdf:first "cell-1" . +_:x1 rdf:rest _:x2 . + +_:x2 rdf:first "cell-2" . +_:x2 rdf:rest rdf:nil .@prefix : <http://example/> . Added: jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-14.ttl URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-14.ttl?rev=1441178&view=auto ============================================================================== --- jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-14.ttl (added) +++ jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-14.ttl Thu Jan 31 20:20:49 2013 @@ -0,0 +1,19 @@ +@prefix : <http://example/> . +@prefix ns: <http://example/ns#> . +@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . + +:x :q _:x0 . + +# Bad list : extra tail. +_:x0 rdf:first "cell-0" . +_:x0 rdf:rest _:x1 . + +_:x1 rdf:first "cell-1" . +_:x1 rdf:rest _:x2 . + +_:x2 rdf:first "cell-2" . +_:x2 rdf:rest rdf:nil . +_:x2 rdf:rest _:x3 . + +_:x3 rdf:first "cell-3" . +_:x3 rdf:rest rdf:nil . Added: jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-15.ttl URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-15.ttl?rev=1441178&view=auto ============================================================================== --- jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-15.ttl (added) +++ jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-15.ttl Thu Jan 31 20:20:49 2013 @@ -0,0 +1,15 @@ +@prefix : <http://example/> . +@prefix ns: <http://example/ns#> . +@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . + +:x :q _:x0 . + +# bad list : not a list - cyclic. +_:x0 rdf:first "cell-0" . +_:x0 rdf:rest _:x1 . + +_:x1 rdf:first "cell-1" . +_:x1 rdf:rest _:x2 . + +_:x2 rdf:first "cell-2" . +_:x2 rdf:rest _:x0 . \ No newline at end of file Added: jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-16.ttl URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-16.ttl?rev=1441178&view=auto ============================================================================== --- jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-16.ttl (added) +++ jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-16.ttl Thu Jan 31 20:20:49 2013 @@ -0,0 +1,18 @@ +@prefix : <http://example/> . +@prefix ns: <http://example/ns#> . +@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . + +# Bad: list tail is shared + +:x :q _:x0 . + +_:x0 rdf:first "cell-0" . +_:x0 rdf:rest _:x1 . + +:x1 :q _:x1 . + +_:x1 rdf:first "cell-1" . +_:x1 rdf:rest _:x2 . + +_:x2 rdf:first "cell-2" . +_:x2 rdf:rest rdf:nil . \ No newline at end of file
