You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by ch...@apache.org on 2012/11/05 13:10:29 UTC

svn commit: r1405763 - in /jena/Scratch/Eyeball/trunk: .classpath doc/eyeball-2.4-full-template.html src/main/java/com/hp/hpl/jena/extras/tools/query/ModelQuery.java src/test/java/com/hp/hpl/jena/extras/tools/query/test/TestModelQuery.java

Author: chrisdollin
Date: Mon Nov  5 12:10:29 2012
New Revision: 1405763

URL: http://svn.apache.org/viewvc?rev=1405763&view=rev
Log:
Revised ModelQuery to use ARQ rather than being chummy with the graph implementation.

Modified:
    jena/Scratch/Eyeball/trunk/.classpath
    jena/Scratch/Eyeball/trunk/doc/eyeball-2.4-full-template.html
    jena/Scratch/Eyeball/trunk/src/main/java/com/hp/hpl/jena/extras/tools/query/ModelQuery.java
    jena/Scratch/Eyeball/trunk/src/test/java/com/hp/hpl/jena/extras/tools/query/test/TestModelQuery.java

Modified: jena/Scratch/Eyeball/trunk/.classpath
URL: http://svn.apache.org/viewvc/jena/Scratch/Eyeball/trunk/.classpath?rev=1405763&r1=1405762&r2=1405763&view=diff
==============================================================================
--- jena/Scratch/Eyeball/trunk/.classpath (original)
+++ jena/Scratch/Eyeball/trunk/.classpath Mon Nov  5 12:10:29 2012
@@ -2,13 +2,9 @@
 <classpath>
   <classpathentry kind="src" path="src/test/java" output="target/test-classes" including="**/*.java"/>
   <classpathentry kind="src" path="src/main/java" including="**/*.java"/>
+  <classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
   <classpathentry kind="output" path="target/classes"/>
   <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
-  <classpathentry kind="var" path="M2_REPO/org/apache/lucene/lucene-core/3.5.0/lucene-core-3.5.0.jar" sourcepath="M2_REPO/org/apache/lucene/lucene-core/3.5.0/lucene-core-3.5.0-sources.jar">
-    <attributes>
-      <attribute value="jar:file:/home/christopher/M2/repository/org/apache/lucene/lucene-core/3.5.0/lucene-core-3.5.0-javadoc.jar!/" name="javadoc_location"/>
-    </attributes>
-  </classpathentry>
   <classpathentry kind="var" path="M2_REPO/junit/junit/4.8.2/junit-4.8.2.jar" sourcepath="M2_REPO/junit/junit/4.8.2/junit-4.8.2-sources.jar">
     <attributes>
       <attribute value="jar:file:/home/christopher/M2/repository/junit/junit/4.8.2/junit-4.8.2-javadoc.jar!/" name="javadoc_location"/>

Modified: jena/Scratch/Eyeball/trunk/doc/eyeball-2.4-full-template.html
URL: http://svn.apache.org/viewvc/jena/Scratch/Eyeball/trunk/doc/eyeball-2.4-full-template.html?rev=1405763&r1=1405762&r2=1405763&view=diff
==============================================================================
--- jena/Scratch/Eyeball/trunk/doc/eyeball-2.4-full-template.html (original)
+++ jena/Scratch/Eyeball/trunk/doc/eyeball-2.4-full-template.html Mon Nov  5 12:10:29 2012
@@ -22,12 +22,12 @@
     <a href="ReleaseNotes.text">release notes</a> for descriptions 
     of changes from previous versions.
     Eyeball is part of the Jena family of RDF/OWL tools: see
-    <a href="http://jena.sourceforge.net">jena.sourceforge.net</a>
+    <i>linktobedetermined</i>
     for the Jena documentation and downloads. Support for the
     Jena family is provided on the mailing lists
-    <i>jena-dev@yahoogroups.com</i> (for developers using Jena)
-    and <i>jena-devel@lists.sourceforge.net</i> (for developers
-    modifying or extending Jena). Note that, ny support is provided 
+    <i>fixme</i> (for developers using Jena)
+    and <i>fixme</i> (for developers
+    modifying or extending Jena). Note that any support is provided
     on a voluntary basis, as and when the effort is available.
   </p>
 
