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 2011/09/30 15:32:03 UTC

svn commit: r1177649 [4/4] - in /incubator/jena/Scratch/AFS/Jena-Dev/trunk: ./ .settings/ Archive/ Archive/Lists/ Archive/ResultSet/ Archive/SSE/ Grammar/ src/ src/dev/ src/fm2/ src/fm2/atlas/ src/fm2/jenautil/ src/opexec/ src/reports/ src/reports/arch...

Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportAddingFilter.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportAddingFilter.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportAddingFilter.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportAddingFilter.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,138 @@
+/**
+ * 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 reports.archive;
+
+import java.text.ParseException ;
+import java.text.SimpleDateFormat ;
+import java.util.Calendar ;
+import java.util.Date ;
+
+import com.hp.hpl.jena.datatypes.xsd.XSDDateTime ;
+import com.hp.hpl.jena.ontology.OntModel ;
+import com.hp.hpl.jena.query.Query ;
+import com.hp.hpl.jena.query.QueryExecution ;
+import com.hp.hpl.jena.query.QueryExecutionFactory ;
+import com.hp.hpl.jena.query.QueryFactory ;
+import com.hp.hpl.jena.query.ResultSetFormatter ;
+import com.hp.hpl.jena.rdf.model.ModelFactory ;
+import com.hp.hpl.jena.sparql.expr.E_Equals ;
+import com.hp.hpl.jena.sparql.expr.Expr ;
+import com.hp.hpl.jena.sparql.expr.ExprVar ;
+import com.hp.hpl.jena.sparql.expr.nodevalue.NodeValueDateTime ;
+import com.hp.hpl.jena.sparql.syntax.ElementFilter ;
+import com.hp.hpl.jena.sparql.syntax.ElementGroup ;
+import com.hp.hpl.jena.sparql.syntax.ElementVisitor ;
+import com.hp.hpl.jena.sparql.syntax.ElementVisitorBase ;
+
+public class ReportAddingFilter {
+
+    // Locations of files used
+//    private static final String ONTOLOGY_FILE_URL = "file:C:\\Users\\Cihan\\Desktop\\Cihan_Yedek\\SRDC\\SRDC\\IKS\\Tests\\test\\jenaDevTestOnt.owl";
+//    private static final String QUERY_FILE_LOCATION = "C:\\Users\\Cihan\\Desktop\\Cihan_Yedek\\SRDC\\SRDC\\IKS\\Tests\\test\\jenaDevTestQuery";
+    
+    private static final String ONTOLOGY_FILE_URL = "file:Reports/AddingFilter/D.rdf" ;
+    private static final String QUERY_FILE_LOCATION = "Reports/AddingFilter/Q.rq";
+
+    
+    private static final String DATETIME_FORMAT = "yyyy-mm-dd HH:mm:ss:SSSZ";
+    private static final String DATETIME_INPUT = "2010-01-19 16:00:00:000-0000";
+
+    public static void main(String[] args) throws Exception {
+        ReportAddingFilter test = new ReportAddingFilter();
+        test.run();
+    }
+
+    public void run() throws Exception {
+
+        // Create and Load ontology
+        OntModel ont = ModelFactory.createOntologyModel();
+        ont.read(ONTOLOGY_FILE_URL);
+
+        // Create query
+//        Query query = QueryFactory.create(FileReader.getInstance().readFile(
+//                QUERY_FILE_LOCATION));
+        Query query = QueryFactory.read(QUERY_FILE_LOCATION) ;
+
+        // Execute And Print Result
+        executeQueryOnOntology(ont, query);
+        // Add FILTER element to the query
+        addElement(query);
+        // Execute the new query
+        executeQueryOnOntology(ont, query);
+
+    }
+
+    private void addElement(Query query) throws ParseException {
+
+        // Define date format
+        SimpleDateFormat format = new SimpleDateFormat(DATETIME_FORMAT);
+        // Create a date object
+        Date date = format.parse(DATETIME_INPUT);
+
+        // Create variable expression
+        Expr exprVar = new ExprVar("Date");
+        // Create dateTime expression
+        Expr exprDate = new NodeValueDateTime(dateToXSDDateTime(date));
+        // Create is equal expression
+        Expr exprEqual = new E_Equals(exprVar, exprDate);
+        // Create FILTER
+        final ElementFilter filter = new ElementFilter(exprEqual);
+        // Define an element visitor to add FILTER element
+        FilterAdder visitor = new FilterAdder(filter);
+        // Visit query pattern so visitor will add the element filter
+        query.getQueryPattern().visit(visitor);
+    }
+
+    private static XSDDateTime dateToXSDDateTime(Date date) {
+        // Get a calendar
+        Calendar cal = Calendar.getInstance();
+        // Set time of the calendar to specified date
+        cal.setTime(date);
+        // return the newly created object using calendar
+        return new XSDDateTime(cal);
+    }
+
+    private static void executeQueryOnOntology(OntModel ont, Query query) {
+        // Print query
+        System.out.println(query.serialize());
+        // Create execution
+        QueryExecution exec = QueryExecutionFactory.create(query, ont);
+        // Print results
+        System.out.println(ResultSetFormatter.asText(exec.execSelect()));
+
+    }
+
+    public class FilterAdder extends ElementVisitorBase implements
+            ElementVisitor {
+        //Filter to be added to query 
+        private ElementFilter filter;
+
+        //Public constructor
+        public FilterAdder(ElementFilter elFilter) {
+            filter = elFilter;
+        }
+
+        //Override this function so that it adds the desired filter
+        @Override
+        public void visit(ElementGroup el) {
+            el.addElementFilter(filter);
+        }
+    }
+
+}

Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportAssignSubstitute.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportAssignSubstitute.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportAssignSubstitute.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportAssignSubstitute.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,78 @@
+/**
+ * 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 reports.archive;
+
+import org.junit.Test ;
+import org.openjena.atlas.lib.StrUtils ;
+
+import com.hp.hpl.jena.query.Query ;
+import com.hp.hpl.jena.query.QueryFactory ;
+import com.hp.hpl.jena.query.Syntax ;
+import com.hp.hpl.jena.sparql.algebra.Algebra ;
+import com.hp.hpl.jena.sparql.algebra.Op ;
+import com.hp.hpl.jena.sparql.algebra.optimize.Optimize ;
+import com.hp.hpl.jena.sparql.core.Substitute ;
+import com.hp.hpl.jena.sparql.core.Var ;
+import com.hp.hpl.jena.sparql.util.NodeFactory ;
+
+public class ReportAssignSubstitute
+{
+    @Test
+    public void test()
+    {
+    }
+
+    
+    public static void main(String[] argv) throws Exception
+    {
+        // Test case needed.
+        String qs = StrUtils.strjoinNL("PREFIX  rdfs:   <http://www.w3.org/2000/01/rdf-schema#>",
+                                       "PREFIX fn:      <http://www.w3.org/2005/xpath-functions#>",
+                                       "PREFIX : <http://example/>",
+                                       "SELECT *" ,
+                                       "WHERE {" ,
+//                                       "    ?instance a :Person .",
+                                       "    ?instance rdfs:label ?label .",
+//                                       "    {",
+//                                       "        LET (?lab := ?label) .",
+                                       "        LET (?label := ?label) .",
+                                       "         FILTER fn:starts-with(?lab, \"A\") .",
+//                                       "    }",
+                                       "} ") ; 
+        Query query = QueryFactory.create(qs, Syntax.syntaxARQ) ;
+        Op op1 = Algebra.compile(query) ;
+
+        Op op1a = Substitute.substitute(op1, Var.alloc("label"), NodeFactory.parseNode("'aa'")) ;
+        System.out.println(op1a) ;
+        System.exit(0) ;
+        
+        
+        System.out.println(op1) ;
+        Op op2 = Algebra.optimize(op1) ;
+        System.out.println(op2) ;
+        
+        Op op2a = Substitute.substitute(op2, Var.alloc("label"), NodeFactory.parseNode("'aa'")) ;
+        System.out.println(op2a) ;
+        
+        Optimize.noOptimizer() ;
+        Op op3 = Algebra.optimize(op1) ;
+        System.out.println(op3) ;
+        System.exit(0) ;
+    }
+}

Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportCopySubstituteNoContext.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportCopySubstituteNoContext.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportCopySubstituteNoContext.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportCopySubstituteNoContext.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,44 @@
+/**
+ * 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 reports.archive;
+
+import com.hp.hpl.jena.query.Query ;
+import com.hp.hpl.jena.query.QueryExecution ;
+import com.hp.hpl.jena.query.QueryExecutionFactory ;
+import com.hp.hpl.jena.query.QueryFactory ;
+import com.hp.hpl.jena.query.QuerySolutionMap ;
+import com.hp.hpl.jena.query.Syntax ;
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.rdf.model.ModelFactory ;
+import com.hp.hpl.jena.vocabulary.OWL ;
+
+public class ReportCopySubstituteNoContext
+{
+    public static void main(String ...argv)
+    {
+        Query query = QueryFactory.create("ASK WHERE { FILTER IRI(\"http://aldi.de\") }", Syntax.syntaxARQ);
+        Model model = ModelFactory.createDefaultModel();
+        QueryExecution qexec = QueryExecutionFactory.create(query, model);
+        QuerySolutionMap bindings = new QuerySolutionMap();
+        bindings.add("this", OWL.Thing);
+        qexec.setInitialBinding(bindings);
+        qexec.execAsk();
+        System.out.println("DONE") ;
+    }
+}

Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportDuplicateBNodes.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportDuplicateBNodes.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportDuplicateBNodes.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportDuplicateBNodes.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,59 @@
+/**
+ * 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 reports.archive;
+
+import com.hp.hpl.jena.ontology.Individual ;
+import com.hp.hpl.jena.ontology.OntClass ;
+import com.hp.hpl.jena.ontology.OntModel ;
+import com.hp.hpl.jena.ontology.OntModelSpec ;
+import com.hp.hpl.jena.ontology.OntProperty ;
+import com.hp.hpl.jena.query.Query ;
+import com.hp.hpl.jena.query.QueryExecution ;
+import com.hp.hpl.jena.query.QueryExecutionFactory ;
+import com.hp.hpl.jena.query.QueryFactory ;
+import com.hp.hpl.jena.query.ResultSet ;
+import com.hp.hpl.jena.query.ResultSetFormatter ;
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.rdf.model.ModelFactory ;
+
+public class ReportDuplicateBNodes
+{
+    public static void main(String...argv)
+    {
+        String queryString = "SELECT * { ?s ?p ?o }" ;
+        
+        
+        OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
+        
+        String NS = "http://mc-model.owl#";
+        OntClass typeA = model.createClass(NS+"TypeA");
+        OntClass typeB = model.createClass(NS+"TypeB");
+        Individual indiA = model.createIndividual(NS+"IndiA", typeA);
+        Individual indiB = model.createIndividual(NS+"IndiB", typeB);
+        OntProperty rel = model.createOntProperty(NS+"rel");
+        model.createStatement(indiA, rel, indiB).createReifiedStatement();
+        Query query = QueryFactory.create(queryString);
+
+        Model model2 = model.getBaseModel() ;
+        QueryExecution qe = QueryExecutionFactory.create(query, model2);
+        ResultSet results = qe.execSelect();
+        ResultSetFormatter.out(results, query);
+
+    }
+}

Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportEventUpdate.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportEventUpdate.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportEventUpdate.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportEventUpdate.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,89 @@
+/**
+ * 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 reports.archive;
+
+import com.hp.hpl.jena.query.Dataset ;
+import com.hp.hpl.jena.query.DatasetFactory ;
+import com.hp.hpl.jena.rdf.listeners.StatementListener ;
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.rdf.model.ModelChangedListener ;
+import com.hp.hpl.jena.rdf.model.ModelFactory ;
+import com.hp.hpl.jena.rdf.model.Property ;
+import com.hp.hpl.jena.rdf.model.Resource ;
+import com.hp.hpl.jena.rdf.model.Statement ;
+import com.hp.hpl.jena.sparql.core.DSG_Mem ;
+import com.hp.hpl.jena.sparql.core.DatasetGraph ;
+import com.hp.hpl.jena.update.UpdateAction ;
+import com.hp.hpl.jena.update.UpdateFactory ;
+import com.hp.hpl.jena.update.UpdateRequest ;
+
+
+public class ReportEventUpdate
+{
+    public static void main(String ...args)
+    {
+        DatasetGraph dsg = new DSG_Mem() ;
+        
+        //Dataset ds = DatasetFactory.create() ;
+        //Dataset ds = DatasetFactory.create(dsg) ;
+        Dataset ds = DatasetFactory.create(ModelFactory.createModelForGraph(dsg.getDefaultGraph())) ;
+        
+        
+        
+        exec(ds) ;
+        exec(DatasetFactory.create()) ;
+        
+    }
+    
+    
+    static void exec(Dataset ds)
+    {
+        Model m = ds.getDefaultModel() ;
+        
+        // Works for graph backed dataset.
+        ModelChangedListener listener = new StatementListener()
+        {
+            @Override
+            public void addedStatement( Statement s )
+            {
+             System.out.println("Add: "+s) ;
+            }
+            @Override
+            public void removedStatement( Statement s )
+            {
+                System.out.println("Remove: "+s) ;
+            }
+        } ;
+        
+        m.register(listener) ;
+        
+        Resource s = m.createResource("http://example/s") ;
+        Property p = m.createProperty("http://example/o") ;
+        m.add(s, p, "123") ;
+        
+        UpdateRequest request = UpdateFactory.create("BASE <http://example> INSERT DATA { <s> <p> <o> }") ;
+        UpdateAction.execute(request, ds) ;
+        
+        System.out.print(ds.asDatasetGraph()) ;
+        System.out.println("DONE") ;
+        
+        
+        
+    }
+}

Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportGraphBind.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportGraphBind.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportGraphBind.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportGraphBind.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,124 @@
+/**
+ * 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 reports.archive;
+
+import com.hp.hpl.jena.query.DataSource;
+import com.hp.hpl.jena.query.DatasetFactory;
+import com.hp.hpl.jena.query.Query;
+import com.hp.hpl.jena.query.QueryExecution;
+import com.hp.hpl.jena.query.QueryExecutionFactory;
+import com.hp.hpl.jena.query.QueryFactory;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+
+public class ReportGraphBind {
+
+    /* execute a construct query on a model, and return the resulting model */
+    private static Model runQuery(String queryStr, Model model){
+        /* create and execute query */
+        Query query = QueryFactory.create(queryStr);
+        DataSource dsource = DatasetFactory.create();
+        dsource.addNamedModel("http://input/", model);
+        QueryExecution qexec = QueryExecutionFactory.create(query, dsource);
+        Model resultModel = qexec.execConstruct() ;
+        qexec.close();
+        return resultModel;
+    }
+
+    /* execute a construct query on a model, and return the resulting model */
+    private static void runQuery2(String queryStr, Model model){
+        /* create and execute query */
+
+        Query query = QueryFactory.create(queryStr);
+        System.out.println(query);
+
+        DataSource dsource = DatasetFactory.create();
+        dsource.addNamedModel("http://input/", model);
+        QueryExecution qexec = QueryExecutionFactory.create(query, dsource);
+        Model resultModel = qexec.execConstruct() ;
+        qexec.close();
+        System.out.println("--------") ;
+        resultModel.write(System.out, "N-TRIPLES") ;
+        System.out.println("--------") ;
+        System.out.println();
+    }
+
+
+    public static void main(String[] args){
+        /** 
+         * I would expect all of these queries to be equivalent 
+         */
+
+        /* BIND inside the GRAPH{} section, and do regular pattern matching */
+        String bind_URI_in =  "CONSTRUCT { ?s ?p ?o } \n " +
+        " WHERE {  \n" +
+        " GRAPH<http://input/> { \n" +
+        "   BIND(<http://some/uri> AS ?s) \n" +
+        "   ?s ?p ?o. \n "+
+        " } \n "+
+        "} \n ";
+
+        /* BIND outside the GRAPH{} section, and do regular pattern matching */
+        String bind_URI_out =  "CONSTRUCT { ?s ?p ?o } \n " +
+        " WHERE {  \n" +
+        " BIND(<http://some/uri> AS ?s) \n" +
+        " GRAPH<http://input/> { \n" +
+        "   ?s ?p ?o. \n " +
+        " } \n "+
+        "} \n ";
+
+        /* BIND inside the GRAPH{} section, and FILTER inside */
+        String bind_URI_in_filter =  "CONSTRUCT { ?s ?p ?o } \n " +
+        " WHERE {  \n" +
+        " GRAPH<http://input/> { \n" +
+        "   BIND(<http://some/uri> AS ?bound) \n" +
+        "   ?s ?p ?o. \n "+
+        "   FILTER(?s = ?bound ) \n"+
+        " } \n "+
+        "} \n ";
+
+        /* BIND outside the GRAPH{} section, and FILTER inside 
+         *  
+         * DOES NOT WORK AS EXPECTED
+         */
+        String bind_URI_out_filter =  "CONSTRUCT { ?s ?p ?o } \n " +
+        " WHERE {  \n" +
+        " BIND(<http://some/uri> AS ?bound) \n" +
+        " GRAPH<http://input/> { \n" +
+        "   ?s ?p ?o. \n " +
+        "   FILTER(?s = ?bound ) \n"+
+        " } \n "+
+        "} \n ";
+
+        Model model = runQuery("CONSTRUCT { <http://some/uri> <http://some/prop> <http://some/uri2> } WHERE {} ", ModelFactory.createDefaultModel());
+
+        runQuery2(bind_URI_in,  model) ; 
+        runQuery2(bind_URI_out, model) ; 
+        runQuery2(bind_URI_in_filter,  model) ; 
+        runQuery2(bind_URI_out_filter, model) ; 
+
+        //    assert(runQuery(bind_URI_in,  model).size()==1); 
+        //    assert(runQuery(bind_URI_out, model).size()==1); 
+        //    assert(runQuery(bind_URI_in_filter,  model).size()==1); 
+        //    assert(runQuery(bind_URI_out_filter, model).size()==1) : "A filter bug? "; 
+
+
+
+    }
+}

Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportRemoteService.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportRemoteService.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportRemoteService.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportRemoteService.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,50 @@
+/**
+ * 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 reports.archive;
+
+import com.hp.hpl.jena.query.QueryExecution ;
+import com.hp.hpl.jena.query.QueryExecutionFactory ;
+import com.hp.hpl.jena.query.ResultSet ;
+import com.hp.hpl.jena.query.ResultSetFormatter ;
+
+public class ReportRemoteService
+{
+    public static void main(String...argv)
+    {
+        System.out.println();
+        
+        // "snorql" is the web form, "sparql" is the service endpoint
+        
+        String service="http://www4.wiwiss.fu-berlin.de/dblp/sparql"; // or http://dblp.l3s.de/d2r/snorql/
+        String query="select distinct ?Concept where {[] a ?Concept}";
+        
+        System.out.println("Remote: "+service);
+
+        QueryExecution e = QueryExecutionFactory. sparqlService(service, query);
+        try {
+            ResultSet results = e.execSelect();
+            ResultSetFormatter.out(results) ;
+        }
+
+        finally {
+            System.out.println("closing!" );
+            e.close() ;
+        }
+    }
+}

Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportServiceVarRename.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportServiceVarRename.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportServiceVarRename.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportServiceVarRename.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,44 @@
+/**
+ * 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 reports.archive;
+
+import com.hp.hpl.jena.query.Query ;
+import com.hp.hpl.jena.query.QueryFactory ;
+import com.hp.hpl.jena.sparql.algebra.Algebra ;
+import com.hp.hpl.jena.sparql.algebra.Op ;
+
+import org.openjena.atlas.lib.StrUtils ;
+
+public class ReportServiceVarRename
+{
+    public static void main(String[] args)
+    {
+        String qs = StrUtils.strjoinNL("SELECT DISTINCT ?s",
+                                       "{ SERVICE <http://dbpedia.org/sparql>",
+                                       "    { SELECT ?s { ?s <http://xmlns.com/foaf/0.1/knows> ?o . } limit 10 }",
+                                       "}") ;
+        Query query = QueryFactory.create(qs) ;
+        Op op = Algebra.compile(query) ;
+        Op op2 = Algebra.optimize(op) ;
+        System.out.println(op) ;
+        System.out.println(op2) ;
+        System.exit(0) ;
+    }
+
+}

Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportSlowDatatype.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportSlowDatatype.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportSlowDatatype.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportSlowDatatype.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,68 @@
+/**
+ * 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 reports.archive;
+
+import com.hp.hpl.jena.query.Query ;
+import com.hp.hpl.jena.query.QueryExecution ;
+import com.hp.hpl.jena.query.QueryExecutionFactory ;
+import com.hp.hpl.jena.query.QueryFactory ;
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.sparql.util.QueryExecUtils ;
+import com.hp.hpl.jena.sparql.util.Timer ;
+import com.hp.hpl.jena.util.FileManager ;
+
+public class ReportSlowDatatype
+{
+    public static void main(String...argv)
+    {
+        Model model = FileManager.get().loadModel("tmp/holger-test.ttl") ;
+        
+        Query q1 = QueryFactory.read("tmp/Q1.rq") ;
+        System.out.println(q1) ;
+        Query q2 = QueryFactory.read("tmp/Q2.rq") ;
+        System.out.println(q2) ;
+
+        exec(q1, model) ;
+        exec(q2, model) ;
+        
+        System.out.println("----") ;
+        
+        execTimed(q1, model) ;
+        execTimed(q2, model) ;
+    }
+    
+    private static void exec(Query query, Model model)
+    {
+        QueryExecution qexec = QueryExecutionFactory.create(query, model) ;
+        QueryExecUtils.executeQuery(query, qexec) ;
+    }
+    
+    private static void execTimed(Query query, Model model)
+    {
+//        System.out.println(ARQ.VERSION); 
+//        System.out.println(Jena.VERSION); 
+
+        Timer timer = new Timer() ;
+        timer.startTimer() ;
+        exec(query, model) ;
+        long time = timer.endTimer() ;
+        System.out.printf("Time = %.2fs\n", time/1000.0) ;
+    }
+    
+}

Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportUnclosedIterator.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportUnclosedIterator.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportUnclosedIterator.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportUnclosedIterator.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,54 @@
+/**
+ * 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 reports.archive;
+
+import com.hp.hpl.jena.query.Query ;
+import com.hp.hpl.jena.query.QueryExecution ;
+import com.hp.hpl.jena.query.QueryExecutionFactory ;
+import com.hp.hpl.jena.query.QueryFactory ;
+import com.hp.hpl.jena.query.ResultSet ;
+import com.hp.hpl.jena.query.Syntax ;
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.rdf.model.ModelFactory ;
+
+public class ReportUnclosedIterator
+{
+    public static void main(String...argv)
+    {
+        // Analysis
+        // Aggregation reads whole results and then "replaces" the root iterator."
+        // Order does the same? No, because ORDER is over everyting, this is per group. 
+        
+        Model model = ModelFactory.createDefaultModel();
+        // Insert one triple here.
+        //model.getGraph().add(SSE.parseTriple("(<x> <p> <y>)")) ;
+        
+        String str = "SELECT count(?object) WHERE { ?subject ?p ?object }";
+        Query query = QueryFactory.create(str, Syntax.syntaxARQ);
+        QueryExecution qexec = QueryExecutionFactory.create(query, model);
+        ResultSet rs = qexec.execSelect();
+//        ResultSetFormatter.out(rs) ;
+//        if ( rs.hasNext() ) 
+//            rs.next();
+        //rs.hasNext() ; // If this, forcing iteraors to finish neatly, it works.
+        
+        qexec.close();
+        System.out.println("Exit") ;
+    }
+}

Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportUpdate1.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportUpdate1.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportUpdate1.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/ReportUpdate1.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,66 @@
+/**
+ * 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 reports.archive;
+
+
+import com.hp.hpl.jena.sparql.sse.SSE ;
+import com.hp.hpl.jena.update.GraphStore ;
+import com.hp.hpl.jena.update.GraphStoreFactory ;
+import com.hp.hpl.jena.update.UpdateAction ;
+import com.hp.hpl.jena.update.UpdateFactory ;
+import com.hp.hpl.jena.update.UpdateRequest ;
+
+
+public class ReportUpdate1
+{
+    public static void main (String... argv)
+    {
+        GraphStore graphStore = GraphStoreFactory.create() ;
+
+        String q = 
+            "CREATE GRAPH <example:store> \n" +  // create a graph
+            "INSERT INTO  <example:store> { _:foo a <example:Thing> . } \n" + // add some data
+            "DELETE FROM  <example:store> { ?s ?p ?o } WHERE { ?s ?p ?o } \n"; // remove all data
+
+        UpdateRequest req = UpdateFactory.create(q) ;
+        
+        UpdateRequest req1 = UpdateFactory.create("CREATE GRAPH <example:store>") ;
+        UpdateRequest req2 = UpdateFactory.create("INSERT INTO  <example:store> { _:foo a <example:Thing> . }") ;
+        UpdateRequest req3 = UpdateFactory.create("DELETE FROM  <example:store> { ?s ?p ?o } WHERE { ?s ?p ?o }") ;
+        UpdateRequest req4 = UpdateFactory.create("DELETE FROM  <example:store> { ?s ?p ?o } WHERE { GRAPH <example:store> {?s ?p ?o } }") ;
+        
+        
+        //System.out.println("---------------------") ;
+        SSE.write(graphStore) ;
+        UpdateAction.execute(req1, graphStore);
+        System.out.println("---------------------") ;
+        SSE.write(graphStore) ;
+        UpdateAction.execute(req2, graphStore);
+        System.out.println("---------------------") ;
+        SSE.write(graphStore) ;
+        UpdateAction.execute(req4, graphStore);
+        System.out.println("---------------------") ;
+        SSE.write(graphStore) ;
+        System.out.println("---------------------") ;
+        
+        //UpdateAction.execute(UpdateFactory.create(q), graphStore);
+        SSE.write(graphStore) ;
+    }
+
+}