jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [2/6] jena git commit: JENA-1102: EBV of "a"@en now handled.
Date Thu, 17 Dec 2015 20:58:19 GMT
JENA-1102: EBV of "a"@en now handled.

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

Branch: refs/heads/master
Commit: 2a50b822d15d9505ae5c60fa02d2fd74ff34599c
Parents: 751e49c
Author: Andy Seaborne <andy@apache.org>
Authored: Thu Dec 17 16:58:56 2015 +0000
Committer: Andy Seaborne <andy@apache.org>
Committed: Thu Dec 17 16:58:56 2015 +0000

----------------------------------------------------------------------
 .../jena/sparql/expr/nodevalue/XSDFuncOp.java   |  7 ++++--
 .../apache/jena/sparql/expr/TestNodeValue.java  | 26 +++++++++++++++++---
 2 files changed, 27 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/2a50b822/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/XSDFuncOp.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/XSDFuncOp.java b/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/XSDFuncOp.java
index 6b2ea50..d0cadee 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/XSDFuncOp.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/XSDFuncOp.java
@@ -218,14 +218,17 @@ public class XSDFuncOp
     public static boolean booleanEffectiveValue(NodeValue nv) {
         // Apply the "boolean effective value" rules
         // boolean: value of the boolean (strictly, if derived from xsd:boolean)
-        // string: length(string) > 0
+        // plain literal: lexical form length(string) > 0
         // numeric: number != Nan && number != 0
         // http://www.w3.org/TR/xquery/#dt-ebv
 
         if ( nv.isBoolean() )
             return nv.getBoolean() ;
         if ( nv.isString() )
-            return nv.getString().length() > 0 ;
+            return ! nv.getString().isEmpty() ;
+        if ( nv.isLiteral() && Util.isLangString(nv.asNode()) ) 
+            // Plain literals : no lang tag done by the test above.
+            return ! nv.getNode().getLiteralLexicalForm().isEmpty() ;
         if ( nv.isInteger() )
             return !nv.getInteger().equals(NodeValue.IntegerZERO) ;
         if ( nv.isDecimal() )

http://git-wip-us.apache.org/repos/asf/jena/blob/2a50b822/jena-arq/src/test/java/org/apache/jena/sparql/expr/TestNodeValue.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/expr/TestNodeValue.java b/jena-arq/src/test/java/org/apache/jena/sparql/expr/TestNodeValue.java
index bb94098..465f896 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/expr/TestNodeValue.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/expr/TestNodeValue.java
@@ -27,6 +27,7 @@ import org.apache.jena.JenaRuntime ;
 import org.apache.jena.atlas.junit.BaseTest ;
 import org.apache.jena.datatypes.xsd.XSDDatatype ;
 import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.NodeFactory ;
 import org.apache.jena.sparql.expr.ExprEvalException ;
 import org.apache.jena.sparql.expr.NodeValue ;
 import org.apache.jena.sparql.expr.nodevalue.XSDFuncOp ;
@@ -554,8 +555,6 @@ public class TestNodeValue extends BaseTest
     {
         NodeValue v = NodeValue.makeInteger(1) ;
         assertFalse("It's a boolean: "+v, v.isBoolean()) ;
-        //assertTrue("Not a node: "+v, v.hasNode()) ;
-        try { v.getBoolean() ; fail("getBoolean should fail") ; } catch (ExprEvalException
e) {}
         assertTrue("Not EBV true: "+v, XSDFuncOp.booleanEffectiveValue(v)) ;
     }
     
@@ -563,7 +562,6 @@ public class TestNodeValue extends BaseTest
     {
         NodeValue v = NodeValue.makeInteger(0) ;
         assertFalse("It's a boolean: "+v, v.isBoolean()) ;
-        //assertTrue("Not a node: "+v, v.hasNode()) ;
         try { v.getBoolean() ; fail("getBoolean should fail") ; } catch (ExprEvalException
e) {}
         assertFalse("Not EBV false: "+v, XSDFuncOp.booleanEffectiveValue(v)) ;
     }
@@ -581,11 +579,31 @@ public class TestNodeValue extends BaseTest
     {
         NodeValue v = NodeValue.makeString("") ;
         assertFalse("It's a boolean: "+v, v.isBoolean()) ;
-        //assertTrue("Not a node: "+v, v.hasNode()) ;
         try { v.getBoolean() ; fail("getBoolean should fail") ; } catch (ExprEvalException
e) {}
         assertFalse("Not EBV false: "+v, XSDFuncOp.booleanEffectiveValue(v)) ;
     }
     
+    // EBV includes plain literals which includes language tagged literals.
+    @Test public void testEBV7()
+    {
+        Node x = NodeFactory.createLiteral("", "en") ;
+        NodeValue v = NodeValue.makeNode(x) ;
+        assertFalse("Not EBV false: "+v, XSDFuncOp.booleanEffectiveValue(v)) ;
+    }
+
+    @Test public void testEBV8()
+    {
+        Node x = NodeFactory.createLiteral("not empty", "en") ;
+        NodeValue v = NodeValue.makeNode(x) ;
+        assertTrue("Not EBV true: "+v, XSDFuncOp.booleanEffectiveValue(v)) ;
+    }
+
+    private static boolean filterEBV(NodeValue nv) {
+        try { return XSDFuncOp.booleanEffectiveValue(nv) ; }
+        catch (ExprEvalException ex) { return false ; }
+    }
+    
+    
     @Test public void testFloatDouble1()
     {
         NodeValue v1 = NodeValue.makeNodeDouble("1.5") ;


Mime
View raw message