@@ -130,18 +130,23 @@ java [java options eg classpath and prox
 
   <h3>examples of command-line use</h3>
 
+  <p>
+    We abbreviate <code>java [java options eg classpath and proxy] -jar eyeball-2.4-exec.jar</code>
+    to $sysball below.
+  </p>
+
     <pre>
-java jena.eyeball -version
+$eyeball -version
 
-java jena.eyeball -check myDataFile.rdf
+$eyeball -check myDataFile.rdf
 
-java jena.eyeball -assume dc -check http://example.com/nosuch.n3
+$eyeball -assume dc -check http://example.com/nosuch.n3
 
-java jena.eyeball -assume mySchema.rdf -check myData.rdf -render xml
+$eyeball -assume mySchema.rdf -check myData.rdf -render xml
 
-java jena.eyeball -check myData.rdf -include consistent-type
+$eyeball -check myData.rdf -include consistent-type
 
-java jena.eyeball -check myConfig.ttl -sign &gt;signedConfig.ttl
+$eyeball -check myConfig.ttl -sign &gt;signedConfig.ttl
 </pre>
 
   <h3>-check specialURL+</h3>
@@ -199,12 +204,12 @@ java jena.eyeball -check myConfig.ttl -s
   configuration files to load. A single configuration model is
   constructed as the union of the contents of those files. If this
   option is omitted, the default configuration file
-  <i>etc/eyeball-config.n3</i> is loaded. See <a href=
+  <i>etc/eyeball-config.ttl</i> is loaded. See <a href=
   "#inside-configuration">inside the Eyeball configuration file</a> 
   for details of the configuration file.</p>
   <pre>
--config my-hacked-config-file.n3
--config etc/eyeball-config.n3 extras.ttl
+-config my-hacked-config-file.ttl
+-config etc/eyeball-config.ttl extras.ttl
 </pre>
 
   <p>The <i>-root rootURI</i> option specifies the root resource in
@@ -253,7 +258,7 @@ java jena.eyeball -check myConfig.ttl -s
       (b) your command-line interpreter may treat quotes
       specially, and to allow the quotes to pass through to
       Eyeball, you'll have to use another (different) pair of
-      quotes!
+      quotes.
     </li>
 
     <li>
@@ -390,11 +395,11 @@ java jena.eyeball -check myConfig.ttl -s
   subjects - which are all blank nodes - and lightly prettifying
   the predicate and object). To change the rendering style, supply
   the <i>-render</i> option with the name of the renderer as its
-  value. Eyeball comes with N3, XML, and text renderers; the
+  value. Eyeball comes with Turtle, XML, and text renderers; the
   Eyeball config file associates renderer names with their
   classes.</p>
   <pre>
--render n3
+-render ttl
 -render rdf
 </pre>
 

Modified: jena/Scratch/Eyeball/trunk/src/main/java/com/hp/hpl/jena/extras/tools/query/ModelQuery.java
URL: http://svn.apache.org/viewvc/jena/Scratch/Eyeball/trunk/src/main/java/com/hp/hpl/jena/extras/tools/query/ModelQuery.java?rev=1405763&r1=1405762&r2=1405763&view=diff
==============================================================================
--- jena/Scratch/Eyeball/trunk/src/main/java/com/hp/hpl/jena/extras/tools/query/ModelQuery.java (original)
+++ jena/Scratch/Eyeball/trunk/src/main/java/com/hp/hpl/jena/extras/tools/query/ModelQuery.java Mon Nov  5 12:10:29 2012
@@ -21,27 +21,36 @@ package com.hp.hpl.jena.extras.tools.que
 import java.util.*;
 
 import com.hp.hpl.jena.graph.Node;
-import com.hp.hpl.jena.graph.query.Query;
+import com.hp.hpl.jena.graph.Triple;
+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.QuerySolution;
+import com.hp.hpl.jena.query.ResultSet;
 import com.hp.hpl.jena.rdf.model.*;
 import com.hp.hpl.jena.shared.JenaException;
+import com.hp.hpl.jena.sparql.core.Var;
+import com.hp.hpl.jena.sparql.syntax.ElementGroup;
 import com.hp.hpl.jena.util.iterator.ExtendedIterator;
+import com.hp.hpl.jena.util.iterator.NiceIterator;
 
 /**
-    A ModelQuery object holds a collection of (S P O) query triples. Each of the
-    S P O nodes can be an ordinary Model RDFNode or a QueryVariable.
-    When the ModelQuery is run over some Model, it returns a sequence of
-    results; each result (a List) can be supplied to a Queryariable to extract
-    the underlying result binding.
+    A ModelQuery wraps an ARQ query (for historical reasons).
     
     @author kers
 */
 public class ModelQuery
