jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject jena git commit: JENA-1269: Handle keywords 'true' and 'false' as node values
Date Thu, 22 Dec 2016 14:49:09 GMT
Repository: jena
Updated Branches:
  refs/heads/master 7443adf64 -> 9075e9ac2


JENA-1269: Handle keywords 'true' and 'false' as node values


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

Branch: refs/heads/master
Commit: 9075e9ac2b2969621691bee3b39fe85623b18e56
Parents: 7443adf
Author: Andy Seaborne <andy@apache.org>
Authored: Thu Dec 22 14:48:52 2016 +0000
Committer: Andy Seaborne <andy@apache.org>
Committed: Thu Dec 22 14:48:52 2016 +0000

----------------------------------------------------------------------
 .../engine/binding/BindingInputStream.java      | 25 ++++++++++++++++++--
 .../engine/binding/TestBindingStreams.java      |  9 +++++++
 2 files changed, 32 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/9075e9ac/jena-arq/src/main/java/org/apache/jena/sparql/engine/binding/BindingInputStream.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/binding/BindingInputStream.java
b/jena-arq/src/main/java/org/apache/jena/sparql/engine/binding/BindingInputStream.java
index e54c919..70e38bc 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/binding/BindingInputStream.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/binding/BindingInputStream.java
@@ -42,6 +42,7 @@ import org.apache.jena.riot.tokens.TokenType ;
 import org.apache.jena.riot.tokens.Tokenizer ;
 import org.apache.jena.riot.tokens.TokenizerFactory ;
 import org.apache.jena.sparql.core.Var ;
+import org.apache.jena.sparql.graph.NodeConst ;
 
 /** Language for reading in a stream of bindings.
  * See <a href="https://cwiki.apache.org/confluence/display/JENA/BindingIO">BindingIO</a>
@@ -133,20 +134,28 @@ public class BindingInputStream extends LangEngine implements Iterator<Binding>,
         {
             while ( lookingAt(TokenType.KEYWORD) )
             {
-                Token t = nextToken() ;
+                Token t = peekToken() ;
                 if ( t.getImage().equalsIgnoreCase("VARS") )
                 {
+                    nextToken();
                     directiveVars() ;
                     continue ;
                 }
                 if ( t.getImage().equalsIgnoreCase("PREFIX") )
                 {
+                    nextToken();
                     directivePrefix() ;
                     continue ;
                 }
+                // Not a directive.
+                break;
             }
         }
 
+        
+        protected final static String  KW_TRUE        = "true" ;
+        protected final static String  KW_FALSE       = "false" ;
+
         @Override
         protected Binding moveToNext()
         {
@@ -172,8 +181,20 @@ public class BindingInputStream extends LangEngine implements Iterator<Binding>,
                         n = lastLine.get(v) ;
                     else if ( token.hasType(TokenType.BNODE) )
                         n = NodeFactory.createBlankNode(NodeFmtLib.decodeBNodeLabel(token.getImage()))
;
-                    else
+                    else if ( token.hasType(TokenType.KEYWORD) ) {
+                        // Keywords values.
+                        String lex = token.getImage();
+                        if ( lex.equals(KW_TRUE) )
+                            n = NodeConst.nodeTrue ;
+                        else if ( lex.equals(KW_FALSE) )
+                            n = NodeConst.nodeFalse ;
+                        else {
+                            exception(token, "Keyword out of place: "+lex);
+                            n = null;
+                        }
+                    } else {
                         n = profile.create(null, token) ;
+                    }
                     binding.add(v, n) ;
                 }
                 i++ ;

http://git-wip-us.apache.org/repos/asf/jena/blob/9075e9ac/jena-arq/src/test/java/org/apache/jena/sparql/engine/binding/TestBindingStreams.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/binding/TestBindingStreams.java
b/jena-arq/src/test/java/org/apache/jena/sparql/engine/binding/TestBindingStreams.java
index d10bf7e..557cdb9 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/engine/binding/TestBindingStreams.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/binding/TestBindingStreams.java
@@ -33,6 +33,7 @@ import org.apache.jena.riot.system.PrefixMapFactory ;
 import org.apache.jena.riot.tokens.Tokenizer ;
 import org.apache.jena.riot.tokens.TokenizerFactory ;
 import org.apache.jena.sparql.core.Var ;
+import org.apache.jena.sparql.graph.NodeConst ;
 import org.apache.jena.sparql.resultset.ResultSetCompare ;
 import org.apache.jena.sparql.sse.Item ;
 import org.apache.jena.sparql.sse.SSE ;
@@ -85,6 +86,14 @@ public class TestBindingStreams extends BaseTest
     @Test public void bindingStream_10()        { testRead("VARS ?a ?b . 1 2 . * 9 .", b12,
b19) ; }
     @Test public void bindingStream_11()        { testRead("VARS ?a ?b ?c . 1 2 - . * 9 -
.", b12, b19) ; }
     
+    @Test
+    public void bindingStream_12() {
+        BindingMap b = BindingFactory.create();
+        b.add(Var.alloc("a"), NodeConst.nodeTrue);
+        b.add(Var.alloc("c"), NodeConst.nodeFalse);
+        testRead("VARS ?a ?b ?c . true - false . ", b);
+    }
+    
     @Test public void bindingStream_20()        { testRead("PREFIX : <http://example/>
. VARS ?x .\n:abc  .\n- .", x10, b0) ; }
     
     @Test public void bindingStream_50()        { testWriteRead(b12) ; }


Mime
View raw message