JENA-816 : SSE output for RDF 1.1 Project: http://git-wip-us.apache.org/repos/asf/jena/repo Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/c3843a36 Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/c3843a36 Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/c3843a36
Branch: refs/heads/hadoop-rdf Commit: c3843a36ee2e6e27cd244a0c36de0a08cc4c5869 Parents: 581cb41 Author: Andy Seaborne <[email protected]> Authored: Fri Nov 21 19:57:49 2014 +0000 Committer: Andy Seaborne <[email protected]> Committed: Fri Nov 21 19:57:49 2014 +0000 ---------------------------------------------------------------------- .../com/hp/hpl/jena/sparql/util/FmtUtils.java | 67 +++++++++----------- .../com/hp/hpl/jena/sparql/util/NodeUtils.java | 28 +++++++- .../apache/jena/riot/out/NodeFormatterBase.java | 21 ------ 3 files changed, 56 insertions(+), 60 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jena/blob/c3843a36/jena-arq/src/main/java/com/hp/hpl/jena/sparql/util/FmtUtils.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/util/FmtUtils.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/util/FmtUtils.java index 0a348af..cd58728 100644 --- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/util/FmtUtils.java +++ b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/util/FmtUtils.java @@ -275,11 +275,15 @@ public class FmtUtils stringEsc(result, s, true) ; result.append("\"") ; - // Format the language tag - if ( lang != null && lang.length()>0) - { + if ( NodeUtils.isSimpleString(literal) ) { + // No op. + return ; + } + + if ( NodeUtils.isLangString(literal) ) { result.append("@") ; result.append(lang) ; + return ; } if ( datatype != null ) @@ -348,47 +352,34 @@ public class FmtUtils public static void stringForNode(StringBuilder result, Node n, SerializationContext context) { - if ( n == null ) { - result.append( "<<null>>"); - return; + if ( n == null ) { + result.append("<<null>>") ; + return ; } // mappable? - if ( context != null && context.getBNodeMap() != null ) - { - String str = context.getBNodeMap().asString(n) ; - if ( str != null ) - { - result.append( str); - return; + if ( context != null && context.getBNodeMap() != null ) { + String str = context.getBNodeMap().asString(n) ; + if ( str != null ) { + result.append(str) ; + return ; } } - if ( n.isBlank() ) - { - result.append( "_:" ).append( n.getBlankNodeLabel() ); - } - else if ( n.isLiteral() ) - { - stringForLiteral( result, (Node_Literal) n, context ); - } - else if ( n.isURI() ) - { - String uri = n.getURI(); - stringForURI( result, uri, context ); - } - else if ( n.isVariable() ) - { - result.append( "?" ).append( n.getName() ); - } - else if ( n.equals( Node.ANY ) ) - { - result.append( "ANY" ); - } - else - { - Log.warn( FmtUtils.class, "Failed to turn a node into a string: " + n ); - result.append( n.toString() ); + if ( n.isBlank() ) { + result.append("_:").append(n.getBlankNodeLabel()) ; + } else if ( n.isLiteral() ) { + stringForLiteral(result, (Node_Literal)n, context) ; + } else if ( n.isURI() ) { + String uri = n.getURI() ; + stringForURI(result, uri, context) ; + } else if ( n.isVariable() ) { + result.append("?").append(n.getName()) ; + } else if ( n.equals(Node.ANY) ) { + result.append("ANY") ; + } else { + Log.warn(FmtUtils.class, "Failed to turn a node into a string: " + n) ; + result.append(n.toString()) ; } } http://git-wip-us.apache.org/repos/asf/jena/blob/c3843a36/jena-arq/src/main/java/com/hp/hpl/jena/sparql/util/NodeUtils.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/util/NodeUtils.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/util/NodeUtils.java index bdc2d47..a72dbdc 100644 --- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/util/NodeUtils.java +++ b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/util/NodeUtils.java @@ -23,7 +23,7 @@ import java.util.HashSet ; import java.util.Iterator ; import java.util.Set ; - +import com.hp.hpl.jena.JenaRuntime ; import com.hp.hpl.jena.datatypes.RDFDatatype ; import com.hp.hpl.jena.datatypes.xsd.XSDDatatype ; import com.hp.hpl.jena.graph.Node ; @@ -31,6 +31,7 @@ import com.hp.hpl.jena.graph.NodeFactory ; import org.apache.jena.atlas.lib.StrUtils ; import org.apache.jena.iri.IRI ; + import com.hp.hpl.jena.sparql.ARQInternalErrorException ; import com.hp.hpl.jena.sparql.expr.Expr ; import com.hp.hpl.jena.sparql.expr.ExprEvalException ; @@ -265,6 +266,31 @@ public class NodeUtils return node.getLiteralDatatypeURI() == null && node.getLiteralLanguage().equals("") ; } + + /** + * A Node is a simple string if: <li>(RDF 1.0) No datatype and no language + * tag. <li>(RDF 1.1) xsd:string + */ + public static boolean isSimpleString(Node n) { + RDFDatatype dt = n.getLiteralDatatype() ; + if ( dt == null ) + return !isLangString(n) ; + if ( JenaRuntime.isRDF11 ) + return dt.equals(XSDDatatype.XSDstring) ; + return false ; + } + + /** + * A Node is a language string if it has a language tag. + * (RDF 1.0 and RDF 1.1) + */ + public static boolean isLangString(Node n) { + String lang = n.getLiteralLanguage() ; + if ( lang == null ) + return false ; + return !lang.equals("") ; + } + // This is term comparison. public static EqualityTest sameTerm = new EqualityTest() { http://git-wip-us.apache.org/repos/asf/jena/blob/c3843a36/jena-arq/src/main/java/org/apache/jena/riot/out/NodeFormatterBase.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/main/java/org/apache/jena/riot/out/NodeFormatterBase.java b/jena-arq/src/main/java/org/apache/jena/riot/out/NodeFormatterBase.java index 1b4b5f9..dbcf620 100644 --- a/jena-arq/src/main/java/org/apache/jena/riot/out/NodeFormatterBase.java +++ b/jena-arq/src/main/java/org/apache/jena/riot/out/NodeFormatterBase.java @@ -54,27 +54,6 @@ public abstract class NodeFormatterBase implements NodeFormatter @Override public void formatBNode(AWriter w, Node n) { formatBNode(w, n.getBlankNodeLabel()) ; } -// /** A Node is a simple string if: -// * <li>(RDF 1.0) No datatype and no language tag. -// * <li>(RDF 1.1) xsd:string -// */ -// private static boolean isSimpleString(Node n) { -// RDFDatatype dt = n.getLiteralDatatype() ; -// if ( dt == null ) -// return ! isLangString(n) ; -// if ( JenaRuntime.isRDF11 ) -// return dt.equals(XSDDatatype.XSDstring) ; -// return false ; -// } -// -// /** A Node is a language string if it has a language tag. (RDF 1.0 and RDF 1.1) */ -// private static boolean isLangString(Node n) { -// String lang = n.getLiteralLanguage() ; -// if ( lang == null ) -// return false ; -// return ! lang.equals("") ; -// } - @Override public void formatLiteral(AWriter w, Node n) {
