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 2021/05/15 21:35:57 UTC
[GitHub] [jena] MBoegers opened a new pull request #1002: Jena 1262 Sorting of prefixes in Turtle serializer
MBoegers opened a new pull request #1002:
URL: https://github.com/apache/jena/pull/1002
With [Jena-1262](https://issues.apache.org/jira/browse/JENA-1262) the Turtle serialization is improved.
In this PR I've implemented the first section of the ticket, which requires the prefixes to be sorted and aligned.
Also, I've removed unused code and reformated the RiotLib.java file
The second part needs refinement, I will start a discussion within the ticket.
--
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
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org
[GitHub] [jena] MBoegers commented on a change in pull request #1002: JENA-1262: Sorting of prefixes in Turtle serializer
Posted by GitBox <gi...@apache.org>.
MBoegers commented on a change in pull request #1002:
URL: https://github.com/apache/jena/pull/1002#discussion_r633117614
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -52,160 +38,199 @@
import org.apache.jena.sparql.util.NodeFactoryExtra;
import org.apache.jena.util.iterator.ExtendedIterator;
-/** Misc RIOT code */
-public class RiotLib
-{
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.*;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+import static org.apache.jena.riot.RDFLanguages.*;
+import static org.apache.jena.riot.writer.WriterConst.PREFIX_IRI;
+
+/**
+ * Misc RIOT code
+ */
+public class RiotLib {
// ---- BlankNode skolemization as IRIs
private final static boolean skolomizedBNodes = ARQ.isTrueOrUndef(ARQ.constantBNodeLabels);
- /** "Skolemize" to a node.
+
+ /**
+ * "Skolemize" to a node.
* Returns a Node_URI.
*/
public static Node blankNodeToIri(Node node) {
- if ( node.isBlank() )
+ if (node.isBlank())
return NodeFactory.createURI(blankNodeToIriString(node));
return node;
}
- /** "Skolemize" to a string. */
+ /**
+ * "Skolemize" to a string.
+ */
public static String blankNodeToIriString(Node node) {
- if ( node.isBlank() ) {
+ if (node.isBlank()) {
String x = node.getBlankNodeLabel();
return "_:" + x;
}
- if ( node.isURI())
+ if (node.isURI())
return node.getURI();
throw new RiotException("Not a blank node or URI");
}
private final static String bNodeLabelStart = "_:";
- /** Implement {@code <_:....>} as a "Node IRI"
+
+ /**
+ * Implement {@code <_:....>} as a "Node IRI"
* that is, use the given label as the BNode internal label.
* Use with care.
* Returns a Node_URI.
*/
public static Node createIRIorBNode(String str) {
// Is it a bNode label? i.e. <_:xyz>
- if ( skolomizedBNodes && isBNodeIRI(str) ) {
+ if (skolomizedBNodes && isBNodeIRI(str)) {
String s = str.substring(bNodeLabelStart.length());
- Node n = NodeFactory.createBlankNode(s);
- return n;
+ return NodeFactory.createBlankNode(s);
}
return NodeFactory.createURI(str);
}
- /** Test whether a IRI is a ARQ-encoded blank node. */
+ /**
Review comment:
IntelliJ inserts newlines automaticly, if not configured otherwise. I'll change the rule for jena.
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -52,160 +38,199 @@
import org.apache.jena.sparql.util.NodeFactoryExtra;
import org.apache.jena.util.iterator.ExtendedIterator;
-/** Misc RIOT code */
-public class RiotLib
-{
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.*;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+import static org.apache.jena.riot.RDFLanguages.*;
+import static org.apache.jena.riot.writer.WriterConst.PREFIX_IRI;
+
+/**
+ * Misc RIOT code
+ */
+public class RiotLib {
// ---- BlankNode skolemization as IRIs
private final static boolean skolomizedBNodes = ARQ.isTrueOrUndef(ARQ.constantBNodeLabels);
- /** "Skolemize" to a node.
+
+ /**
+ * "Skolemize" to a node.
* Returns a Node_URI.
*/
public static Node blankNodeToIri(Node node) {
- if ( node.isBlank() )
+ if (node.isBlank())
return NodeFactory.createURI(blankNodeToIriString(node));
return node;
}
- /** "Skolemize" to a string. */
+ /**
+ * "Skolemize" to a string.
+ */
public static String blankNodeToIriString(Node node) {
- if ( node.isBlank() ) {
+ if (node.isBlank()) {
String x = node.getBlankNodeLabel();
return "_:" + x;
}
- if ( node.isURI())
+ if (node.isURI())
return node.getURI();
throw new RiotException("Not a blank node or URI");
}
private final static String bNodeLabelStart = "_:";
- /** Implement {@code <_:....>} as a "Node IRI"
+
+ /**
+ * Implement {@code <_:....>} as a "Node IRI"
* that is, use the given label as the BNode internal label.
* Use with care.
* Returns a Node_URI.
*/
public static Node createIRIorBNode(String str) {
// Is it a bNode label? i.e. <_:xyz>
- if ( skolomizedBNodes && isBNodeIRI(str) ) {
+ if (skolomizedBNodes && isBNodeIRI(str)) {
String s = str.substring(bNodeLabelStart.length());
- Node n = NodeFactory.createBlankNode(s);
- return n;
+ return NodeFactory.createBlankNode(s);
}
return NodeFactory.createURI(str);
}
- /** Test whether a IRI is a ARQ-encoded blank node. */
+ /**
Review comment:
IntelliJ inserts newlines automatically, if not configured otherwise. I'll change the rule for Jena.
--
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
---------------------------------------------------------------------
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 #1002: JENA-1262: Sorting of prefixes in Turtle serializer
Posted by GitBox <gi...@apache.org>.
afs commented on a change in pull request #1002:
URL: https://github.com/apache/jena/pull/1002#discussion_r633497856
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -52,160 +38,199 @@
import org.apache.jena.sparql.util.NodeFactoryExtra;
import org.apache.jena.util.iterator.ExtendedIterator;
-/** Misc RIOT code */
-public class RiotLib
-{
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.*;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+import static org.apache.jena.riot.RDFLanguages.*;
+import static org.apache.jena.riot.writer.WriterConst.PREFIX_IRI;
+
+/**
+ * Misc RIOT code
+ */
+public class RiotLib {
// ---- BlankNode skolemization as IRIs
private final static boolean skolomizedBNodes = ARQ.isTrueOrUndef(ARQ.constantBNodeLabels);
- /** "Skolemize" to a node.
+
+ /**
+ * "Skolemize" to a node.
* Returns a Node_URI.
*/
public static Node blankNodeToIri(Node node) {
- if ( node.isBlank() )
+ if (node.isBlank())
return NodeFactory.createURI(blankNodeToIriString(node));
return node;
}
- /** "Skolemize" to a string. */
+ /**
+ * "Skolemize" to a string.
+ */
public static String blankNodeToIriString(Node node) {
- if ( node.isBlank() ) {
+ if (node.isBlank()) {
String x = node.getBlankNodeLabel();
return "_:" + x;
}
- if ( node.isURI())
+ if (node.isURI())
return node.getURI();
throw new RiotException("Not a blank node or URI");
}
private final static String bNodeLabelStart = "_:";
- /** Implement {@code <_:....>} as a "Node IRI"
+
+ /**
+ * Implement {@code <_:....>} as a "Node IRI"
* that is, use the given label as the BNode internal label.
* Use with care.
* Returns a Node_URI.
*/
public static Node createIRIorBNode(String str) {
// Is it a bNode label? i.e. <_:xyz>
- if ( skolomizedBNodes && isBNodeIRI(str) ) {
Review comment:
Leave this as-is. I think it is my local settings which I had changes to include spaces at the time.
--
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
---------------------------------------------------------------------
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 #1002: JENA-1262: Sorting of prefixes in Turtle serializer
Posted by GitBox <gi...@apache.org>.
afs commented on a change in pull request #1002:
URL: https://github.com/apache/jena/pull/1002#discussion_r633500945
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -18,20 +18,6 @@
package org.apache.jena.riot.system;
-import static org.apache.jena.riot.RDFLanguages.NQUADS;
Review comment:
The code is mixture of styles from many years of evolution. We don't have hard-and-fast rules; reformatting clutters up history and Jena has retained history from most of its life, even back to into SVN times (but not CVS). So generally, it's reflect the style of the file.
--
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
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org
[GitHub] [jena] MBoegers commented on a change in pull request #1002: JENA-1262: Sorting of prefixes in Turtle serializer
Posted by GitBox <gi...@apache.org>.
MBoegers commented on a change in pull request #1002:
URL: https://github.com/apache/jena/pull/1002#discussion_r633118518
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -52,160 +38,199 @@
import org.apache.jena.sparql.util.NodeFactoryExtra;
import org.apache.jena.util.iterator.ExtendedIterator;
-/** Misc RIOT code */
-public class RiotLib
-{
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.*;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+import static org.apache.jena.riot.RDFLanguages.*;
+import static org.apache.jena.riot.writer.WriterConst.PREFIX_IRI;
+
+/**
+ * Misc RIOT code
+ */
+public class RiotLib {
// ---- BlankNode skolemization as IRIs
private final static boolean skolomizedBNodes = ARQ.isTrueOrUndef(ARQ.constantBNodeLabels);
- /** "Skolemize" to a node.
+
+ /**
+ * "Skolemize" to a node.
* Returns a Node_URI.
*/
public static Node blankNodeToIri(Node node) {
- if ( node.isBlank() )
+ if (node.isBlank())
return NodeFactory.createURI(blankNodeToIriString(node));
return node;
}
- /** "Skolemize" to a string. */
+ /**
+ * "Skolemize" to a string.
+ */
public static String blankNodeToIriString(Node node) {
- if ( node.isBlank() ) {
+ if (node.isBlank()) {
String x = node.getBlankNodeLabel();
return "_:" + x;
}
- if ( node.isURI())
+ if (node.isURI())
return node.getURI();
throw new RiotException("Not a blank node or URI");
}
private final static String bNodeLabelStart = "_:";
- /** Implement {@code <_:....>} as a "Node IRI"
+
+ /**
+ * Implement {@code <_:....>} as a "Node IRI"
* that is, use the given label as the BNode internal label.
* Use with care.
* Returns a Node_URI.
*/
public static Node createIRIorBNode(String str) {
// Is it a bNode label? i.e. <_:xyz>
- if ( skolomizedBNodes && isBNodeIRI(str) ) {
Review comment:
I've noticed that my setup reformated the blanks away and I checked the illustration from [CONTRIBUTING.md](https://github.com/apache/jena/blob/main/CONTRIBUTING.md) and saw no difference.
I'll review my project format settings to align with common formatting and add a comment to CONTRIBUTING.md.
--
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
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org
[GitHub] [jena] MBoegers commented on a change in pull request #1002: JENA-1262: Sorting of prefixes in Turtle serializer
Posted by GitBox <gi...@apache.org>.
MBoegers commented on a change in pull request #1002:
URL: https://github.com/apache/jena/pull/1002#discussion_r633116925
##########
File path: jena-arq/src/test/java/org/apache/jena/riot/system/TestRiotLib.java
##########
@@ -0,0 +1,92 @@
+/**
Review comment:
Copied it from a file next to it, license header in javadoc is not intended. Will switch to `/* .. */`
##########
File path: jena-arq/src/test/java/org/apache/jena/riot/system/TestRiotLib.java
##########
@@ -0,0 +1,92 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.system;
+
+import org.apache.jena.atlas.io.IndentedLineBuffer;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestRiotLib {
+
+ private PrefixMap prefixMap;
+
+ @Before
+ public void setupMaps() {
+ // Mappings from requirement JENA-1262
+ this.prefixMap = new PrefixMapStd();
+ this.prefixMap.add("lcc-3166-1", "http://www.omg.org/spec/LCC/Countries/ISO3166-1-CountryCodes/");
+ this.prefixMap.add("dct", "http://purl.org/dc/terms/");
+ this.prefixMap.add("owl", "http://www.w3.org/2002/07/owl#");
+ this.prefixMap.add("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
+ this.prefixMap.add("lcc-3166-2", "http://www.omg.org/spec/LCC/Countries/ISO3166-2-SubdivisionCodes/");
+ this.prefixMap.add("xsd", "http://www.w3.org/2001/XMLSchema#");
+ this.prefixMap.add("skos", "http://www.w3.org/2004/02/skos/core#");
+ this.prefixMap.add("sm", "http://www.omg.org/techprocess/ab/SpecificationMetadata/");
+ this.prefixMap.add("rdfs", "http://www.w3.org/2000/01/rdf-schema#");
+ this.prefixMap.add("lcc-lr", "http://www.omg.org/spec/LCC/Languages/LanguageRepresentation/");
+ this.prefixMap.add("lcc-cr", "http://www.omg.org/spec/LCC/Countries/CountryRepresentation/");
+ }
+
+ // Expected result transformed into new style from requirement JENA-1262
+ private static final String expectedNewStyle = "PREFIX dct: <http://purl.org/dc/terms/>\n" +
Review comment:
Nice that makes it easier.
Memo to me: I'll need to add a `'\n'` at the last line because every prefix a new line is added, even in the last line.
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -52,160 +38,199 @@
import org.apache.jena.sparql.util.NodeFactoryExtra;
import org.apache.jena.util.iterator.ExtendedIterator;
-/** Misc RIOT code */
-public class RiotLib
-{
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.*;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+import static org.apache.jena.riot.RDFLanguages.*;
+import static org.apache.jena.riot.writer.WriterConst.PREFIX_IRI;
+
+/**
+ * Misc RIOT code
+ */
+public class RiotLib {
// ---- BlankNode skolemization as IRIs
private final static boolean skolomizedBNodes = ARQ.isTrueOrUndef(ARQ.constantBNodeLabels);
- /** "Skolemize" to a node.
+
+ /**
+ * "Skolemize" to a node.
* Returns a Node_URI.
*/
public static Node blankNodeToIri(Node node) {
- if ( node.isBlank() )
+ if (node.isBlank())
return NodeFactory.createURI(blankNodeToIriString(node));
return node;
}
- /** "Skolemize" to a string. */
+ /**
+ * "Skolemize" to a string.
+ */
public static String blankNodeToIriString(Node node) {
- if ( node.isBlank() ) {
+ if (node.isBlank()) {
String x = node.getBlankNodeLabel();
return "_:" + x;
}
- if ( node.isURI())
+ if (node.isURI())
return node.getURI();
throw new RiotException("Not a blank node or URI");
}
private final static String bNodeLabelStart = "_:";
- /** Implement {@code <_:....>} as a "Node IRI"
+
+ /**
+ * Implement {@code <_:....>} as a "Node IRI"
* that is, use the given label as the BNode internal label.
* Use with care.
* Returns a Node_URI.
*/
public static Node createIRIorBNode(String str) {
// Is it a bNode label? i.e. <_:xyz>
- if ( skolomizedBNodes && isBNodeIRI(str) ) {
+ if (skolomizedBNodes && isBNodeIRI(str)) {
String s = str.substring(bNodeLabelStart.length());
- Node n = NodeFactory.createBlankNode(s);
- return n;
+ return NodeFactory.createBlankNode(s);
}
return NodeFactory.createURI(str);
}
- /** Test whether a IRI is a ARQ-encoded blank node. */
+ /**
Review comment:
IntelliJ inserts newlines automaticly, if not configured otherwise. I'll change the rule for jena.
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -52,160 +38,199 @@
import org.apache.jena.sparql.util.NodeFactoryExtra;
import org.apache.jena.util.iterator.ExtendedIterator;
-/** Misc RIOT code */
-public class RiotLib
-{
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.*;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+import static org.apache.jena.riot.RDFLanguages.*;
+import static org.apache.jena.riot.writer.WriterConst.PREFIX_IRI;
+
+/**
+ * Misc RIOT code
+ */
+public class RiotLib {
// ---- BlankNode skolemization as IRIs
private final static boolean skolomizedBNodes = ARQ.isTrueOrUndef(ARQ.constantBNodeLabels);
- /** "Skolemize" to a node.
+
+ /**
+ * "Skolemize" to a node.
* Returns a Node_URI.
*/
public static Node blankNodeToIri(Node node) {
- if ( node.isBlank() )
+ if (node.isBlank())
return NodeFactory.createURI(blankNodeToIriString(node));
return node;
}
- /** "Skolemize" to a string. */
+ /**
+ * "Skolemize" to a string.
+ */
public static String blankNodeToIriString(Node node) {
- if ( node.isBlank() ) {
+ if (node.isBlank()) {
String x = node.getBlankNodeLabel();
return "_:" + x;
}
- if ( node.isURI())
+ if (node.isURI())
return node.getURI();
throw new RiotException("Not a blank node or URI");
}
private final static String bNodeLabelStart = "_:";
- /** Implement {@code <_:....>} as a "Node IRI"
+
+ /**
+ * Implement {@code <_:....>} as a "Node IRI"
* that is, use the given label as the BNode internal label.
* Use with care.
* Returns a Node_URI.
*/
public static Node createIRIorBNode(String str) {
// Is it a bNode label? i.e. <_:xyz>
- if ( skolomizedBNodes && isBNodeIRI(str) ) {
+ if (skolomizedBNodes && isBNodeIRI(str)) {
String s = str.substring(bNodeLabelStart.length());
- Node n = NodeFactory.createBlankNode(s);
- return n;
+ return NodeFactory.createBlankNode(s);
}
return NodeFactory.createURI(str);
}
- /** Test whether a IRI is a ARQ-encoded blank node. */
+ /**
Review comment:
IntelliJ inserts newlines automatically, if not configured otherwise. I'll change the rule for Jena.
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -52,160 +38,199 @@
import org.apache.jena.sparql.util.NodeFactoryExtra;
import org.apache.jena.util.iterator.ExtendedIterator;
-/** Misc RIOT code */
-public class RiotLib
-{
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.*;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+import static org.apache.jena.riot.RDFLanguages.*;
+import static org.apache.jena.riot.writer.WriterConst.PREFIX_IRI;
+
+/**
+ * Misc RIOT code
+ */
+public class RiotLib {
// ---- BlankNode skolemization as IRIs
private final static boolean skolomizedBNodes = ARQ.isTrueOrUndef(ARQ.constantBNodeLabels);
- /** "Skolemize" to a node.
+
+ /**
+ * "Skolemize" to a node.
* Returns a Node_URI.
*/
public static Node blankNodeToIri(Node node) {
- if ( node.isBlank() )
+ if (node.isBlank())
return NodeFactory.createURI(blankNodeToIriString(node));
return node;
}
- /** "Skolemize" to a string. */
+ /**
+ * "Skolemize" to a string.
+ */
public static String blankNodeToIriString(Node node) {
- if ( node.isBlank() ) {
+ if (node.isBlank()) {
String x = node.getBlankNodeLabel();
return "_:" + x;
}
- if ( node.isURI())
+ if (node.isURI())
return node.getURI();
throw new RiotException("Not a blank node or URI");
}
private final static String bNodeLabelStart = "_:";
- /** Implement {@code <_:....>} as a "Node IRI"
+
+ /**
+ * Implement {@code <_:....>} as a "Node IRI"
* that is, use the given label as the BNode internal label.
* Use with care.
* Returns a Node_URI.
*/
public static Node createIRIorBNode(String str) {
// Is it a bNode label? i.e. <_:xyz>
- if ( skolomizedBNodes && isBNodeIRI(str) ) {
Review comment:
I've noticed that my setup reformated the blanks away and I checked the illustration from [CONTRIBUTING.md](https://github.com/apache/jena/blob/main/CONTRIBUTING.md) and saw no difference.
I'll review my project format settings to align with common formatting and add a comment to CONTRIBUTING.md.
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -52,160 +38,199 @@
import org.apache.jena.sparql.util.NodeFactoryExtra;
import org.apache.jena.util.iterator.ExtendedIterator;
-/** Misc RIOT code */
-public class RiotLib
-{
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.*;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+import static org.apache.jena.riot.RDFLanguages.*;
+import static org.apache.jena.riot.writer.WriterConst.PREFIX_IRI;
+
+/**
+ * Misc RIOT code
+ */
+public class RiotLib {
// ---- BlankNode skolemization as IRIs
private final static boolean skolomizedBNodes = ARQ.isTrueOrUndef(ARQ.constantBNodeLabels);
- /** "Skolemize" to a node.
+
+ /**
+ * "Skolemize" to a node.
* Returns a Node_URI.
*/
public static Node blankNodeToIri(Node node) {
- if ( node.isBlank() )
+ if (node.isBlank())
return NodeFactory.createURI(blankNodeToIriString(node));
return node;
}
- /** "Skolemize" to a string. */
+ /**
+ * "Skolemize" to a string.
+ */
public static String blankNodeToIriString(Node node) {
- if ( node.isBlank() ) {
+ if (node.isBlank()) {
String x = node.getBlankNodeLabel();
return "_:" + x;
}
- if ( node.isURI())
+ if (node.isURI())
return node.getURI();
throw new RiotException("Not a blank node or URI");
}
private final static String bNodeLabelStart = "_:";
- /** Implement {@code <_:....>} as a "Node IRI"
+
+ /**
+ * Implement {@code <_:....>} as a "Node IRI"
* that is, use the given label as the BNode internal label.
* Use with care.
* Returns a Node_URI.
*/
public static Node createIRIorBNode(String str) {
// Is it a bNode label? i.e. <_:xyz>
- if ( skolomizedBNodes && isBNodeIRI(str) ) {
+ if (skolomizedBNodes && isBNodeIRI(str)) {
String s = str.substring(bNodeLabelStart.length());
- Node n = NodeFactory.createBlankNode(s);
- return n;
+ return NodeFactory.createBlankNode(s);
}
return NodeFactory.createURI(str);
}
- /** Test whether a IRI is a ARQ-encoded blank node. */
+ /**
+ * Test whether a IRI is a ARQ-encoded blank node.
+ */
public static boolean isBNodeIRI(String iri) {
return iri.startsWith(bNodeLabelStart);
}
private static final String URI_PREFIX_FIXUP = "::";
// These two must be in-step.
- /** Function applied to undefined prefixes to convert to a URI string */
- public static final Function<String,String> fixupPrefixes = (x) -> URI_PREFIX_FIXUP.concat(x);
+ /**
+ * Function applied to undefined prefixes to convert to a URI string
+ */
+ public static final Function<String, String> fixupPrefixes = URI_PREFIX_FIXUP::concat;
- /** Function to test for undefined prefix URIs*/
- public static final Predicate<String> testFixupedPrefixURI = (x) -> x.startsWith(URI_PREFIX_FIXUP);
+ /**
+ * Function to test for undefined prefix URIs
+ */
+ public static final Predicate<String> testFixupedPrefixURI = (x) -> x.startsWith(URI_PREFIX_FIXUP);
- /** Test whether a IRI is a ARQ-encoded blank node. */
+ /**
+ * Test whether a IRI is a ARQ-encoded blank node.
+ */
public static boolean isPrefixIRI(String iri) {
return testFixupedPrefixURI.test(iri);
}
- /** Convert an prefix name (qname) to an IRI, for when the prerix is nor defined.
+ /**
+ * Convert an prefix name (qname) to an IRI, for when the prerix is nor defined.
+ *
* @see ARQ#fixupUndefinedPrefixes
*/
public static String fixupPrefixIRI(String prefix, String localPart) {
- return fixupPrefixIRI(prefix+":"+localPart);
+ return fixupPrefixIRI(prefix + ":" + localPart);
}
- /** Convert an prefix name (qname) to an IRI, for when the prefix is not defined.
+ /**
+ * Convert an prefix name (qname) to an IRI, for when the prefix is not defined.
+ *
* @see ARQ#fixupUndefinedPrefixes
*/
public static String fixupPrefixIRI(String prefixedName) {
return fixupPrefixes.apply(prefixedName);
}
- /** Parse a string to get one Node (the first token in the string) */
+ /**
+ * Parse a string to get one Node (the first token in the string)
+ */
public static Node parse(String string) {
return NodeFactoryExtra.parseNode(string, null);
}
- public static ParserProfile profile(Lang lang, String baseIRI, ErrorHandler handler)
- {
- if ( sameLang(NTRIPLES, lang) || sameLang(NQUADS, lang) )
- {
+ public static ParserProfile profile(Lang lang, String baseIRI, ErrorHandler handler) {
+ if (sameLang(NTRIPLES, lang) || sameLang(NQUADS, lang)) {
boolean checking = SysRIOT.isStrictMode();
// If strict mode, do checking e.g. URIs
return profile(baseIRI, false, checking, handler);
}
- if ( sameLang(RDFJSON, lang) )
+ if (sameLang(RDFJSON, lang))
return profile(baseIRI, false, true, handler);
return profile(baseIRI, true, true, handler);
}
- /** Create a parser profile for the given setup */
+ /**
+ * Create a parser profile for the given setup
+ */
private static ParserProfile profile(String baseIRI, boolean resolveIRIs, boolean checking, ErrorHandler handler) {
LabelToNode labelToNode = SyntaxLabels.createLabelToNode();
IRIx base = resolveIRIs
? IRIs.resolveIRI(baseIRI)
: IRIx.create(baseIRI);
- IRIxResolver resolver = IRIxResolver.create(base).resolve(resolveIRIs).allowRelative(false).build();
- ParserProfile profile = RiotLib.createParserProfile(factoryRDF(labelToNode), handler, resolver, checking);
- return profile;
+ IRIxResolver resolver = IRIxResolver
+ .create(base)
+ .resolve(resolveIRIs)
+ .allowRelative(false)
+ .build();
+ return RiotLib.createParserProfile(factoryRDF(labelToNode), handler, resolver, checking);
}
- /** Create a new (not influenced by anything else) {@code FactoryRDF}
+ /**
+ * Create a new (not influenced by anything else) {@code FactoryRDF}
* using the label to blank node scheme provided.
*/
public static FactoryRDF factoryRDF(LabelToNode labelMapping) {
return new FactoryRDFCaching(FactoryRDFCaching.DftNodeCacheSize, labelMapping);
}
- /** Create a new (not influenced by anything else) {@code FactoryRDF}
+ /**
+ * Create a new (not influenced by anything else) {@code FactoryRDF}
* using the default label to blank node scheme.
*/
public static FactoryRDF factoryRDF() {
return factoryRDF(SyntaxLabels.createLabelToNode());
}
- /** Create a {@link ParserProfile} with default settings. */
+ /**
+ * Create a {@link ParserProfile} with default settings.
+ */
public static ParserProfile dftProfile() {
return createParserProfile(RiotLib.factoryRDF(), ErrorHandlerFactory.errorHandlerStd, true);
}
- /** Create a {@link ParserProfile} with default settings, and a specific error handler. */
- public static ParserProfile createParserProfile(ErrorHandler errorHandler) {
- return createParserProfile(RiotLib.factoryRDF(), errorHandler, true);
- }
-
- /** Create a {@link ParserProfile} with default settings, and a specific error handler. */
+ /**
+ * Create a {@link ParserProfile} with default settings, and a specific error handler.
+ */
public static ParserProfile createParserProfile(FactoryRDF factory, ErrorHandler errorHandler, boolean checking) {
return new ParserProfileStd(factory,
- errorHandler,
- IRIxResolver.create(IRIs.getSystemBase()).build(),
- PrefixMapFactory.create(),
- RIOT.getContext().copy(),
- checking, false);
+ errorHandler,
Review comment:
In this case, I see your point. In a more general situation, I like to prevent scrolling to the right by breaking lines. But that's personal as well ;-)
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -18,20 +18,6 @@
package org.apache.jena.riot.system;
-import static org.apache.jena.riot.RDFLanguages.NQUADS;
Review comment:
Yes indeed, that would produce a lot of noise.
IDEs can import/export style rules, I feel like it would help with first PRs to have such rules delivered with the source code.
--
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
---------------------------------------------------------------------
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 #1002: JENA-1262: Sorting of prefixes in Turtle serializer
Posted by GitBox <gi...@apache.org>.
afs commented on a change in pull request #1002:
URL: https://github.com/apache/jena/pull/1002#discussion_r633073554
##########
File path: jena-arq/src/test/java/org/apache/jena/riot/system/TestRiotLib.java
##########
@@ -0,0 +1,92 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.system;
+
+import org.apache.jena.atlas.io.IndentedLineBuffer;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestRiotLib {
+
+ private PrefixMap prefixMap;
+
+ @Before
+ public void setupMaps() {
+ // Mappings from requirement JENA-1262
+ this.prefixMap = new PrefixMapStd();
+ this.prefixMap.add("lcc-3166-1", "http://www.omg.org/spec/LCC/Countries/ISO3166-1-CountryCodes/");
+ this.prefixMap.add("dct", "http://purl.org/dc/terms/");
+ this.prefixMap.add("owl", "http://www.w3.org/2002/07/owl#");
+ this.prefixMap.add("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
+ this.prefixMap.add("lcc-3166-2", "http://www.omg.org/spec/LCC/Countries/ISO3166-2-SubdivisionCodes/");
+ this.prefixMap.add("xsd", "http://www.w3.org/2001/XMLSchema#");
+ this.prefixMap.add("skos", "http://www.w3.org/2004/02/skos/core#");
+ this.prefixMap.add("sm", "http://www.omg.org/techprocess/ab/SpecificationMetadata/");
+ this.prefixMap.add("rdfs", "http://www.w3.org/2000/01/rdf-schema#");
+ this.prefixMap.add("lcc-lr", "http://www.omg.org/spec/LCC/Languages/LanguageRepresentation/");
+ this.prefixMap.add("lcc-cr", "http://www.omg.org/spec/LCC/Countries/CountryRepresentation/");
+ }
+
+ // Expected result transformed into new style from requirement JENA-1262
+ private static final String expectedNewStyle = "PREFIX dct: <http://purl.org/dc/terms/>\n" +
Review comment:
FYI: There is a utility `StrUtils.strjoinNL(String...)` to avoid all the `\n`.
##########
File path: jena-arq/src/test/java/org/apache/jena/riot/system/TestRiotLib.java
##########
@@ -0,0 +1,92 @@
+/**
Review comment:
This isn't javadoc. The source is a mix - but for new files, no need to `/**`.
It helps to have as much consistency as possible when checking many files by script.
Fixing old formatting has a cost - file history get entries which are not material changes which can make bug-hunting a bit harder.
It does not need the <p>.
The URL is indented by 4.
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -18,20 +18,6 @@
package org.apache.jena.riot.system;
-import static org.apache.jena.riot.RDFLanguages.NQUADS;
Review comment:
My IDE (Eclipse) puts static imports first. As far as I know, it is the default behaviour although I may have set it years ago. I think we'll get into trouble if we keep swapping the order.
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -52,160 +38,199 @@
import org.apache.jena.sparql.util.NodeFactoryExtra;
import org.apache.jena.util.iterator.ExtendedIterator;
-/** Misc RIOT code */
-public class RiotLib
-{
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.*;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+import static org.apache.jena.riot.RDFLanguages.*;
+import static org.apache.jena.riot.writer.WriterConst.PREFIX_IRI;
+
+/**
+ * Misc RIOT code
+ */
+public class RiotLib {
// ---- BlankNode skolemization as IRIs
private final static boolean skolomizedBNodes = ARQ.isTrueOrUndef(ARQ.constantBNodeLabels);
- /** "Skolemize" to a node.
+
+ /**
+ * "Skolemize" to a node.
* Returns a Node_URI.
*/
public static Node blankNodeToIri(Node node) {
- if ( node.isBlank() )
+ if (node.isBlank())
return NodeFactory.createURI(blankNodeToIriString(node));
return node;
}
- /** "Skolemize" to a string. */
+ /**
+ * "Skolemize" to a string.
+ */
public static String blankNodeToIriString(Node node) {
- if ( node.isBlank() ) {
+ if (node.isBlank()) {
String x = node.getBlankNodeLabel();
return "_:" + x;
}
- if ( node.isURI())
+ if (node.isURI())
return node.getURI();
throw new RiotException("Not a blank node or URI");
}
private final static String bNodeLabelStart = "_:";
- /** Implement {@code <_:....>} as a "Node IRI"
+
+ /**
+ * Implement {@code <_:....>} as a "Node IRI"
* that is, use the given label as the BNode internal label.
* Use with care.
* Returns a Node_URI.
*/
public static Node createIRIorBNode(String str) {
// Is it a bNode label? i.e. <_:xyz>
- if ( skolomizedBNodes && isBNodeIRI(str) ) {
+ if (skolomizedBNodes && isBNodeIRI(str)) {
String s = str.substring(bNodeLabelStart.length());
- Node n = NodeFactory.createBlankNode(s);
- return n;
+ return NodeFactory.createBlankNode(s);
}
return NodeFactory.createURI(str);
}
- /** Test whether a IRI is a ARQ-encoded blank node. */
+ /**
+ * Test whether a IRI is a ARQ-encoded blank node.
+ */
public static boolean isBNodeIRI(String iri) {
return iri.startsWith(bNodeLabelStart);
}
private static final String URI_PREFIX_FIXUP = "::";
// These two must be in-step.
- /** Function applied to undefined prefixes to convert to a URI string */
- public static final Function<String,String> fixupPrefixes = (x) -> URI_PREFIX_FIXUP.concat(x);
+ /**
+ * Function applied to undefined prefixes to convert to a URI string
+ */
+ public static final Function<String, String> fixupPrefixes = URI_PREFIX_FIXUP::concat;
- /** Function to test for undefined prefix URIs*/
- public static final Predicate<String> testFixupedPrefixURI = (x) -> x.startsWith(URI_PREFIX_FIXUP);
+ /**
+ * Function to test for undefined prefix URIs
+ */
+ public static final Predicate<String> testFixupedPrefixURI = (x) -> x.startsWith(URI_PREFIX_FIXUP);
- /** Test whether a IRI is a ARQ-encoded blank node. */
+ /**
+ * Test whether a IRI is a ARQ-encoded blank node.
+ */
public static boolean isPrefixIRI(String iri) {
return testFixupedPrefixURI.test(iri);
}
- /** Convert an prefix name (qname) to an IRI, for when the prerix is nor defined.
+ /**
+ * Convert an prefix name (qname) to an IRI, for when the prerix is nor defined.
+ *
* @see ARQ#fixupUndefinedPrefixes
*/
public static String fixupPrefixIRI(String prefix, String localPart) {
- return fixupPrefixIRI(prefix+":"+localPart);
+ return fixupPrefixIRI(prefix + ":" + localPart);
}
- /** Convert an prefix name (qname) to an IRI, for when the prefix is not defined.
+ /**
+ * Convert an prefix name (qname) to an IRI, for when the prefix is not defined.
+ *
* @see ARQ#fixupUndefinedPrefixes
*/
public static String fixupPrefixIRI(String prefixedName) {
return fixupPrefixes.apply(prefixedName);
}
- /** Parse a string to get one Node (the first token in the string) */
+ /**
+ * Parse a string to get one Node (the first token in the string)
+ */
public static Node parse(String string) {
return NodeFactoryExtra.parseNode(string, null);
}
- public static ParserProfile profile(Lang lang, String baseIRI, ErrorHandler handler)
- {
- if ( sameLang(NTRIPLES, lang) || sameLang(NQUADS, lang) )
- {
+ public static ParserProfile profile(Lang lang, String baseIRI, ErrorHandler handler) {
+ if (sameLang(NTRIPLES, lang) || sameLang(NQUADS, lang)) {
boolean checking = SysRIOT.isStrictMode();
// If strict mode, do checking e.g. URIs
return profile(baseIRI, false, checking, handler);
}
- if ( sameLang(RDFJSON, lang) )
+ if (sameLang(RDFJSON, lang))
return profile(baseIRI, false, true, handler);
return profile(baseIRI, true, true, handler);
}
- /** Create a parser profile for the given setup */
+ /**
+ * Create a parser profile for the given setup
+ */
private static ParserProfile profile(String baseIRI, boolean resolveIRIs, boolean checking, ErrorHandler handler) {
LabelToNode labelToNode = SyntaxLabels.createLabelToNode();
IRIx base = resolveIRIs
? IRIs.resolveIRI(baseIRI)
: IRIx.create(baseIRI);
- IRIxResolver resolver = IRIxResolver.create(base).resolve(resolveIRIs).allowRelative(false).build();
- ParserProfile profile = RiotLib.createParserProfile(factoryRDF(labelToNode), handler, resolver, checking);
- return profile;
+ IRIxResolver resolver = IRIxResolver
+ .create(base)
+ .resolve(resolveIRIs)
+ .allowRelative(false)
+ .build();
+ return RiotLib.createParserProfile(factoryRDF(labelToNode), handler, resolver, checking);
}
- /** Create a new (not influenced by anything else) {@code FactoryRDF}
+ /**
+ * Create a new (not influenced by anything else) {@code FactoryRDF}
* using the label to blank node scheme provided.
*/
public static FactoryRDF factoryRDF(LabelToNode labelMapping) {
return new FactoryRDFCaching(FactoryRDFCaching.DftNodeCacheSize, labelMapping);
}
- /** Create a new (not influenced by anything else) {@code FactoryRDF}
+ /**
+ * Create a new (not influenced by anything else) {@code FactoryRDF}
* using the default label to blank node scheme.
*/
public static FactoryRDF factoryRDF() {
return factoryRDF(SyntaxLabels.createLabelToNode());
}
- /** Create a {@link ParserProfile} with default settings. */
+ /**
+ * Create a {@link ParserProfile} with default settings.
+ */
public static ParserProfile dftProfile() {
return createParserProfile(RiotLib.factoryRDF(), ErrorHandlerFactory.errorHandlerStd, true);
}
- /** Create a {@link ParserProfile} with default settings, and a specific error handler. */
- public static ParserProfile createParserProfile(ErrorHandler errorHandler) {
- return createParserProfile(RiotLib.factoryRDF(), errorHandler, true);
- }
-
- /** Create a {@link ParserProfile} with default settings, and a specific error handler. */
+ /**
+ * Create a {@link ParserProfile} with default settings, and a specific error handler.
+ */
public static ParserProfile createParserProfile(FactoryRDF factory, ErrorHandler errorHandler, boolean checking) {
return new ParserProfileStd(factory,
- errorHandler,
- IRIxResolver.create(IRIs.getSystemBase()).build(),
- PrefixMapFactory.create(),
- RIOT.getContext().copy(),
- checking, false);
+ errorHandler,
Review comment:
Personal opinion: Leave as aligned to argument list.
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -52,160 +38,199 @@
import org.apache.jena.sparql.util.NodeFactoryExtra;
import org.apache.jena.util.iterator.ExtendedIterator;
-/** Misc RIOT code */
-public class RiotLib
-{
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.*;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+import static org.apache.jena.riot.RDFLanguages.*;
+import static org.apache.jena.riot.writer.WriterConst.PREFIX_IRI;
+
+/**
+ * Misc RIOT code
+ */
+public class RiotLib {
// ---- BlankNode skolemization as IRIs
private final static boolean skolomizedBNodes = ARQ.isTrueOrUndef(ARQ.constantBNodeLabels);
- /** "Skolemize" to a node.
+
+ /**
+ * "Skolemize" to a node.
* Returns a Node_URI.
*/
public static Node blankNodeToIri(Node node) {
- if ( node.isBlank() )
+ if (node.isBlank())
return NodeFactory.createURI(blankNodeToIriString(node));
return node;
}
- /** "Skolemize" to a string. */
+ /**
+ * "Skolemize" to a string.
+ */
public static String blankNodeToIriString(Node node) {
- if ( node.isBlank() ) {
+ if (node.isBlank()) {
String x = node.getBlankNodeLabel();
return "_:" + x;
}
- if ( node.isURI())
+ if (node.isURI())
return node.getURI();
throw new RiotException("Not a blank node or URI");
}
private final static String bNodeLabelStart = "_:";
- /** Implement {@code <_:....>} as a "Node IRI"
+
+ /**
+ * Implement {@code <_:....>} as a "Node IRI"
* that is, use the given label as the BNode internal label.
* Use with care.
* Returns a Node_URI.
*/
public static Node createIRIorBNode(String str) {
// Is it a bNode label? i.e. <_:xyz>
- if ( skolomizedBNodes && isBNodeIRI(str) ) {
Review comment:
My IDE setup puts the outer spaces in. It's quite common in the code base.
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -267,46 +293,67 @@ private static void writeBaseOldStyle(IndentedWriter out, String base) {
}
}
- /** Write prefixes */
+ /**
+ * Write prefixes
+ */
public static void writePrefixes(IndentedWriter out, PrefixMap prefixMap, boolean newStyle) {
- if ( prefixMap != null && !prefixMap.isEmpty() ) {
- for ( Map.Entry<String, String> e : prefixMap.getMapping().entrySet() ) {
- if ( newStyle )
- writePrefixNewStyle(out, e.getKey(), e.getValue());
- else
- writePrefixOldStyle(out, e.getKey(), e.getValue());
+ if (prefixMap != null && !prefixMap.isEmpty()) {
+ int maxPrefixLenght = prefixMap.getMapping().keySet().stream()
Review comment:
Typo in "length"
s/maxPrefixLenght/maxPrefixLength/g
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -52,160 +38,199 @@
import org.apache.jena.sparql.util.NodeFactoryExtra;
import org.apache.jena.util.iterator.ExtendedIterator;
-/** Misc RIOT code */
-public class RiotLib
-{
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.*;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+import static org.apache.jena.riot.RDFLanguages.*;
+import static org.apache.jena.riot.writer.WriterConst.PREFIX_IRI;
+
+/**
+ * Misc RIOT code
+ */
+public class RiotLib {
// ---- BlankNode skolemization as IRIs
private final static boolean skolomizedBNodes = ARQ.isTrueOrUndef(ARQ.constantBNodeLabels);
- /** "Skolemize" to a node.
+
+ /**
+ * "Skolemize" to a node.
* Returns a Node_URI.
*/
public static Node blankNodeToIri(Node node) {
- if ( node.isBlank() )
+ if (node.isBlank())
return NodeFactory.createURI(blankNodeToIriString(node));
return node;
}
- /** "Skolemize" to a string. */
+ /**
+ * "Skolemize" to a string.
+ */
public static String blankNodeToIriString(Node node) {
- if ( node.isBlank() ) {
+ if (node.isBlank()) {
String x = node.getBlankNodeLabel();
return "_:" + x;
}
- if ( node.isURI())
+ if (node.isURI())
return node.getURI();
throw new RiotException("Not a blank node or URI");
}
private final static String bNodeLabelStart = "_:";
- /** Implement {@code <_:....>} as a "Node IRI"
+
+ /**
+ * Implement {@code <_:....>} as a "Node IRI"
* that is, use the given label as the BNode internal label.
* Use with care.
* Returns a Node_URI.
*/
public static Node createIRIorBNode(String str) {
// Is it a bNode label? i.e. <_:xyz>
- if ( skolomizedBNodes && isBNodeIRI(str) ) {
+ if (skolomizedBNodes && isBNodeIRI(str)) {
String s = str.substring(bNodeLabelStart.length());
- Node n = NodeFactory.createBlankNode(s);
- return n;
+ return NodeFactory.createBlankNode(s);
}
return NodeFactory.createURI(str);
}
- /** Test whether a IRI is a ARQ-encoded blank node. */
+ /**
Review comment:
Personal opinion: Where the javadoc is a single line, having two extra lines is noice.
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -52,160 +38,199 @@
import org.apache.jena.sparql.util.NodeFactoryExtra;
import org.apache.jena.util.iterator.ExtendedIterator;
-/** Misc RIOT code */
-public class RiotLib
-{
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.*;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+import static org.apache.jena.riot.RDFLanguages.*;
+import static org.apache.jena.riot.writer.WriterConst.PREFIX_IRI;
+
+/**
+ * Misc RIOT code
+ */
+public class RiotLib {
// ---- BlankNode skolemization as IRIs
private final static boolean skolomizedBNodes = ARQ.isTrueOrUndef(ARQ.constantBNodeLabels);
- /** "Skolemize" to a node.
+
+ /**
+ * "Skolemize" to a node.
* Returns a Node_URI.
*/
public static Node blankNodeToIri(Node node) {
- if ( node.isBlank() )
+ if (node.isBlank())
return NodeFactory.createURI(blankNodeToIriString(node));
return node;
}
- /** "Skolemize" to a string. */
+ /**
+ * "Skolemize" to a string.
+ */
public static String blankNodeToIriString(Node node) {
- if ( node.isBlank() ) {
+ if (node.isBlank()) {
String x = node.getBlankNodeLabel();
return "_:" + x;
}
- if ( node.isURI())
+ if (node.isURI())
return node.getURI();
throw new RiotException("Not a blank node or URI");
}
private final static String bNodeLabelStart = "_:";
- /** Implement {@code <_:....>} as a "Node IRI"
+
+ /**
+ * Implement {@code <_:....>} as a "Node IRI"
* that is, use the given label as the BNode internal label.
* Use with care.
* Returns a Node_URI.
*/
public static Node createIRIorBNode(String str) {
// Is it a bNode label? i.e. <_:xyz>
- if ( skolomizedBNodes && isBNodeIRI(str) ) {
+ if (skolomizedBNodes && isBNodeIRI(str)) {
String s = str.substring(bNodeLabelStart.length());
- Node n = NodeFactory.createBlankNode(s);
- return n;
+ return NodeFactory.createBlankNode(s);
}
return NodeFactory.createURI(str);
}
- /** Test whether a IRI is a ARQ-encoded blank node. */
+ /**
+ * Test whether a IRI is a ARQ-encoded blank node.
+ */
public static boolean isBNodeIRI(String iri) {
return iri.startsWith(bNodeLabelStart);
}
private static final String URI_PREFIX_FIXUP = "::";
// These two must be in-step.
- /** Function applied to undefined prefixes to convert to a URI string */
- public static final Function<String,String> fixupPrefixes = (x) -> URI_PREFIX_FIXUP.concat(x);
+ /**
+ * Function applied to undefined prefixes to convert to a URI string
+ */
+ public static final Function<String, String> fixupPrefixes = URI_PREFIX_FIXUP::concat;
- /** Function to test for undefined prefix URIs*/
- public static final Predicate<String> testFixupedPrefixURI = (x) -> x.startsWith(URI_PREFIX_FIXUP);
+ /**
+ * Function to test for undefined prefix URIs
+ */
+ public static final Predicate<String> testFixupedPrefixURI = (x) -> x.startsWith(URI_PREFIX_FIXUP);
- /** Test whether a IRI is a ARQ-encoded blank node. */
+ /**
+ * Test whether a IRI is a ARQ-encoded blank node.
+ */
public static boolean isPrefixIRI(String iri) {
return testFixupedPrefixURI.test(iri);
}
- /** Convert an prefix name (qname) to an IRI, for when the prerix is nor defined.
+ /**
+ * Convert an prefix name (qname) to an IRI, for when the prerix is nor defined.
+ *
* @see ARQ#fixupUndefinedPrefixes
*/
public static String fixupPrefixIRI(String prefix, String localPart) {
- return fixupPrefixIRI(prefix+":"+localPart);
+ return fixupPrefixIRI(prefix + ":" + localPart);
}
- /** Convert an prefix name (qname) to an IRI, for when the prefix is not defined.
+ /**
+ * Convert an prefix name (qname) to an IRI, for when the prefix is not defined.
+ *
* @see ARQ#fixupUndefinedPrefixes
*/
public static String fixupPrefixIRI(String prefixedName) {
return fixupPrefixes.apply(prefixedName);
}
- /** Parse a string to get one Node (the first token in the string) */
+ /**
+ * Parse a string to get one Node (the first token in the string)
+ */
public static Node parse(String string) {
return NodeFactoryExtra.parseNode(string, null);
}
- public static ParserProfile profile(Lang lang, String baseIRI, ErrorHandler handler)
- {
- if ( sameLang(NTRIPLES, lang) || sameLang(NQUADS, lang) )
- {
+ public static ParserProfile profile(Lang lang, String baseIRI, ErrorHandler handler) {
+ if (sameLang(NTRIPLES, lang) || sameLang(NQUADS, lang)) {
boolean checking = SysRIOT.isStrictMode();
// If strict mode, do checking e.g. URIs
return profile(baseIRI, false, checking, handler);
}
- if ( sameLang(RDFJSON, lang) )
+ if (sameLang(RDFJSON, lang))
return profile(baseIRI, false, true, handler);
return profile(baseIRI, true, true, handler);
}
- /** Create a parser profile for the given setup */
+ /**
+ * Create a parser profile for the given setup
+ */
private static ParserProfile profile(String baseIRI, boolean resolveIRIs, boolean checking, ErrorHandler handler) {
LabelToNode labelToNode = SyntaxLabels.createLabelToNode();
IRIx base = resolveIRIs
? IRIs.resolveIRI(baseIRI)
: IRIx.create(baseIRI);
- IRIxResolver resolver = IRIxResolver.create(base).resolve(resolveIRIs).allowRelative(false).build();
- ParserProfile profile = RiotLib.createParserProfile(factoryRDF(labelToNode), handler, resolver, checking);
- return profile;
+ IRIxResolver resolver = IRIxResolver
+ .create(base)
+ .resolve(resolveIRIs)
+ .allowRelative(false)
+ .build();
+ return RiotLib.createParserProfile(factoryRDF(labelToNode), handler, resolver, checking);
}
- /** Create a new (not influenced by anything else) {@code FactoryRDF}
+ /**
+ * Create a new (not influenced by anything else) {@code FactoryRDF}
* using the label to blank node scheme provided.
*/
public static FactoryRDF factoryRDF(LabelToNode labelMapping) {
return new FactoryRDFCaching(FactoryRDFCaching.DftNodeCacheSize, labelMapping);
}
- /** Create a new (not influenced by anything else) {@code FactoryRDF}
+ /**
+ * Create a new (not influenced by anything else) {@code FactoryRDF}
* using the default label to blank node scheme.
*/
public static FactoryRDF factoryRDF() {
return factoryRDF(SyntaxLabels.createLabelToNode());
}
- /** Create a {@link ParserProfile} with default settings. */
+ /**
+ * Create a {@link ParserProfile} with default settings.
+ */
public static ParserProfile dftProfile() {
return createParserProfile(RiotLib.factoryRDF(), ErrorHandlerFactory.errorHandlerStd, true);
}
- /** Create a {@link ParserProfile} with default settings, and a specific error handler. */
- public static ParserProfile createParserProfile(ErrorHandler errorHandler) {
- return createParserProfile(RiotLib.factoryRDF(), errorHandler, true);
- }
-
- /** Create a {@link ParserProfile} with default settings, and a specific error handler. */
+ /**
+ * Create a {@link ParserProfile} with default settings, and a specific error handler.
+ */
public static ParserProfile createParserProfile(FactoryRDF factory, ErrorHandler errorHandler, boolean checking) {
return new ParserProfileStd(factory,
- errorHandler,
- IRIxResolver.create(IRIs.getSystemBase()).build(),
- PrefixMapFactory.create(),
- RIOT.getContext().copy(),
- checking, false);
+ errorHandler,
+ IRIxResolver.create(IRIs.getSystemBase()).build(),
+ PrefixMapFactory.create(),
+ RIOT.getContext().copy(),
+ checking, false);
}
- /** Create a {@link ParserProfile}. */
+ /**
+ * Create a {@link ParserProfile}.
+ */
public static ParserProfile createParserProfile(FactoryRDF factory, ErrorHandler errorHandler,
IRIxResolver resolver, boolean checking) {
return new ParserProfileStd(factory,
- errorHandler,
Review comment:
Argument list.
##########
File path: jena-arq/src/test/java/org/apache/jena/riot/system/TestRiotLib.java
##########
@@ -0,0 +1,92 @@
+/**
Review comment:
This isn't javadoc. The source is a mix - but for new files, no need to `/**`.
It helps to have as much consistency as possible when checking many files by script.
Fixing old formatting has a cost - file history get entries which are not material changes which can make bug-hunting a bit harder.
It does not need the `<p>`.
The URL is indented by 4.
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -52,160 +38,199 @@
import org.apache.jena.sparql.util.NodeFactoryExtra;
import org.apache.jena.util.iterator.ExtendedIterator;
-/** Misc RIOT code */
-public class RiotLib
-{
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.*;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+import static org.apache.jena.riot.RDFLanguages.*;
+import static org.apache.jena.riot.writer.WriterConst.PREFIX_IRI;
+
+/**
+ * Misc RIOT code
+ */
+public class RiotLib {
// ---- BlankNode skolemization as IRIs
private final static boolean skolomizedBNodes = ARQ.isTrueOrUndef(ARQ.constantBNodeLabels);
- /** "Skolemize" to a node.
+
+ /**
+ * "Skolemize" to a node.
* Returns a Node_URI.
*/
public static Node blankNodeToIri(Node node) {
- if ( node.isBlank() )
+ if (node.isBlank())
return NodeFactory.createURI(blankNodeToIriString(node));
return node;
}
- /** "Skolemize" to a string. */
+ /**
+ * "Skolemize" to a string.
+ */
public static String blankNodeToIriString(Node node) {
- if ( node.isBlank() ) {
+ if (node.isBlank()) {
String x = node.getBlankNodeLabel();
return "_:" + x;
}
- if ( node.isURI())
+ if (node.isURI())
return node.getURI();
throw new RiotException("Not a blank node or URI");
}
private final static String bNodeLabelStart = "_:";
- /** Implement {@code <_:....>} as a "Node IRI"
+
+ /**
+ * Implement {@code <_:....>} as a "Node IRI"
* that is, use the given label as the BNode internal label.
* Use with care.
* Returns a Node_URI.
*/
public static Node createIRIorBNode(String str) {
// Is it a bNode label? i.e. <_:xyz>
- if ( skolomizedBNodes && isBNodeIRI(str) ) {
Review comment:
Fine - not strong opinion.
##########
File path: jena-arq/src/test/java/org/apache/jena/riot/system/TestRiotLib.java
##########
@@ -0,0 +1,92 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.system;
+
+import org.apache.jena.atlas.io.IndentedLineBuffer;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestRiotLib {
+
+ private PrefixMap prefixMap;
+
+ @Before
+ public void setupMaps() {
+ // Mappings from requirement JENA-1262
+ this.prefixMap = new PrefixMapStd();
+ this.prefixMap.add("lcc-3166-1", "http://www.omg.org/spec/LCC/Countries/ISO3166-1-CountryCodes/");
+ this.prefixMap.add("dct", "http://purl.org/dc/terms/");
+ this.prefixMap.add("owl", "http://www.w3.org/2002/07/owl#");
+ this.prefixMap.add("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
+ this.prefixMap.add("lcc-3166-2", "http://www.omg.org/spec/LCC/Countries/ISO3166-2-SubdivisionCodes/");
+ this.prefixMap.add("xsd", "http://www.w3.org/2001/XMLSchema#");
+ this.prefixMap.add("skos", "http://www.w3.org/2004/02/skos/core#");
+ this.prefixMap.add("sm", "http://www.omg.org/techprocess/ab/SpecificationMetadata/");
+ this.prefixMap.add("rdfs", "http://www.w3.org/2000/01/rdf-schema#");
+ this.prefixMap.add("lcc-lr", "http://www.omg.org/spec/LCC/Languages/LanguageRepresentation/");
+ this.prefixMap.add("lcc-cr", "http://www.omg.org/spec/LCC/Countries/CountryRepresentation/");
+ }
+
+ // Expected result transformed into new style from requirement JENA-1262
+ private static final String expectedNewStyle = "PREFIX dct: <http://purl.org/dc/terms/>\n" +
Review comment:
If the last argument in the "String..." is "", then it ends a newline.
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -52,160 +38,199 @@
import org.apache.jena.sparql.util.NodeFactoryExtra;
import org.apache.jena.util.iterator.ExtendedIterator;
-/** Misc RIOT code */
-public class RiotLib
-{
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.*;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+import static org.apache.jena.riot.RDFLanguages.*;
+import static org.apache.jena.riot.writer.WriterConst.PREFIX_IRI;
+
+/**
+ * Misc RIOT code
+ */
+public class RiotLib {
// ---- BlankNode skolemization as IRIs
private final static boolean skolomizedBNodes = ARQ.isTrueOrUndef(ARQ.constantBNodeLabels);
- /** "Skolemize" to a node.
+
+ /**
+ * "Skolemize" to a node.
* Returns a Node_URI.
*/
public static Node blankNodeToIri(Node node) {
- if ( node.isBlank() )
+ if (node.isBlank())
return NodeFactory.createURI(blankNodeToIriString(node));
return node;
}
- /** "Skolemize" to a string. */
+ /**
+ * "Skolemize" to a string.
+ */
public static String blankNodeToIriString(Node node) {
- if ( node.isBlank() ) {
+ if (node.isBlank()) {
String x = node.getBlankNodeLabel();
return "_:" + x;
}
- if ( node.isURI())
+ if (node.isURI())
return node.getURI();
throw new RiotException("Not a blank node or URI");
}
private final static String bNodeLabelStart = "_:";
- /** Implement {@code <_:....>} as a "Node IRI"
+
+ /**
+ * Implement {@code <_:....>} as a "Node IRI"
* that is, use the given label as the BNode internal label.
* Use with care.
* Returns a Node_URI.
*/
public static Node createIRIorBNode(String str) {
// Is it a bNode label? i.e. <_:xyz>
- if ( skolomizedBNodes && isBNodeIRI(str) ) {
Review comment:
Leave this as-is. I think it is my local settings which I had changes to include spaces at the time.
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -18,20 +18,6 @@
package org.apache.jena.riot.system;
-import static org.apache.jena.riot.RDFLanguages.NQUADS;
Review comment:
The code is mixture of styles from many years of evolution. We don't have hard-and-fast rules; reformatting clutters up history and Jena has retain history from most of its life, even back to into SVN times (but not CVS). So generally, it's reflect the style of the file.
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -18,20 +18,6 @@
package org.apache.jena.riot.system;
-import static org.apache.jena.riot.RDFLanguages.NQUADS;
Review comment:
The code is mixture of styles from many years of evolution. We don't have hard-and-fast rules; reformatting clutters up history and Jena has retained history from most of its life, even back to into SVN times (but not CVS). So generally, it's reflect the style of the file.
--
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
---------------------------------------------------------------------
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 #1002: JENA-1262: Sorting of prefixes in Turtle serializer
Posted by GitBox <gi...@apache.org>.
afs merged pull request #1002:
URL: https://github.com/apache/jena/pull/1002
--
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
---------------------------------------------------------------------
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 #1002: JENA-1262: Sorting of prefixes in Turtle serializer
Posted by GitBox <gi...@apache.org>.
afs commented on a change in pull request #1002:
URL: https://github.com/apache/jena/pull/1002#discussion_r633117860
##########
File path: jena-arq/src/test/java/org/apache/jena/riot/system/TestRiotLib.java
##########
@@ -0,0 +1,92 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.system;
+
+import org.apache.jena.atlas.io.IndentedLineBuffer;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestRiotLib {
+
+ private PrefixMap prefixMap;
+
+ @Before
+ public void setupMaps() {
+ // Mappings from requirement JENA-1262
+ this.prefixMap = new PrefixMapStd();
+ this.prefixMap.add("lcc-3166-1", "http://www.omg.org/spec/LCC/Countries/ISO3166-1-CountryCodes/");
+ this.prefixMap.add("dct", "http://purl.org/dc/terms/");
+ this.prefixMap.add("owl", "http://www.w3.org/2002/07/owl#");
+ this.prefixMap.add("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
+ this.prefixMap.add("lcc-3166-2", "http://www.omg.org/spec/LCC/Countries/ISO3166-2-SubdivisionCodes/");
+ this.prefixMap.add("xsd", "http://www.w3.org/2001/XMLSchema#");
+ this.prefixMap.add("skos", "http://www.w3.org/2004/02/skos/core#");
+ this.prefixMap.add("sm", "http://www.omg.org/techprocess/ab/SpecificationMetadata/");
+ this.prefixMap.add("rdfs", "http://www.w3.org/2000/01/rdf-schema#");
+ this.prefixMap.add("lcc-lr", "http://www.omg.org/spec/LCC/Languages/LanguageRepresentation/");
+ this.prefixMap.add("lcc-cr", "http://www.omg.org/spec/LCC/Countries/CountryRepresentation/");
+ }
+
+ // Expected result transformed into new style from requirement JENA-1262
+ private static final String expectedNewStyle = "PREFIX dct: <http://purl.org/dc/terms/>\n" +
Review comment:
If the last argument in the "String..." is "", then it ends a newline.
--
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
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org
[GitHub] [jena] MBoegers commented on a change in pull request #1002: JENA-1262: Sorting of prefixes in Turtle serializer
Posted by GitBox <gi...@apache.org>.
MBoegers commented on a change in pull request #1002:
URL: https://github.com/apache/jena/pull/1002#discussion_r633116925
##########
File path: jena-arq/src/test/java/org/apache/jena/riot/system/TestRiotLib.java
##########
@@ -0,0 +1,92 @@
+/**
Review comment:
Copied it from a file next to it, license header in javadoc is not intended. Will switch to `/* .. */`
--
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
---------------------------------------------------------------------
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 #1002: JENA-1262: Sorting of prefixes in Turtle serializer
Posted by GitBox <gi...@apache.org>.
afs commented on a change in pull request #1002:
URL: https://github.com/apache/jena/pull/1002#discussion_r633073554
##########
File path: jena-arq/src/test/java/org/apache/jena/riot/system/TestRiotLib.java
##########
@@ -0,0 +1,92 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.system;
+
+import org.apache.jena.atlas.io.IndentedLineBuffer;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestRiotLib {
+
+ private PrefixMap prefixMap;
+
+ @Before
+ public void setupMaps() {
+ // Mappings from requirement JENA-1262
+ this.prefixMap = new PrefixMapStd();
+ this.prefixMap.add("lcc-3166-1", "http://www.omg.org/spec/LCC/Countries/ISO3166-1-CountryCodes/");
+ this.prefixMap.add("dct", "http://purl.org/dc/terms/");
+ this.prefixMap.add("owl", "http://www.w3.org/2002/07/owl#");
+ this.prefixMap.add("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
+ this.prefixMap.add("lcc-3166-2", "http://www.omg.org/spec/LCC/Countries/ISO3166-2-SubdivisionCodes/");
+ this.prefixMap.add("xsd", "http://www.w3.org/2001/XMLSchema#");
+ this.prefixMap.add("skos", "http://www.w3.org/2004/02/skos/core#");
+ this.prefixMap.add("sm", "http://www.omg.org/techprocess/ab/SpecificationMetadata/");
+ this.prefixMap.add("rdfs", "http://www.w3.org/2000/01/rdf-schema#");
+ this.prefixMap.add("lcc-lr", "http://www.omg.org/spec/LCC/Languages/LanguageRepresentation/");
+ this.prefixMap.add("lcc-cr", "http://www.omg.org/spec/LCC/Countries/CountryRepresentation/");
+ }
+
+ // Expected result transformed into new style from requirement JENA-1262
+ private static final String expectedNewStyle = "PREFIX dct: <http://purl.org/dc/terms/>\n" +
Review comment:
FYI: There is a utility `StrUtils.strjoinNL(String...)` to avoid all the `\n`.
##########
File path: jena-arq/src/test/java/org/apache/jena/riot/system/TestRiotLib.java
##########
@@ -0,0 +1,92 @@
+/**
Review comment:
This isn't javadoc. The source is a mix - but for new files, no need to `/**`.
It helps to have as much consistency as possible when checking many files by script.
Fixing old formatting has a cost - file history get entries which are not material changes which can make bug-hunting a bit harder.
It does not need the <p>.
The URL is indented by 4.
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -18,20 +18,6 @@
package org.apache.jena.riot.system;
-import static org.apache.jena.riot.RDFLanguages.NQUADS;
Review comment:
My IDE (Eclipse) puts static imports first. As far as I know, it is the default behaviour although I may have set it years ago. I think we'll get into trouble if we keep swapping the order.
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -52,160 +38,199 @@
import org.apache.jena.sparql.util.NodeFactoryExtra;
import org.apache.jena.util.iterator.ExtendedIterator;
-/** Misc RIOT code */
-public class RiotLib
-{
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.*;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+import static org.apache.jena.riot.RDFLanguages.*;
+import static org.apache.jena.riot.writer.WriterConst.PREFIX_IRI;
+
+/**
+ * Misc RIOT code
+ */
+public class RiotLib {
// ---- BlankNode skolemization as IRIs
private final static boolean skolomizedBNodes = ARQ.isTrueOrUndef(ARQ.constantBNodeLabels);
- /** "Skolemize" to a node.
+
+ /**
+ * "Skolemize" to a node.
* Returns a Node_URI.
*/
public static Node blankNodeToIri(Node node) {
- if ( node.isBlank() )
+ if (node.isBlank())
return NodeFactory.createURI(blankNodeToIriString(node));
return node;
}
- /** "Skolemize" to a string. */
+ /**
+ * "Skolemize" to a string.
+ */
public static String blankNodeToIriString(Node node) {
- if ( node.isBlank() ) {
+ if (node.isBlank()) {
String x = node.getBlankNodeLabel();
return "_:" + x;
}
- if ( node.isURI())
+ if (node.isURI())
return node.getURI();
throw new RiotException("Not a blank node or URI");
}
private final static String bNodeLabelStart = "_:";
- /** Implement {@code <_:....>} as a "Node IRI"
+
+ /**
+ * Implement {@code <_:....>} as a "Node IRI"
* that is, use the given label as the BNode internal label.
* Use with care.
* Returns a Node_URI.
*/
public static Node createIRIorBNode(String str) {
// Is it a bNode label? i.e. <_:xyz>
- if ( skolomizedBNodes && isBNodeIRI(str) ) {
+ if (skolomizedBNodes && isBNodeIRI(str)) {
String s = str.substring(bNodeLabelStart.length());
- Node n = NodeFactory.createBlankNode(s);
- return n;
+ return NodeFactory.createBlankNode(s);
}
return NodeFactory.createURI(str);
}
- /** Test whether a IRI is a ARQ-encoded blank node. */
+ /**
+ * Test whether a IRI is a ARQ-encoded blank node.
+ */
public static boolean isBNodeIRI(String iri) {
return iri.startsWith(bNodeLabelStart);
}
private static final String URI_PREFIX_FIXUP = "::";
// These two must be in-step.
- /** Function applied to undefined prefixes to convert to a URI string */
- public static final Function<String,String> fixupPrefixes = (x) -> URI_PREFIX_FIXUP.concat(x);
+ /**
+ * Function applied to undefined prefixes to convert to a URI string
+ */
+ public static final Function<String, String> fixupPrefixes = URI_PREFIX_FIXUP::concat;
- /** Function to test for undefined prefix URIs*/
- public static final Predicate<String> testFixupedPrefixURI = (x) -> x.startsWith(URI_PREFIX_FIXUP);
+ /**
+ * Function to test for undefined prefix URIs
+ */
+ public static final Predicate<String> testFixupedPrefixURI = (x) -> x.startsWith(URI_PREFIX_FIXUP);
- /** Test whether a IRI is a ARQ-encoded blank node. */
+ /**
+ * Test whether a IRI is a ARQ-encoded blank node.
+ */
public static boolean isPrefixIRI(String iri) {
return testFixupedPrefixURI.test(iri);
}
- /** Convert an prefix name (qname) to an IRI, for when the prerix is nor defined.
+ /**
+ * Convert an prefix name (qname) to an IRI, for when the prerix is nor defined.
+ *
* @see ARQ#fixupUndefinedPrefixes
*/
public static String fixupPrefixIRI(String prefix, String localPart) {
- return fixupPrefixIRI(prefix+":"+localPart);
+ return fixupPrefixIRI(prefix + ":" + localPart);
}
- /** Convert an prefix name (qname) to an IRI, for when the prefix is not defined.
+ /**
+ * Convert an prefix name (qname) to an IRI, for when the prefix is not defined.
+ *
* @see ARQ#fixupUndefinedPrefixes
*/
public static String fixupPrefixIRI(String prefixedName) {
return fixupPrefixes.apply(prefixedName);
}
- /** Parse a string to get one Node (the first token in the string) */
+ /**
+ * Parse a string to get one Node (the first token in the string)
+ */
public static Node parse(String string) {
return NodeFactoryExtra.parseNode(string, null);
}
- public static ParserProfile profile(Lang lang, String baseIRI, ErrorHandler handler)
- {
- if ( sameLang(NTRIPLES, lang) || sameLang(NQUADS, lang) )
- {
+ public static ParserProfile profile(Lang lang, String baseIRI, ErrorHandler handler) {
+ if (sameLang(NTRIPLES, lang) || sameLang(NQUADS, lang)) {
boolean checking = SysRIOT.isStrictMode();
// If strict mode, do checking e.g. URIs
return profile(baseIRI, false, checking, handler);
}
- if ( sameLang(RDFJSON, lang) )
+ if (sameLang(RDFJSON, lang))
return profile(baseIRI, false, true, handler);
return profile(baseIRI, true, true, handler);
}
- /** Create a parser profile for the given setup */
+ /**
+ * Create a parser profile for the given setup
+ */
private static ParserProfile profile(String baseIRI, boolean resolveIRIs, boolean checking, ErrorHandler handler) {
LabelToNode labelToNode = SyntaxLabels.createLabelToNode();
IRIx base = resolveIRIs
? IRIs.resolveIRI(baseIRI)
: IRIx.create(baseIRI);
- IRIxResolver resolver = IRIxResolver.create(base).resolve(resolveIRIs).allowRelative(false).build();
- ParserProfile profile = RiotLib.createParserProfile(factoryRDF(labelToNode), handler, resolver, checking);
- return profile;
+ IRIxResolver resolver = IRIxResolver
+ .create(base)
+ .resolve(resolveIRIs)
+ .allowRelative(false)
+ .build();
+ return RiotLib.createParserProfile(factoryRDF(labelToNode), handler, resolver, checking);
}
- /** Create a new (not influenced by anything else) {@code FactoryRDF}
+ /**
+ * Create a new (not influenced by anything else) {@code FactoryRDF}
* using the label to blank node scheme provided.
*/
public static FactoryRDF factoryRDF(LabelToNode labelMapping) {
return new FactoryRDFCaching(FactoryRDFCaching.DftNodeCacheSize, labelMapping);
}
- /** Create a new (not influenced by anything else) {@code FactoryRDF}
+ /**
+ * Create a new (not influenced by anything else) {@code FactoryRDF}
* using the default label to blank node scheme.
*/
public static FactoryRDF factoryRDF() {
return factoryRDF(SyntaxLabels.createLabelToNode());
}
- /** Create a {@link ParserProfile} with default settings. */
+ /**
+ * Create a {@link ParserProfile} with default settings.
+ */
public static ParserProfile dftProfile() {
return createParserProfile(RiotLib.factoryRDF(), ErrorHandlerFactory.errorHandlerStd, true);
}
- /** Create a {@link ParserProfile} with default settings, and a specific error handler. */
- public static ParserProfile createParserProfile(ErrorHandler errorHandler) {
- return createParserProfile(RiotLib.factoryRDF(), errorHandler, true);
- }
-
- /** Create a {@link ParserProfile} with default settings, and a specific error handler. */
+ /**
+ * Create a {@link ParserProfile} with default settings, and a specific error handler.
+ */
public static ParserProfile createParserProfile(FactoryRDF factory, ErrorHandler errorHandler, boolean checking) {
return new ParserProfileStd(factory,
- errorHandler,
- IRIxResolver.create(IRIs.getSystemBase()).build(),
- PrefixMapFactory.create(),
- RIOT.getContext().copy(),
- checking, false);
+ errorHandler,
Review comment:
Personal opinion: Leave as aligned to argument list.
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -52,160 +38,199 @@
import org.apache.jena.sparql.util.NodeFactoryExtra;
import org.apache.jena.util.iterator.ExtendedIterator;
-/** Misc RIOT code */
-public class RiotLib
-{
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.*;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+import static org.apache.jena.riot.RDFLanguages.*;
+import static org.apache.jena.riot.writer.WriterConst.PREFIX_IRI;
+
+/**
+ * Misc RIOT code
+ */
+public class RiotLib {
// ---- BlankNode skolemization as IRIs
private final static boolean skolomizedBNodes = ARQ.isTrueOrUndef(ARQ.constantBNodeLabels);
- /** "Skolemize" to a node.
+
+ /**
+ * "Skolemize" to a node.
* Returns a Node_URI.
*/
public static Node blankNodeToIri(Node node) {
- if ( node.isBlank() )
+ if (node.isBlank())
return NodeFactory.createURI(blankNodeToIriString(node));
return node;
}
- /** "Skolemize" to a string. */
+ /**
+ * "Skolemize" to a string.
+ */
public static String blankNodeToIriString(Node node) {
- if ( node.isBlank() ) {
+ if (node.isBlank()) {
String x = node.getBlankNodeLabel();
return "_:" + x;
}
- if ( node.isURI())
+ if (node.isURI())
return node.getURI();
throw new RiotException("Not a blank node or URI");
}
private final static String bNodeLabelStart = "_:";
- /** Implement {@code <_:....>} as a "Node IRI"
+
+ /**
+ * Implement {@code <_:....>} as a "Node IRI"
* that is, use the given label as the BNode internal label.
* Use with care.
* Returns a Node_URI.
*/
public static Node createIRIorBNode(String str) {
// Is it a bNode label? i.e. <_:xyz>
- if ( skolomizedBNodes && isBNodeIRI(str) ) {
Review comment:
My IDE setup puts the outer spaces in. It's quite common in the code base.
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -267,46 +293,67 @@ private static void writeBaseOldStyle(IndentedWriter out, String base) {
}
}
- /** Write prefixes */
+ /**
+ * Write prefixes
+ */
public static void writePrefixes(IndentedWriter out, PrefixMap prefixMap, boolean newStyle) {
- if ( prefixMap != null && !prefixMap.isEmpty() ) {
- for ( Map.Entry<String, String> e : prefixMap.getMapping().entrySet() ) {
- if ( newStyle )
- writePrefixNewStyle(out, e.getKey(), e.getValue());
- else
- writePrefixOldStyle(out, e.getKey(), e.getValue());
+ if (prefixMap != null && !prefixMap.isEmpty()) {
+ int maxPrefixLenght = prefixMap.getMapping().keySet().stream()
Review comment:
Typo in "length"
s/maxPrefixLenght/maxPrefixLength/g
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -52,160 +38,199 @@
import org.apache.jena.sparql.util.NodeFactoryExtra;
import org.apache.jena.util.iterator.ExtendedIterator;
-/** Misc RIOT code */
-public class RiotLib
-{
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.*;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+import static org.apache.jena.riot.RDFLanguages.*;
+import static org.apache.jena.riot.writer.WriterConst.PREFIX_IRI;
+
+/**
+ * Misc RIOT code
+ */
+public class RiotLib {
// ---- BlankNode skolemization as IRIs
private final static boolean skolomizedBNodes = ARQ.isTrueOrUndef(ARQ.constantBNodeLabels);
- /** "Skolemize" to a node.
+
+ /**
+ * "Skolemize" to a node.
* Returns a Node_URI.
*/
public static Node blankNodeToIri(Node node) {
- if ( node.isBlank() )
+ if (node.isBlank())
return NodeFactory.createURI(blankNodeToIriString(node));
return node;
}
- /** "Skolemize" to a string. */
+ /**
+ * "Skolemize" to a string.
+ */
public static String blankNodeToIriString(Node node) {
- if ( node.isBlank() ) {
+ if (node.isBlank()) {
String x = node.getBlankNodeLabel();
return "_:" + x;
}
- if ( node.isURI())
+ if (node.isURI())
return node.getURI();
throw new RiotException("Not a blank node or URI");
}
private final static String bNodeLabelStart = "_:";
- /** Implement {@code <_:....>} as a "Node IRI"
+
+ /**
+ * Implement {@code <_:....>} as a "Node IRI"
* that is, use the given label as the BNode internal label.
* Use with care.
* Returns a Node_URI.
*/
public static Node createIRIorBNode(String str) {
// Is it a bNode label? i.e. <_:xyz>
- if ( skolomizedBNodes && isBNodeIRI(str) ) {
+ if (skolomizedBNodes && isBNodeIRI(str)) {
String s = str.substring(bNodeLabelStart.length());
- Node n = NodeFactory.createBlankNode(s);
- return n;
+ return NodeFactory.createBlankNode(s);
}
return NodeFactory.createURI(str);
}
- /** Test whether a IRI is a ARQ-encoded blank node. */
+ /**
Review comment:
Personal opinion: Where the javadoc is a single line, having two extra lines is noice.
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -52,160 +38,199 @@
import org.apache.jena.sparql.util.NodeFactoryExtra;
import org.apache.jena.util.iterator.ExtendedIterator;
-/** Misc RIOT code */
-public class RiotLib
-{
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.*;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+import static org.apache.jena.riot.RDFLanguages.*;
+import static org.apache.jena.riot.writer.WriterConst.PREFIX_IRI;
+
+/**
+ * Misc RIOT code
+ */
+public class RiotLib {
// ---- BlankNode skolemization as IRIs
private final static boolean skolomizedBNodes = ARQ.isTrueOrUndef(ARQ.constantBNodeLabels);
- /** "Skolemize" to a node.
+
+ /**
+ * "Skolemize" to a node.
* Returns a Node_URI.
*/
public static Node blankNodeToIri(Node node) {
- if ( node.isBlank() )
+ if (node.isBlank())
return NodeFactory.createURI(blankNodeToIriString(node));
return node;
}
- /** "Skolemize" to a string. */
+ /**
+ * "Skolemize" to a string.
+ */
public static String blankNodeToIriString(Node node) {
- if ( node.isBlank() ) {
+ if (node.isBlank()) {
String x = node.getBlankNodeLabel();
return "_:" + x;
}
- if ( node.isURI())
+ if (node.isURI())
return node.getURI();
throw new RiotException("Not a blank node or URI");
}
private final static String bNodeLabelStart = "_:";
- /** Implement {@code <_:....>} as a "Node IRI"
+
+ /**
+ * Implement {@code <_:....>} as a "Node IRI"
* that is, use the given label as the BNode internal label.
* Use with care.
* Returns a Node_URI.
*/
public static Node createIRIorBNode(String str) {
// Is it a bNode label? i.e. <_:xyz>
- if ( skolomizedBNodes && isBNodeIRI(str) ) {
+ if (skolomizedBNodes && isBNodeIRI(str)) {
String s = str.substring(bNodeLabelStart.length());
- Node n = NodeFactory.createBlankNode(s);
- return n;
+ return NodeFactory.createBlankNode(s);
}
return NodeFactory.createURI(str);
}
- /** Test whether a IRI is a ARQ-encoded blank node. */
+ /**
+ * Test whether a IRI is a ARQ-encoded blank node.
+ */
public static boolean isBNodeIRI(String iri) {
return iri.startsWith(bNodeLabelStart);
}
private static final String URI_PREFIX_FIXUP = "::";
// These two must be in-step.
- /** Function applied to undefined prefixes to convert to a URI string */
- public static final Function<String,String> fixupPrefixes = (x) -> URI_PREFIX_FIXUP.concat(x);
+ /**
+ * Function applied to undefined prefixes to convert to a URI string
+ */
+ public static final Function<String, String> fixupPrefixes = URI_PREFIX_FIXUP::concat;
- /** Function to test for undefined prefix URIs*/
- public static final Predicate<String> testFixupedPrefixURI = (x) -> x.startsWith(URI_PREFIX_FIXUP);
+ /**
+ * Function to test for undefined prefix URIs
+ */
+ public static final Predicate<String> testFixupedPrefixURI = (x) -> x.startsWith(URI_PREFIX_FIXUP);
- /** Test whether a IRI is a ARQ-encoded blank node. */
+ /**
+ * Test whether a IRI is a ARQ-encoded blank node.
+ */
public static boolean isPrefixIRI(String iri) {
return testFixupedPrefixURI.test(iri);
}
- /** Convert an prefix name (qname) to an IRI, for when the prerix is nor defined.
+ /**
+ * Convert an prefix name (qname) to an IRI, for when the prerix is nor defined.
+ *
* @see ARQ#fixupUndefinedPrefixes
*/
public static String fixupPrefixIRI(String prefix, String localPart) {
- return fixupPrefixIRI(prefix+":"+localPart);
+ return fixupPrefixIRI(prefix + ":" + localPart);
}
- /** Convert an prefix name (qname) to an IRI, for when the prefix is not defined.
+ /**
+ * Convert an prefix name (qname) to an IRI, for when the prefix is not defined.
+ *
* @see ARQ#fixupUndefinedPrefixes
*/
public static String fixupPrefixIRI(String prefixedName) {
return fixupPrefixes.apply(prefixedName);
}
- /** Parse a string to get one Node (the first token in the string) */
+ /**
+ * Parse a string to get one Node (the first token in the string)
+ */
public static Node parse(String string) {
return NodeFactoryExtra.parseNode(string, null);
}
- public static ParserProfile profile(Lang lang, String baseIRI, ErrorHandler handler)
- {
- if ( sameLang(NTRIPLES, lang) || sameLang(NQUADS, lang) )
- {
+ public static ParserProfile profile(Lang lang, String baseIRI, ErrorHandler handler) {
+ if (sameLang(NTRIPLES, lang) || sameLang(NQUADS, lang)) {
boolean checking = SysRIOT.isStrictMode();
// If strict mode, do checking e.g. URIs
return profile(baseIRI, false, checking, handler);
}
- if ( sameLang(RDFJSON, lang) )
+ if (sameLang(RDFJSON, lang))
return profile(baseIRI, false, true, handler);
return profile(baseIRI, true, true, handler);
}
- /** Create a parser profile for the given setup */
+ /**
+ * Create a parser profile for the given setup
+ */
private static ParserProfile profile(String baseIRI, boolean resolveIRIs, boolean checking, ErrorHandler handler) {
LabelToNode labelToNode = SyntaxLabels.createLabelToNode();
IRIx base = resolveIRIs
? IRIs.resolveIRI(baseIRI)
: IRIx.create(baseIRI);
- IRIxResolver resolver = IRIxResolver.create(base).resolve(resolveIRIs).allowRelative(false).build();
- ParserProfile profile = RiotLib.createParserProfile(factoryRDF(labelToNode), handler, resolver, checking);
- return profile;
+ IRIxResolver resolver = IRIxResolver
+ .create(base)
+ .resolve(resolveIRIs)
+ .allowRelative(false)
+ .build();
+ return RiotLib.createParserProfile(factoryRDF(labelToNode), handler, resolver, checking);
}
- /** Create a new (not influenced by anything else) {@code FactoryRDF}
+ /**
+ * Create a new (not influenced by anything else) {@code FactoryRDF}
* using the label to blank node scheme provided.
*/
public static FactoryRDF factoryRDF(LabelToNode labelMapping) {
return new FactoryRDFCaching(FactoryRDFCaching.DftNodeCacheSize, labelMapping);
}
- /** Create a new (not influenced by anything else) {@code FactoryRDF}
+ /**
+ * Create a new (not influenced by anything else) {@code FactoryRDF}
* using the default label to blank node scheme.
*/
public static FactoryRDF factoryRDF() {
return factoryRDF(SyntaxLabels.createLabelToNode());
}
- /** Create a {@link ParserProfile} with default settings. */
+ /**
+ * Create a {@link ParserProfile} with default settings.
+ */
public static ParserProfile dftProfile() {
return createParserProfile(RiotLib.factoryRDF(), ErrorHandlerFactory.errorHandlerStd, true);
}
- /** Create a {@link ParserProfile} with default settings, and a specific error handler. */
- public static ParserProfile createParserProfile(ErrorHandler errorHandler) {
- return createParserProfile(RiotLib.factoryRDF(), errorHandler, true);
- }
-
- /** Create a {@link ParserProfile} with default settings, and a specific error handler. */
+ /**
+ * Create a {@link ParserProfile} with default settings, and a specific error handler.
+ */
public static ParserProfile createParserProfile(FactoryRDF factory, ErrorHandler errorHandler, boolean checking) {
return new ParserProfileStd(factory,
- errorHandler,
- IRIxResolver.create(IRIs.getSystemBase()).build(),
- PrefixMapFactory.create(),
- RIOT.getContext().copy(),
- checking, false);
+ errorHandler,
+ IRIxResolver.create(IRIs.getSystemBase()).build(),
+ PrefixMapFactory.create(),
+ RIOT.getContext().copy(),
+ checking, false);
}
- /** Create a {@link ParserProfile}. */
+ /**
+ * Create a {@link ParserProfile}.
+ */
public static ParserProfile createParserProfile(FactoryRDF factory, ErrorHandler errorHandler,
IRIxResolver resolver, boolean checking) {
return new ParserProfileStd(factory,
- errorHandler,
Review comment:
Argument list.
--
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
---------------------------------------------------------------------
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 #1002: JENA-1262: Sorting of prefixes in Turtle serializer
Posted by GitBox <gi...@apache.org>.
afs commented on a change in pull request #1002:
URL: https://github.com/apache/jena/pull/1002#discussion_r633117762
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -52,160 +38,199 @@
import org.apache.jena.sparql.util.NodeFactoryExtra;
import org.apache.jena.util.iterator.ExtendedIterator;
-/** Misc RIOT code */
-public class RiotLib
-{
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.*;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+import static org.apache.jena.riot.RDFLanguages.*;
+import static org.apache.jena.riot.writer.WriterConst.PREFIX_IRI;
+
+/**
+ * Misc RIOT code
+ */
+public class RiotLib {
// ---- BlankNode skolemization as IRIs
private final static boolean skolomizedBNodes = ARQ.isTrueOrUndef(ARQ.constantBNodeLabels);
- /** "Skolemize" to a node.
+
+ /**
+ * "Skolemize" to a node.
* Returns a Node_URI.
*/
public static Node blankNodeToIri(Node node) {
- if ( node.isBlank() )
+ if (node.isBlank())
return NodeFactory.createURI(blankNodeToIriString(node));
return node;
}
- /** "Skolemize" to a string. */
+ /**
+ * "Skolemize" to a string.
+ */
public static String blankNodeToIriString(Node node) {
- if ( node.isBlank() ) {
+ if (node.isBlank()) {
String x = node.getBlankNodeLabel();
return "_:" + x;
}
- if ( node.isURI())
+ if (node.isURI())
return node.getURI();
throw new RiotException("Not a blank node or URI");
}
private final static String bNodeLabelStart = "_:";
- /** Implement {@code <_:....>} as a "Node IRI"
+
+ /**
+ * Implement {@code <_:....>} as a "Node IRI"
* that is, use the given label as the BNode internal label.
* Use with care.
* Returns a Node_URI.
*/
public static Node createIRIorBNode(String str) {
// Is it a bNode label? i.e. <_:xyz>
- if ( skolomizedBNodes && isBNodeIRI(str) ) {
Review comment:
Fine - not strong opinion.
--
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
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org
[GitHub] [jena] MBoegers commented on a change in pull request #1002: JENA-1262: Sorting of prefixes in Turtle serializer
Posted by GitBox <gi...@apache.org>.
MBoegers commented on a change in pull request #1002:
URL: https://github.com/apache/jena/pull/1002#discussion_r633118818
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -52,160 +38,199 @@
import org.apache.jena.sparql.util.NodeFactoryExtra;
import org.apache.jena.util.iterator.ExtendedIterator;
-/** Misc RIOT code */
-public class RiotLib
-{
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.*;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+import static org.apache.jena.riot.RDFLanguages.*;
+import static org.apache.jena.riot.writer.WriterConst.PREFIX_IRI;
+
+/**
+ * Misc RIOT code
+ */
+public class RiotLib {
// ---- BlankNode skolemization as IRIs
private final static boolean skolomizedBNodes = ARQ.isTrueOrUndef(ARQ.constantBNodeLabels);
- /** "Skolemize" to a node.
+
+ /**
+ * "Skolemize" to a node.
* Returns a Node_URI.
*/
public static Node blankNodeToIri(Node node) {
- if ( node.isBlank() )
+ if (node.isBlank())
return NodeFactory.createURI(blankNodeToIriString(node));
return node;
}
- /** "Skolemize" to a string. */
+ /**
+ * "Skolemize" to a string.
+ */
public static String blankNodeToIriString(Node node) {
- if ( node.isBlank() ) {
+ if (node.isBlank()) {
String x = node.getBlankNodeLabel();
return "_:" + x;
}
- if ( node.isURI())
+ if (node.isURI())
return node.getURI();
throw new RiotException("Not a blank node or URI");
}
private final static String bNodeLabelStart = "_:";
- /** Implement {@code <_:....>} as a "Node IRI"
+
+ /**
+ * Implement {@code <_:....>} as a "Node IRI"
* that is, use the given label as the BNode internal label.
* Use with care.
* Returns a Node_URI.
*/
public static Node createIRIorBNode(String str) {
// Is it a bNode label? i.e. <_:xyz>
- if ( skolomizedBNodes && isBNodeIRI(str) ) {
+ if (skolomizedBNodes && isBNodeIRI(str)) {
String s = str.substring(bNodeLabelStart.length());
- Node n = NodeFactory.createBlankNode(s);
- return n;
+ return NodeFactory.createBlankNode(s);
}
return NodeFactory.createURI(str);
}
- /** Test whether a IRI is a ARQ-encoded blank node. */
+ /**
+ * Test whether a IRI is a ARQ-encoded blank node.
+ */
public static boolean isBNodeIRI(String iri) {
return iri.startsWith(bNodeLabelStart);
}
private static final String URI_PREFIX_FIXUP = "::";
// These two must be in-step.
- /** Function applied to undefined prefixes to convert to a URI string */
- public static final Function<String,String> fixupPrefixes = (x) -> URI_PREFIX_FIXUP.concat(x);
+ /**
+ * Function applied to undefined prefixes to convert to a URI string
+ */
+ public static final Function<String, String> fixupPrefixes = URI_PREFIX_FIXUP::concat;
- /** Function to test for undefined prefix URIs*/
- public static final Predicate<String> testFixupedPrefixURI = (x) -> x.startsWith(URI_PREFIX_FIXUP);
+ /**
+ * Function to test for undefined prefix URIs
+ */
+ public static final Predicate<String> testFixupedPrefixURI = (x) -> x.startsWith(URI_PREFIX_FIXUP);
- /** Test whether a IRI is a ARQ-encoded blank node. */
+ /**
+ * Test whether a IRI is a ARQ-encoded blank node.
+ */
public static boolean isPrefixIRI(String iri) {
return testFixupedPrefixURI.test(iri);
}
- /** Convert an prefix name (qname) to an IRI, for when the prerix is nor defined.
+ /**
+ * Convert an prefix name (qname) to an IRI, for when the prerix is nor defined.
+ *
* @see ARQ#fixupUndefinedPrefixes
*/
public static String fixupPrefixIRI(String prefix, String localPart) {
- return fixupPrefixIRI(prefix+":"+localPart);
+ return fixupPrefixIRI(prefix + ":" + localPart);
}
- /** Convert an prefix name (qname) to an IRI, for when the prefix is not defined.
+ /**
+ * Convert an prefix name (qname) to an IRI, for when the prefix is not defined.
+ *
* @see ARQ#fixupUndefinedPrefixes
*/
public static String fixupPrefixIRI(String prefixedName) {
return fixupPrefixes.apply(prefixedName);
}
- /** Parse a string to get one Node (the first token in the string) */
+ /**
+ * Parse a string to get one Node (the first token in the string)
+ */
public static Node parse(String string) {
return NodeFactoryExtra.parseNode(string, null);
}
- public static ParserProfile profile(Lang lang, String baseIRI, ErrorHandler handler)
- {
- if ( sameLang(NTRIPLES, lang) || sameLang(NQUADS, lang) )
- {
+ public static ParserProfile profile(Lang lang, String baseIRI, ErrorHandler handler) {
+ if (sameLang(NTRIPLES, lang) || sameLang(NQUADS, lang)) {
boolean checking = SysRIOT.isStrictMode();
// If strict mode, do checking e.g. URIs
return profile(baseIRI, false, checking, handler);
}
- if ( sameLang(RDFJSON, lang) )
+ if (sameLang(RDFJSON, lang))
return profile(baseIRI, false, true, handler);
return profile(baseIRI, true, true, handler);
}
- /** Create a parser profile for the given setup */
+ /**
+ * Create a parser profile for the given setup
+ */
private static ParserProfile profile(String baseIRI, boolean resolveIRIs, boolean checking, ErrorHandler handler) {
LabelToNode labelToNode = SyntaxLabels.createLabelToNode();
IRIx base = resolveIRIs
? IRIs.resolveIRI(baseIRI)
: IRIx.create(baseIRI);
- IRIxResolver resolver = IRIxResolver.create(base).resolve(resolveIRIs).allowRelative(false).build();
- ParserProfile profile = RiotLib.createParserProfile(factoryRDF(labelToNode), handler, resolver, checking);
- return profile;
+ IRIxResolver resolver = IRIxResolver
+ .create(base)
+ .resolve(resolveIRIs)
+ .allowRelative(false)
+ .build();
+ return RiotLib.createParserProfile(factoryRDF(labelToNode), handler, resolver, checking);
}
- /** Create a new (not influenced by anything else) {@code FactoryRDF}
+ /**
+ * Create a new (not influenced by anything else) {@code FactoryRDF}
* using the label to blank node scheme provided.
*/
public static FactoryRDF factoryRDF(LabelToNode labelMapping) {
return new FactoryRDFCaching(FactoryRDFCaching.DftNodeCacheSize, labelMapping);
}
- /** Create a new (not influenced by anything else) {@code FactoryRDF}
+ /**
+ * Create a new (not influenced by anything else) {@code FactoryRDF}
* using the default label to blank node scheme.
*/
public static FactoryRDF factoryRDF() {
return factoryRDF(SyntaxLabels.createLabelToNode());
}
- /** Create a {@link ParserProfile} with default settings. */
+ /**
+ * Create a {@link ParserProfile} with default settings.
+ */
public static ParserProfile dftProfile() {
return createParserProfile(RiotLib.factoryRDF(), ErrorHandlerFactory.errorHandlerStd, true);
}
- /** Create a {@link ParserProfile} with default settings, and a specific error handler. */
- public static ParserProfile createParserProfile(ErrorHandler errorHandler) {
- return createParserProfile(RiotLib.factoryRDF(), errorHandler, true);
- }
-
- /** Create a {@link ParserProfile} with default settings, and a specific error handler. */
+ /**
+ * Create a {@link ParserProfile} with default settings, and a specific error handler.
+ */
public static ParserProfile createParserProfile(FactoryRDF factory, ErrorHandler errorHandler, boolean checking) {
return new ParserProfileStd(factory,
- errorHandler,
- IRIxResolver.create(IRIs.getSystemBase()).build(),
- PrefixMapFactory.create(),
- RIOT.getContext().copy(),
- checking, false);
+ errorHandler,
Review comment:
In this case, I see your point. In a more general situation, I like to prevent scrolling to the right by breaking lines. But that's personal as well ;-)
--
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
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org
[GitHub] [jena] MBoegers commented on a change in pull request #1002: JENA-1262: Sorting of prefixes in Turtle serializer
Posted by GitBox <gi...@apache.org>.
MBoegers commented on a change in pull request #1002:
URL: https://github.com/apache/jena/pull/1002#discussion_r633119830
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -18,20 +18,6 @@
package org.apache.jena.riot.system;
-import static org.apache.jena.riot.RDFLanguages.NQUADS;
Review comment:
Yes indeed, that would produce a lot of noise.
IDEs can import/export style rules, I feel like it would help with first PRs to have such rules delivered with the source code.
--
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
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org
[GitHub] [jena] MBoegers commented on a change in pull request #1002: JENA-1262: Sorting of prefixes in Turtle serializer
Posted by GitBox <gi...@apache.org>.
MBoegers commented on a change in pull request #1002:
URL: https://github.com/apache/jena/pull/1002#discussion_r633117386
##########
File path: jena-arq/src/test/java/org/apache/jena/riot/system/TestRiotLib.java
##########
@@ -0,0 +1,92 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.system;
+
+import org.apache.jena.atlas.io.IndentedLineBuffer;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestRiotLib {
+
+ private PrefixMap prefixMap;
+
+ @Before
+ public void setupMaps() {
+ // Mappings from requirement JENA-1262
+ this.prefixMap = new PrefixMapStd();
+ this.prefixMap.add("lcc-3166-1", "http://www.omg.org/spec/LCC/Countries/ISO3166-1-CountryCodes/");
+ this.prefixMap.add("dct", "http://purl.org/dc/terms/");
+ this.prefixMap.add("owl", "http://www.w3.org/2002/07/owl#");
+ this.prefixMap.add("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
+ this.prefixMap.add("lcc-3166-2", "http://www.omg.org/spec/LCC/Countries/ISO3166-2-SubdivisionCodes/");
+ this.prefixMap.add("xsd", "http://www.w3.org/2001/XMLSchema#");
+ this.prefixMap.add("skos", "http://www.w3.org/2004/02/skos/core#");
+ this.prefixMap.add("sm", "http://www.omg.org/techprocess/ab/SpecificationMetadata/");
+ this.prefixMap.add("rdfs", "http://www.w3.org/2000/01/rdf-schema#");
+ this.prefixMap.add("lcc-lr", "http://www.omg.org/spec/LCC/Languages/LanguageRepresentation/");
+ this.prefixMap.add("lcc-cr", "http://www.omg.org/spec/LCC/Countries/CountryRepresentation/");
+ }
+
+ // Expected result transformed into new style from requirement JENA-1262
+ private static final String expectedNewStyle = "PREFIX dct: <http://purl.org/dc/terms/>\n" +
Review comment:
Nice that makes it easier.
Memo to me: I'll need to add a `'\n'` at the last line because every prefix a new line is added, even in the last line.
--
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
---------------------------------------------------------------------
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 #1002: JENA-1262: Sorting of prefixes in Turtle serializer
Posted by GitBox <gi...@apache.org>.
afs commented on a change in pull request #1002:
URL: https://github.com/apache/jena/pull/1002#discussion_r633500945
##########
File path: jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
##########
@@ -18,20 +18,6 @@
package org.apache.jena.riot.system;
-import static org.apache.jena.riot.RDFLanguages.NQUADS;
Review comment:
The code is mixture of styles from many years of evolution. We don't have hard-and-fast rules; reformatting clutters up history and Jena has retain history from most of its life, even back to into SVN times (but not CVS). So generally, it's reflect the style of the file.
--
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
---------------------------------------------------------------------
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 #1002: JENA-1262: Sorting of prefixes in Turtle serializer
Posted by GitBox <gi...@apache.org>.
afs commented on a change in pull request #1002:
URL: https://github.com/apache/jena/pull/1002#discussion_r633072563
##########
File path: jena-arq/src/test/java/org/apache/jena/riot/system/TestRiotLib.java
##########
@@ -0,0 +1,92 @@
+/**
Review comment:
This isn't javadoc. The source is a mix - but for new files, no need to `/**`.
It helps to have as much consistency as possible when checking many files by script.
Fixing old formatting has a cost - file history get entries which are not material changes which can make bug-hunting a bit harder.
It does not need the `<p>`.
The URL is indented by 4.
--
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
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org