You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@jena.apache.org by GitBox <gi...@apache.org> on 2020/03/31 08:46:40 UTC

[GitHub] [jena] afs opened a new pull request #720: JENA-1875: Context for Turtle relates stream writers.

afs opened a new pull request #720: JENA-1875: Context for Turtle relates stream writers.
URL: https://github.com/apache/jena/pull/720
 
 
   Add a "context" argument to Turtle/Trig syntax stream writers, including tests.
   
   Also, more on [JENA-1761](https://issues.apache.org/jira/browse/JENA-1761)
   Adding the style switch for @base/BASE.
   
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] kinow commented on a change in pull request #720: JENA-1875: Context for Turtle related stream writers.

Posted by GitBox <gi...@apache.org>.
kinow commented on a change in pull request #720: JENA-1875: Context for Turtle related stream writers.
URL: https://github.com/apache/jena/pull/720#discussion_r401236309
 
 

 ##########
 File path: jena-arq/src/main/java/org/apache/jena/riot/writer/WriterLib.java
 ##########
 @@ -0,0 +1,51 @@
+/*
+ * 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 org.apache.jena.riot.writer;
+
+import org.apache.jena.riot.RIOT;
+import org.apache.jena.sparql.util.Context;
+
+/** Package-scoped utilities */
+/*package*/ class WriterLib {
+
+    static DirectiveStyle dftDirectiveStyle = DirectiveStyle.AT;
 
 Review comment:
   If it's not changed elsewhere, maybe it could be `final` too? Otherwise it could lead to inconsistent results if multiple thread access `directiveStyle` I think? (as it returns its value there)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] afs commented on a change in pull request #720: JENA-1875: Context for Turtle related stream writers.

Posted by GitBox <gi...@apache.org>.
afs commented on a change in pull request #720: JENA-1875: Context for Turtle related stream writers.
URL: https://github.com/apache/jena/pull/720#discussion_r401742884
 
 

 ##########
 File path: jena-arq/src/test/java/org/apache/jena/riot/writer/TestTurtleWriter.java
 ##########
 @@ -55,70 +60,110 @@ static void blankNodeLang(String testdata, RDFFormat lang) {
         Model m = ModelFactory.createDefaultModel() ;
         RDFDataMgr.read(m, r, null, RDFLanguages.NTRIPLES) ;
         Assert.assertTrue(m.size() > 0);
-        
+
         ByteArrayOutputStream output = new ByteArrayOutputStream();
         RDFDataMgr.write(output, m, lang);
-        
+
         ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
         Model m2 = ModelFactory.createDefaultModel();
         RDFDataMgr.read(m2, input, lang.getLang());
-        
+
         Assert.assertTrue(m2.size() > 0);
         Assert.assertTrue(m.isIsomorphicWith(m2));
     }
-    
-    // Tests from JENA-908 
+
+    // Tests from JENA-908
     @Test
     public void bnode_cycles_01() { blankNodeLang(cycle1, RDFFormat.TURTLE) ; }
-    
+
     @Test
     public void bnode_cycles_02() { blankNodeLang(cycle1, RDFFormat.TURTLE_BLOCKS) ; }
-    
+
     @Test
     public void bnode_cycles_03() { blankNodeLang(cycle1, RDFFormat.TURTLE_FLAT) ; }
-    
+
     @Test
     public void bnode_cycles_04() { blankNodeLang(cycle1, RDFFormat.TURTLE_PRETTY) ; }
 
     @Test
     public void bnode_cycles_05() { blankNodeLang(cycle2, RDFFormat.TURTLE) ; }
-    
+
     @Test
     public void bnode_cycles_06() { blankNodeLang(cycle2, RDFFormat.TURTLE_BLOCKS) ; }
-    
+
     @Test
     public void bnode_cycles_07() { blankNodeLang(cycle2, RDFFormat.TURTLE_FLAT) ; }
-    
+
     @Test
     public void bnode_cycles_08() { blankNodeLang(cycle2, RDFFormat.TURTLE_PRETTY) ; }
 
     @Test
     public void bnode_cycles() {
         Model m = RDFDataMgr.loadModel("testing/DAWG-Final/construct/data-ident.ttl");
         Assert.assertTrue(m.size() > 0);
-        
+
         ByteArrayOutputStream output = new ByteArrayOutputStream();
         RDFDataMgr.write(output, m, Lang.TURTLE);
-        
+
         ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
         Model m2 = ModelFactory.createDefaultModel();
         RDFDataMgr.read(m2, input, Lang.TURTLE);
         Assert.assertTrue(m2.size() > 0);
-        
+
         Assert.assertTrue(m.isIsomorphicWith(m2));
     }
-    
+
+    // @base
     @Test
-    public void test_base() {
-        InputStream r = new ByteArrayInputStream(TestTurtleWriter.basetester.getBytes()) ;
-        String b = "http://example.org/" ;
-        Model m = ModelFactory.createDefaultModel() ;
-        m.read(r, b, "TTL") ;
+    public void test_base_1() {
+        // Default base style
+        String result = modelToString(baseTestData, RDFFormat.TURTLE_FLAT, null);
+        int count1 = StringUtils.countMatches(result, "@base");
+        Assert.assertEquals(1, count1);
+        int count2 = StringUtils.countMatches(result, "BASE");
+        Assert.assertEquals(0, count2);
+    }
+
+    @Test
+    public void test_base_2() {
+        Context cxt = RIOT.getContext().copy();
+        cxt.set(RIOT.symTurtleDirectiveStyle, DirectiveStyle.AT);
+        String result = modelToString(baseTestData, RDFFormat.TURTLE_BLOCKS, null);
+        int count1 = StringUtils.countMatches(result, "@base");
+        Assert.assertEquals(1, count1);
+        int count2 = StringUtils.countMatches(result, "BASE");
+        Assert.assertEquals(0, count2);
+    }
+
+
+    // BASE
+    @Test
+    public void test_base_3() {
+        Context cxt = RIOT.getContext().copy();
+        cxt.set(RIOT.symTurtleDirectiveStyle, DirectiveStyle.SPARQL);
+        String result = modelToString(baseTestData, RDFFormat.TURTLE_FLAT, cxt);
+        int count1 = StringUtils.countMatches(result, "BASE");
+        Assert.assertEquals(1, count1);
+        int count2 = StringUtils.countMatches(result, "@base");
+        Assert.assertEquals(0, count2);
+    }
+
+    @Test
+    public void test_base_4() {
+        Context cxt = RIOT.getContext().copy();
+        cxt.set(RIOT.symTurtleDirectiveStyle, DirectiveStyle.SPARQL);
+        String result = modelToString(baseTestData, RDFFormat.TURTLE_BLOCKS, cxt);
+        int count1 = StringUtils.countMatches(result, "BASE");
+        Assert.assertEquals(1, count1);
+        int count2 = StringUtils.countMatches(result, "@base");
+        Assert.assertEquals(0, count2);
+    }
 
-        OutputStream o = new ByteArrayOutputStream() ;
-        RDFWriter.create().source(m).format(RDFFormat.TURTLE_BLOCKS).base(b).output(o) ;
-        String k = o.toString() ;
-        Assert.assertTrue(k.contains("@base")) ;
+    private String modelToString(Model model, RDFFormat format, Context context) {
+        ByteArrayOutputStream o = new ByteArrayOutputStream();
 
 Review comment:
   It's a ByteArrayOutputStream so no external resources. 
   Change made.
   
   (Hmm - now we need to handle IOException!)
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] afs commented on a change in pull request #720: JENA-1875: Context for Turtle related stream writers.

Posted by GitBox <gi...@apache.org>.
afs commented on a change in pull request #720: JENA-1875: Context for Turtle related stream writers.
URL: https://github.com/apache/jena/pull/720#discussion_r401742824
 
 

 ##########
 File path: jena-arq/src/main/java/org/apache/jena/riot/writer/DirectiveStyle.java
 ##########
 @@ -0,0 +1,33 @@
+/*
+ * 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 org.apache.jena.riot.writer;
+
+enum DirectiveStyle {
+    AT, SPARQL ;
+    public static DirectiveStyle create(String label) {
+        String s = label.toLowerCase() ;
+        switch(s) {
+            case "rdf_10": case "rdf10": case "n3": case "at":
+                return DirectiveStyle.AT ;
+            case "rdf_11": case "rdf11": case "sparql":
+                return DirectiveStyle.SPARQL ;
+        }
+        return null;
+    }
+}
 
 Review comment:
   OK - done.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] afs merged pull request #720: JENA-1875: Context for Turtle related stream writers.

Posted by GitBox <gi...@apache.org>.
afs merged pull request #720: JENA-1875: Context for Turtle related stream writers.
URL: https://github.com/apache/jena/pull/720
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] kinow commented on a change in pull request #720: JENA-1875: Context for Turtle related stream writers.

Posted by GitBox <gi...@apache.org>.
kinow commented on a change in pull request #720: JENA-1875: Context for Turtle related stream writers.
URL: https://github.com/apache/jena/pull/720#discussion_r401236678
 
 

 ##########
 File path: jena-arq/src/main/java/org/apache/jena/riot/writer/DirectiveStyle.java
 ##########
 @@ -0,0 +1,33 @@
+/*
+ * 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 org.apache.jena.riot.writer;
+
+enum DirectiveStyle {
+    AT, SPARQL ;
+    public static DirectiveStyle create(String label) {
+        String s = label.toLowerCase() ;
+        switch(s) {
+            case "rdf_10": case "rdf10": case "n3": case "at":
+                return DirectiveStyle.AT ;
+            case "rdf_11": case "rdf11": case "sparql":
+                return DirectiveStyle.SPARQL ;
+        }
+        return null;
+    }
+}
 
 Review comment:
   Missing `newline` at the end of the file? Important for git I think...

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] kinow commented on a change in pull request #720: JENA-1875: Context for Turtle related stream writers.

Posted by GitBox <gi...@apache.org>.
kinow commented on a change in pull request #720: JENA-1875: Context for Turtle related stream writers.
URL: https://github.com/apache/jena/pull/720#discussion_r401238053
 
 

 ##########
 File path: jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFOps.java
 ##########
 @@ -103,8 +107,18 @@ public static void sendGraphToStream(Graph graph, StreamRDF stream) {
         sendGraphToStream(graph, stream, prefixMap) ;
     }
     
-    /** Send the triples of graph and an explicitly given prefix mapping, to a StreamRDF */
+    /**
+     * @deprecated prefer {@link #sendGraphToStream(Graph, StreamRDF, String, PrefixMap)} with a null base URI.
 
 Review comment:
   :+1: 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] kinow commented on a change in pull request #720: JENA-1875: Context for Turtle related stream writers.

Posted by GitBox <gi...@apache.org>.
kinow commented on a change in pull request #720: JENA-1875: Context for Turtle related stream writers.
URL: https://github.com/apache/jena/pull/720#discussion_r401237836
 
 

 ##########
 File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
 ##########
 @@ -342,45 +342,51 @@ private static void writeBaseOldStyle(IndentedWriter out, String base) {
         }
     }
 
-    /** Write prefixes, using {@code PREFIX} */ 
+    /** Write prefixes */ 
     public static void writePrefixes(IndentedWriter out, PrefixMap prefixMap, boolean newStyle) {
-        if ( newStyle )
-            writePrefixesNewStyle(out, prefixMap);
-        else
-            writePrefixesOldStyle(out, prefixMap);
-    }
-    
-    /** Write prefixes, using {@code PREFIX} */ 
-    private static void writePrefixesNewStyle(IndentedWriter out, PrefixMap prefixMap) {
         if ( prefixMap != null && !prefixMap.isEmpty() ) {
             for ( Map.Entry<String, String> e : prefixMap.getMapping().entrySet() ) {
-                out.print("PREFIX ");
-                out.print(e.getKey());
-                out.print(": ");
-                out.pad(PREFIX_IRI);
-                out.print("<");
-                out.print(e.getValue());
-                out.print(">");
-                out.println();
+                if ( newStyle )
+                    writePrefixNewStyle(out, e.getKey(), e.getValue());
+                else
+                    writePrefixOldStyle(out, e.getKey(), e.getValue());
             }
         }
     }
+    
+    /** Write a prefix.
+     * Write using {@code @prefix} or {@code PREFIX}.
+     */ 
+    public static void writePrefix(IndentedWriter out, String prefix, String uri, boolean newStyle) {
+        if ( newStyle )
+            writePrefixNewStyle(out, prefix, uri);
+        else
+            writePrefixOldStyle(out, prefix, uri);
+    }
+
+    /** Write prefix, using {@code PREFIX} */ 
+    private static void writePrefixNewStyle(IndentedWriter out, String prefix, String uri) {
+        out.print("PREFIX ");
+        out.print(prefix);
+        out.print(": ");
+        out.pad(PREFIX_IRI);
+        out.print("<");
+        out.print(uri);
+        out.print(">");
+        out.println();
 
 Review comment:
   Just checking, the other one looks like Turtle with a `.` at the end. This new style doesn't need that right?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] kinow commented on a change in pull request #720: JENA-1875: Context for Turtle related stream writers.

Posted by GitBox <gi...@apache.org>.
kinow commented on a change in pull request #720: JENA-1875: Context for Turtle related stream writers.
URL: https://github.com/apache/jena/pull/720#discussion_r401236501
 
 

 ##########
 File path: jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleShell.java
 ##########
 @@ -82,21 +67,7 @@ protected TurtleShell(IndentedWriter out, PrefixMap pmap, String baseURI, NodeFo
         this.baseURI = baseURI ;
         this.nodeFmt = nodeFmt ;
         this.context = context;
-        this.prefixStyle = prefixStyle(context) ;
-    }
-
-    // Determine the prefix style (applies to BASE as well).
-    private static PrefixStyle prefixStyle(Context context) {
-        Object x = context.get(RIOT.symTurtlePrefixStyle) ;
-        if ( x instanceof String ) {
-            String s = (String)x ;
-            PrefixStyle style = PrefixStyle.create(s);
-            return style == null ? dftPrefixStyle : style;
-        }
-        if ( x instanceof PrefixStyle )
-            return (PrefixStyle)x ;
-        // Default choice; includes null in context.
-        return dftPrefixStyle;
+        this.prefixStyle = WriterLib.directiveStyle(context) ;
 
 Review comment:
   Nice :+1: 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] kinow commented on a change in pull request #720: JENA-1875: Context for Turtle related stream writers.

Posted by GitBox <gi...@apache.org>.
kinow commented on a change in pull request #720: JENA-1875: Context for Turtle related stream writers.
URL: https://github.com/apache/jena/pull/720#discussion_r401234798
 
 

 ##########
 File path: jena-arq/src/test/java/org/apache/jena/riot/writer/TestTurtleWriter.java
 ##########
 @@ -55,70 +60,110 @@ static void blankNodeLang(String testdata, RDFFormat lang) {
         Model m = ModelFactory.createDefaultModel() ;
         RDFDataMgr.read(m, r, null, RDFLanguages.NTRIPLES) ;
         Assert.assertTrue(m.size() > 0);
-        
+
         ByteArrayOutputStream output = new ByteArrayOutputStream();
         RDFDataMgr.write(output, m, lang);
-        
+
         ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
         Model m2 = ModelFactory.createDefaultModel();
         RDFDataMgr.read(m2, input, lang.getLang());
-        
+
         Assert.assertTrue(m2.size() > 0);
         Assert.assertTrue(m.isIsomorphicWith(m2));
     }
-    
-    // Tests from JENA-908 
+
+    // Tests from JENA-908
     @Test
     public void bnode_cycles_01() { blankNodeLang(cycle1, RDFFormat.TURTLE) ; }
-    
+
     @Test
     public void bnode_cycles_02() { blankNodeLang(cycle1, RDFFormat.TURTLE_BLOCKS) ; }
-    
+
     @Test
     public void bnode_cycles_03() { blankNodeLang(cycle1, RDFFormat.TURTLE_FLAT) ; }
-    
+
     @Test
     public void bnode_cycles_04() { blankNodeLang(cycle1, RDFFormat.TURTLE_PRETTY) ; }
 
     @Test
     public void bnode_cycles_05() { blankNodeLang(cycle2, RDFFormat.TURTLE) ; }
-    
+
     @Test
     public void bnode_cycles_06() { blankNodeLang(cycle2, RDFFormat.TURTLE_BLOCKS) ; }
-    
+
     @Test
     public void bnode_cycles_07() { blankNodeLang(cycle2, RDFFormat.TURTLE_FLAT) ; }
-    
+
     @Test
     public void bnode_cycles_08() { blankNodeLang(cycle2, RDFFormat.TURTLE_PRETTY) ; }
 
     @Test
     public void bnode_cycles() {
         Model m = RDFDataMgr.loadModel("testing/DAWG-Final/construct/data-ident.ttl");
         Assert.assertTrue(m.size() > 0);
-        
+
         ByteArrayOutputStream output = new ByteArrayOutputStream();
         RDFDataMgr.write(output, m, Lang.TURTLE);
-        
+
         ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
         Model m2 = ModelFactory.createDefaultModel();
         RDFDataMgr.read(m2, input, Lang.TURTLE);
         Assert.assertTrue(m2.size() > 0);
-        
+
         Assert.assertTrue(m.isIsomorphicWith(m2));
     }
-    
+
+    // @base
     @Test
-    public void test_base() {
-        InputStream r = new ByteArrayInputStream(TestTurtleWriter.basetester.getBytes()) ;
-        String b = "http://example.org/" ;
-        Model m = ModelFactory.createDefaultModel() ;
-        m.read(r, b, "TTL") ;
+    public void test_base_1() {
+        // Default base style
+        String result = modelToString(baseTestData, RDFFormat.TURTLE_FLAT, null);
+        int count1 = StringUtils.countMatches(result, "@base");
+        Assert.assertEquals(1, count1);
+        int count2 = StringUtils.countMatches(result, "BASE");
+        Assert.assertEquals(0, count2);
+    }
+
+    @Test
+    public void test_base_2() {
+        Context cxt = RIOT.getContext().copy();
+        cxt.set(RIOT.symTurtleDirectiveStyle, DirectiveStyle.AT);
+        String result = modelToString(baseTestData, RDFFormat.TURTLE_BLOCKS, null);
+        int count1 = StringUtils.countMatches(result, "@base");
+        Assert.assertEquals(1, count1);
+        int count2 = StringUtils.countMatches(result, "BASE");
+        Assert.assertEquals(0, count2);
+    }
+
+
+    // BASE
+    @Test
+    public void test_base_3() {
+        Context cxt = RIOT.getContext().copy();
+        cxt.set(RIOT.symTurtleDirectiveStyle, DirectiveStyle.SPARQL);
+        String result = modelToString(baseTestData, RDFFormat.TURTLE_FLAT, cxt);
+        int count1 = StringUtils.countMatches(result, "BASE");
+        Assert.assertEquals(1, count1);
+        int count2 = StringUtils.countMatches(result, "@base");
+        Assert.assertEquals(0, count2);
+    }
+
+    @Test
+    public void test_base_4() {
+        Context cxt = RIOT.getContext().copy();
+        cxt.set(RIOT.symTurtleDirectiveStyle, DirectiveStyle.SPARQL);
+        String result = modelToString(baseTestData, RDFFormat.TURTLE_BLOCKS, cxt);
+        int count1 = StringUtils.countMatches(result, "BASE");
+        Assert.assertEquals(1, count1);
+        int count2 = StringUtils.countMatches(result, "@base");
+        Assert.assertEquals(0, count2);
+    }
 
-        OutputStream o = new ByteArrayOutputStream() ;
-        RDFWriter.create().source(m).format(RDFFormat.TURTLE_BLOCKS).base(b).output(o) ;
-        String k = o.toString() ;
-        Assert.assertTrue(k.contains("@base")) ;
+    private String modelToString(Model model, RDFFormat format, Context context) {
+        ByteArrayOutputStream o = new ByteArrayOutputStream();
 
 Review comment:
   Should we use `try-with-resources` here to close it later? Test only so I think it may not matter much.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] afs commented on a change in pull request #720: JENA-1875: Context for Turtle related stream writers.

Posted by GitBox <gi...@apache.org>.
afs commented on a change in pull request #720: JENA-1875: Context for Turtle related stream writers.
URL: https://github.com/apache/jena/pull/720#discussion_r401742869
 
 

 ##########
 File path: jena-arq/src/main/java/org/apache/jena/riot/writer/WriterLib.java
 ##########
 @@ -0,0 +1,51 @@
+/*
+ * 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 org.apache.jena.riot.writer;
+
+import org.apache.jena.riot.RIOT;
+import org.apache.jena.sparql.util.Context;
+
+/** Package-scoped utilities */
+/*package*/ class WriterLib {
+
+    static DirectiveStyle dftDirectiveStyle = DirectiveStyle.AT;
 
 Review comment:
   Yes. Done.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org