Return-Path: X-Original-To: apmail-jena-commits-archive@www.apache.org Delivered-To: apmail-jena-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4773BD94E for ; Mon, 21 Jan 2013 15:38:33 +0000 (UTC) Received: (qmail 46975 invoked by uid 500); 21 Jan 2013 15:38:33 -0000 Delivered-To: apmail-jena-commits-archive@jena.apache.org Received: (qmail 46893 invoked by uid 500); 21 Jan 2013 15:38:30 -0000 Mailing-List: contact commits-help@jena.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jena.apache.org Delivered-To: mailing list commits@jena.apache.org Received: (qmail 46877 invoked by uid 99); 21 Jan 2013 15:38:30 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Jan 2013 15:38:30 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Jan 2013 15:38:27 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 649F323889BB; Mon, 21 Jan 2013 15:38:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1436423 - /jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Jena384_SubstitueFilterOptimize.java Date: Mon, 21 Jan 2013 15:38:07 -0000 To: commits@jena.apache.org From: andy@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130121153807.649F323889BB@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 = "" ; + //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