Github user rvesse commented on a diff in the pull request:
https://github.com/apache/jena/pull/308#discussion_r152523288
--- Diff:
jena-arq/src/main/java/org/apache/jena/riot/process/normalize/CanonicalizeLiteral.java
---
@@ -73,6 +76,36 @@ public Node apply(Node node) {
return n2 ;
}
+ /** Convert the lexical form to a canonical form if one of the known
datatypes,
+ * otherwise return the node argument. (same object :: {@code ==})
+ */
+ public static Node canonicalValue(Node node) {
+ if ( ! node.isLiteral() )
+ return node ;
+ // Fast-track
+ if ( NodeUtils.isLangString(node) )
+ return node;
+ if ( NodeUtils.isSimpleString(node) )
+ return node;
+
+ if ( !
node.getLiteralDatatype().isValid(node.getLiteralLexicalForm()) )
+ // Invalid lexical form for the datatype - do nothing.
+ return node;
+
+ RDFDatatype dt = node.getLiteralDatatype() ;
+ // Datatype, not rdf:langString (RDF 1.1).
+ DatatypeHandler handler = dispatch.get(dt) ;
+ if ( handler == null )
+ return node ;
+ Node n2 = handler.handle(node, node.getLiteralLexicalForm(), dt) ;
+ if ( n2 == null )
+ return node ;
+ return n2 ;
+ }
+
+ /** Convert the language tag of a lexical form to a canonical form if
one of the known datatypes,
+ * otherwise return the node argument. (same object; compare by {@code
==})
+ */
private static Node canonicalLangtag(String lexicalForm, String
langTag) {
String langTag2 = LangTag.canonical(langTag);
if ( langTag2.equals(langTag) )
--- End diff --
Shouldn't we be returning `node` not `null` in the subsequent line?
---