You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2013/01/21 16:38:07 UTC

svn commit: r1436423 - /jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Jena384_SubstitueFilterOptimize.java

Author: andy
Date: Mon Jan 21 15:38:07 2013
New Revision: 1436423

URL: http://svn.apache.org/viewvc?rev=1436423&view=rev
Log:
Test case for report recorded as jena 384.

Added:
    jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Jena384_SubstitueFilterOptimize.java

Added: jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Jena384_SubstitueFilterOptimize.java
URL: http://svn.apache.org/viewvc/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Jena384_SubstitueFilterOptimize.java?rev=1436423&view=auto
==============================================================================
--- jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Jena384_SubstitueFilterOptimize.java (added)
+++ jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Jena384_SubstitueFilterOptimize.java Mon Jan 21 15:38:07 2013
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dev;
+
+import com.hp.hpl.jena.query.* ;
+import com.hp.hpl.jena.rdf.model.ModelFactory ;
+import com.hp.hpl.jena.rdf.model.ResourceFactory ;
+import com.hp.hpl.jena.sparql.algebra.Algebra ;
+import com.hp.hpl.jena.sparql.algebra.Op ;
+import com.hp.hpl.jena.sparql.algebra.Transformer ;
+import com.hp.hpl.jena.sparql.algebra.optimize.TransformFilterEquality ;
+import com.hp.hpl.jena.sparql.core.Substitute ;
+import com.hp.hpl.jena.sparql.core.Var ;
+import com.hp.hpl.jena.sparql.engine.binding.Binding ;
+import com.hp.hpl.jena.sparql.engine.binding.BindingFactory ;
+import com.hp.hpl.jena.sparql.sse.SSE ;
+import com.hp.hpl.jena.sparql.util.QueryExecUtils ;
+
+public class Jena384_SubstitueFilterOptimize {
+
+    public static void main(String ... args)
+    {
+        new Jena384_SubstitueFilterOptimize() .testAskPrebound() ;
+    }
+    
+    //@Test
+    public void testAskPrebound() {
+        String term = "<http://example/>" ;
+        //String term = "'A55'@en" ;
+        
+        
+        Query query = QueryFactory.create("ASK WHERE { FILTER (?arg = "+term+")}");
+        
+        System.out.println(query) ;
+
+        if ( false )
+        {
+            String str = "http://example/" ;
+            QuerySolutionMap binding = new QuerySolutionMap();
+            binding.add("arg", ResourceFactory.createResource(str)) ;
+            QueryExecution qexec = QueryExecutionFactory.create(query, ModelFactory.createDefaultModel());
+            qexec.setInitialBinding(binding);
+            QueryExecUtils.executeQuery(query, qexec) ;
+            System.exit(0) ;
+        }
+        final Op op = Algebra.compile(query) ;
+//        System.out.println("algebra") ;
+//        System.out.println(op) ;
+
+        Binding initialBinding = BindingFactory.binding(Var.alloc("arg"), SSE.parseNode(term)) ;
+        
+        {
+            // Order - substitute then optimize.
+            // Right answer wrong reasons.
+            Op op1 = Transformer.transform(new TransformFilterEquality(), op);
+            op1 = Substitute.substitute(op1, initialBinding) ;
+            System.out.println("optimized-substitute") ;
+            System.out.println(op1) ;
+        }
+        {
+            // Order - substitue then optimize.
+            // Wrong answer, right reasons.
+            Op op2 = Substitute.substitute(op,initialBinding) ;
+            op2 = Transformer.transform(new TransformFilterEquality(), op2);
+            System.out.println("substitute-optimize") ;
+            System.out.println(op2) ;
+        }
+        
+//        boolean result = qexec.execAsk();
+//        Assert.assertTrue(result);
+    } 
+}
\ No newline at end of file