-    {
+    {	
     /**
         Factory method to create new ModelQuery objects.
     */
     public static ModelQuery create()
-        { return create( QueryFactory.usual ); }
+        { return new ModelQuery(); }
+    
+    
+    public ModelQuery() {
+    	query.setQuerySelectType();
+    }
     
     /**
         Factory method to create a new, distinct QueryVariable for this ModelQuery.
@@ -73,24 +82,13 @@ public class ModelQuery
     */
     public ModelQuery add( RDFNode S, RDFNode P, RDFNode O )
         {
-        query.addMatch( translate( S ), translate( P ), translate( O ) );
+        Triple t = new Triple( translate( S ), translate( P ), translate( O ) );
+		triples.add( t );
+        eg.addTriplePattern( t );
         return this;
         }
 
     /**
-        Factory method to create new ModelQuery objects with specialised
-        embedded Query objects - exposed for testing purposes only.
-    */
-    public static ModelQuery create( QueryFactory qf )
-        { return new ModelQuery( qf ); }
-
-    /**
-        Constructor for ModelQuery objects: initialise with the QueryFactory.
-    */
-    protected ModelQuery( QueryFactory qf )
-        { query = qf.create(); }
-
-    /**
          Add a new (S P O) query triple pattern specified by <code>s</code>. Really
          for testing purposes: note that it is not possible to beuild a statement with
          a QueryVariable as a property (a type inconvenience).
@@ -110,7 +108,7 @@ public class ModelQuery
             QueryVariable qv = ((QueryVariable) s);
             if (qv.parent() != this) 
                 throw new JenaException( "this query variable doesn't belong in this ModelQuery" );
-            return Node.createVariable( qv.getId().toString() );
+            return Var.alloc( qv.getId().toString() );
             }
         else
             return s.asNode();
@@ -122,24 +120,41 @@ public class ModelQuery
     */
     public ExtendedIterator<? extends List<Node>> run( Model data )
         {
-        Node [] vars = variables.toArray( new Node[variables.size()] );
-        return query.executeBindings( data.getGraph(),  vars );
+    	query.setQueryPattern( eg );        
+        for (Node var: variables) query.addResultVar( var );
+    //
+        QueryExecution qx = QueryExecutionFactory.create( query, data );
+        ResultSet rs = qx.execSelect();
+    //
+        List<List<Node>> rows = new ArrayList<List<Node>>();
+        while (rs.hasNext()) 
+        	{
+        	QuerySolution qs = rs.nextSolution();
+        	List<Node> row = new ArrayList<Node>();
+        	for (Node v: variables) row.add( qs.get( v.getName() ).asNode() );
+        	rows.add( row );
+        	}
+        qx.close();
+    //
+        return new NiceIterator<List<Node>>().andThen( rows.iterator() );
         }
 
     /**
         Public for testing purposes only. This bit might go away.
     */
-    public final Query query;
+    public final Query query = new Query();
+    
+    final ElementGroup eg = new ElementGroup();
 
     private List<Node> variables = new ArrayList<Node>();
     
+    private List<Triple> triples = new ArrayList<Triple>();
+    
+    public List<Triple> getTriples()
+    	{ return triples; }
+    
+    public List<Node> getVariables() 
+    	{ return variables; }
+    
     private int index = 0;
-
-    public interface QueryFactory
-        {
-        public Query create();
-        
-        public static final QueryFactory usual = new QueryFactory()
-            { public Query create() { return new Query(); } };
-        }
     }

Modified: jena/Scratch/Eyeball/trunk/src/test/java/com/hp/hpl/jena/extras/tools/query/test/TestModelQuery.java
URL: http://svn.apache.org/viewvc/jena/Scratch/Eyeball/trunk/src/test/java/com/hp/hpl/jena/extras/tools/query/test/TestModelQuery.java?rev=1405763&r1=1405762&r2=1405763&view=diff
==============================================================================
--- jena/Scratch/Eyeball/trunk/src/test/java/com/hp/hpl/jena/extras/tools/query/test/TestModelQuery.java (original)
+++ jena/Scratch/Eyeball/trunk/src/test/java/com/hp/hpl/jena/extras/tools/query/test/TestModelQuery.java Mon Nov  5 12:10:29 2012
@@ -46,7 +46,7 @@ import com.hp.hpl.jena.extras.tools.quer
 
 @RunWith(JUnit4.class) public class TestModelQuery
     {   
-    private ModelQuery mq = ModelQuery.create( createSpecialQuery );
+    private ModelQuery mq = ModelQuery.create();
     
     private static Model empty = ModelFactory.createDefaultModel();
     /**
@@ -131,8 +131,8 @@ import com.hp.hpl.jena.extras.tools.quer
         mq.add( resource( "a" ), B, resource( "b" ) );
         mq.add( resource( "h" ), property( "p" ), C );
         mq.run( model( "" ) );
-        Node [] variables = getQuery( mq ).variables;
-        assertEquals( mq.translate( A ), variables[0] );
+        List<Node> variables = mq.getVariables();
+        assertEquals( mq.translate( A ), variables.get(0) );
         }
     
     @Test public void testVariables()
@@ -212,34 +212,9 @@ import com.hp.hpl.jena.extras.tools.quer
         { return Arrays.asList( ModelTestBase.tripleArray( string ) ); }
 
     private List<Triple> getTriples( ModelQuery mq )
-        { return getQuery( mq ).triples; }
-
-    private SpecialQuery getQuery( ModelQuery mq )
-        { return (SpecialQuery) mq.query; }
+        { return mq.getTriples(); }
 
     private Model model( String facts )
         { return ModelTestBase.modelWithStatements( facts ); }    
-    
-    private static class SpecialQuery extends Query
-        {
-        public List<Triple> triples = new ArrayList<Triple>();
-        public Node [] variables = null;
-        
-        public ExtendedIterator<Domain> executeBindings( Graph g, Node [] variables )
-            {
-            this.variables = variables;
-            return super.executeBindings( g, variables );
-            }
-        
-        public Query addMatch( Node S, Node P, Node O )
-            {
-            triples.add( Triple.create( S, P, O ) );
-            return super.addMatch( S, P, O );
-            }
-        }
-    
-    private static ModelQuery.QueryFactory createSpecialQuery =
-        new ModelQuery.QueryFactory() 
-            { public Query create() { return new SpecialQuery(); }};
-        
+
     }