You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by rv...@apache.org on 2014/12/01 17:03:46 UTC

[02/19] jena git commit: JENA-818, JENA-816 : Rewrite sameValueAs.

JENA-818, JENA-816 : Rewrite sameValueAs.

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/46189416
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/46189416
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/46189416

Branch: refs/heads/hadoop-rdf
Commit: 46189416954b4422936ffd41fc3c740bb21fa0ea
Parents: 6b78e06
Author: Andy Seaborne <an...@apache.org>
Authored: Wed Nov 26 19:38:20 2014 +0000
Committer: Andy Seaborne <an...@apache.org>
Committed: Wed Nov 26 19:38:20 2014 +0000

----------------------------------------------------------------------
 .../hpl/jena/graph/impl/LiteralLabelImpl.java   | 85 ++++++++++++++++++--
 1 file changed, 78 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/46189416/jena-core/src/main/java/com/hp/hpl/jena/graph/impl/LiteralLabelImpl.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/com/hp/hpl/jena/graph/impl/LiteralLabelImpl.java b/jena-core/src/main/java/com/hp/hpl/jena/graph/impl/LiteralLabelImpl.java
index cb8be15..64362a3 100644
--- a/jena-core/src/main/java/com/hp/hpl/jena/graph/impl/LiteralLabelImpl.java
+++ b/jena-core/src/main/java/com/hp/hpl/jena/graph/impl/LiteralLabelImpl.java
@@ -29,7 +29,9 @@ import com.hp.hpl.jena.datatypes.*;
 import com.hp.hpl.jena.datatypes.xsd.*;
 import com.hp.hpl.jena.datatypes.xsd.impl.*;
 import com.hp.hpl.jena.rdf.model.impl.Util ;
+import com.hp.hpl.jena.shared.JenaException ;
 import com.hp.hpl.jena.shared.impl.JenaParameters;
+import com.hp.hpl.jena.vocabulary.RDF ;
 
 /**
  * Represents the "contents" of a Node_Literal.
@@ -394,15 +396,84 @@ final /*public*/ class LiteralLabelImpl implements LiteralLabel {
     */
 	@Override
     public boolean sameValueAs( LiteralLabel other ) {
-		if (other == null)
-			return false;
-		if (!wellformed || !other.isWellFormedRaw()) 
-			return areIllFormedLiteralsSameValueAs( other );
-		return dtype == null 
-		    ? isPlainLiteralSameValueAsOther( other ) 
-		    : isTypedLiteralSameValueAsOther( other );
+	    
+	    return sameValueAs(this, other) ;
+	    
+//		if (other == null)
+//			return false;
+//		if (!wellformed || !other.isWellFormedRaw()) 
+//			return areIllFormedLiteralsSameValueAs( other );
+//		return dtype == null 
+//		    ? isPlainLiteralSameValueAsOther( other ) 
+//		    : isTypedLiteralSameValueAsOther( other );
 	}
 
+	// -------------
+    private static boolean sameValueAs(LiteralLabel lit1, LiteralLabel lit2) {
+        //return  lit1.sameValueAs(lit2) ; 
+        if ( lit1 == null )
+            throw new NullPointerException() ;
+        if ( lit2 == null )
+            throw new NullPointerException() ;
+        // Strings.
+        if ( isStringValue(lit1) && isStringValue(lit2) ) {
+            // Complete compatibility mode.
+            if ( JenaParameters.enablePlainLiteralSameAsString )
+                return lit1.getLexicalForm().equals(lit2.getLexicalForm()) ;
+            else
+                return lit1.getLexicalForm().equals(lit2.getLexicalForm()) &&
+                    Objects.equals(lit1.getDatatype(), lit2.getDatatype()) ;
+        }
+        
+        if ( isStringValue(lit1) ) return false ;
+        if ( isStringValue(lit2) ) return false ;
+        
+        // Language tag strings
+        if ( isLangString(lit1) && isLangString(lit2) ) {
+            String lex1 = lit1.getLexicalForm() ;
+            String lex2 = lit2.getLexicalForm() ;
+            return lex1.equals(lex2) && lit1.language().equalsIgnoreCase(lit2.language()) ;
+        } 
+        if ( isLangString(lit1) ) return false ;
+        if ( isLangString(lit2) ) return false ;
+        
+        // Both not strings, not lang strings.
+        // Datatype set.
+        if ( lit1.isWellFormedRaw() && lit2.isWellFormedRaw() )
+            // Both well-formed.
+            return lit1.getDatatype().isEqual(lit1, lit2) ;
+        if ( ! lit1.isWellFormedRaw() && ! lit2.isWellFormedRaw() )
+            return lit1.equals(lit2) ;
+        // One is well formed, the other is not.
+        return false ;
+    }
+    /** Return true if the literal lable is a string value (RDF 1.0 and RDF 1.1) */ 
+    private static boolean isStringValue(LiteralLabel lit) {
+        if ( lit.getDatatype() == null )
+            // RDF 1.0
+            return ! isLangString(lit) ;
+        if ( lit.getDatatype().equals(XSDDatatype.XSDstring)  )
+            return true;
+        return false ;
+    }
+    
+    /** Return true if the literal label is a language string. (RDF 1.0 and RDF 1.1) */
+    public static boolean isLangString(LiteralLabel lit) {
+        String lang = lit.language() ;
+        if ( lang == null )
+            return false ;
+        // Check.
+        if ( lang.equals("") )
+            return false ;
+        // This is an additional check.
+        if ( JenaRuntime.isRDF11 ) {
+            if ( ! Objects.equals(lit.getDatatype(), RDF.dtLangString) )
+                throw new JenaException("Literal with language string which is not rdf:langString: "+lit) ;
+        }
+        return true ;
+    }
+    // -------------
+	
 	/**
 	    Need to support comparison of ill-formed literals in order for the WG 
 	    tests on ill formed literals to be testable using isIsomorphic to. "same