On 21/04/15 21:17, Alan Wu wrote:
Hi Andy,

Thanks. Is it fair/accurate to say that the Jena's in memory datasets
simply ignore the FROM (s) or FROM NAMED (s) portion of a SPARQL query?

No.

QueryExecution qexec = QueryExecutionFactory.create(query) ;

works.

        Andy


Zhe

On 4/21/2015 12:47 PM, Andy Seaborne wrote:
Zhe,

Accessing a specific graph is properly done with GRAPH in SPARQL.

FROM / FROM NAMED is a mechanism to describe the dataset to be
queried. How that description is realised is left open - not all
SPARQL engines are on the web so HTTP GET URLs does not work; reading
a large remote graph for one query is expensive; remote graphs may not
be available.

The description is a temporary overlay in TDB; in memory, the presence
of the already constructed dataset overrides the FROM in the query
which would normally read from those 404 URLs.  For the in-memory
datasets, it is assumed you have created the right one from what ever
graph the app has around.  TDB, being a large persistent store,
doesn't permit that.

The spec provides for the description of datasets.  It does not cover
API details of what happens when multiple choices are provided (the
protocol does - but this isn't the protocol).

    Andy

PS Usage questions are best sent to [email protected] and you'll
likely get advice from other users are as well.

On 21/04/15 17:48, Alan Wu wrote:
Hi Andy,

Not sure I am following here. Are you implying one of those two
implementations is not
conforming to the SPEC? Or the SPEC allows implementations some freedom
in this case?

Thanks,

Zhe

On 4/21/2015 9:40 AM, Andy Seaborne wrote:
On 21/04/15 17:34, Alan Wu wrote:
Hi Andy,

Thanks for your quick response. Will take a look at DynamicDatasets.

Back to the original question, we have two DatasetGraph instances (one
implemented with DatasetGraphMaker
and the other with TDB) and they behave differently. Feels like a bug.

That's because you are better off using GRAPH.

GRAPH <http://example.org/test/> {
   { SELECT DISTINCT  ?subclass ?superclass
      WHERE  {
                 ?subclass rdfs:subClassOf ?superclass
             }
    }
}

or

{ SELECT DISTINCT  ?subclass ?superclass
      WHERE  {
         GRAPH <http://example.org/test/> {
                 ?subclass rdfs:subClassOf ?superclass }
             }
    }

However, you and the Jena dev team are the ultimate judge :)

The SPARQL spec is.

    Andy


Thanks,

Zhe

On 4/21/2015 9:20 AM, Andy Seaborne wrote:
On 21/04/15 17:08, Alan Wu wrote:
Hi Andy,

Thanks for your response.

Hmmm. In that Java code, if a TDB instance is used instead, the
query
results are different.

You didn't mention TDB.


     DatasetGraph ds = TDBFactory.createDatasetGraph("/tmp/tdb");
     RDFDataMgr.read(ds, new FileInputStream(szFile), Lang.NQUADS);

     Query query = QueryFactory.create(szQuery, Syntax.syntaxARQ);
     QueryExecution qexec = QueryExecutionFactory.create(query,
DatasetImpl.wrap(ds));
     ResultSet results = qexec.execSelect();

Got this answer both tiny.queryand tiny.query1
-------------------------------------------------------------------------



| subclass                         |
superclass                         |
=========================================================================



| <http://example.org/test#A_node> |
<http://example.org/test#Property> |
-------------------------------------------------------------------------




TDB does not read from the web.  It uses the named graphs in the
dataset as the pool from which to set up a temporary dynamic dataset.

http://jena.apache.org/documentation/tdb/dynamic_datasets.html

You can build an in-memory dataset like TDB does if you want. See
class "DynamicDatasets".

Using GRAPH will act the same in TDB and memory datasets and is more
flexible.  And faster.

    Andy


Thanks,

Zhe

On 4/21/2015 1:42 AM, Andy Seaborne wrote:
Hi Zhe,

Looks fine to me.  What answers did you expect?

FROM does not apply if the data is directly provided.
(If it did, it would read those URLs which are not RDF content)

Did you mean GRAPH?

    Andy

PS no need to code:
Change the extensions on files to the standards registered ones

tiny.nquads =. tiny.nq
tiny.query => tiny.rq
tiny1.query => tiny1.rq

and then ...

java -cp ... arq.sparql --data tiny.nq --query tiny.query

On 21/04/15 00:51, Alan Wu wrote:
Hi All,

Here is the test case (data in N-QUADS, two simple SPARQL queries,
and a
test Java code) that my colleague Miriam constructed.
Both queries seem to return incorrect results. We have tried Jena
2.11.1
libraries, 2.12.1, and 2.13.
They all have the same behavior as far as this test case goes.

Thanks,

Zhe

% cat tiny.nquads
<http://www.w3.org/2002/07/owl#Nothing>
<http://www.w3.org/2000/01/rdf-schema#subClassOf>
<http://example.org/test#A_node>
<http://example.org/test/ClassEntailments> .

<http://example.org/test#Something>
<http://www.w3.org/2000/01/rdf-schema#subClassOf>
<http://example.org/test#Something>
<http://example.org/test/ClassEntailments> .

<http://example.org/test#A_node>
<http://www.w3.org/2000/01/rdf-schema#subClassOf>
<http://example.org/test#Property> <http://example.org/test/> .

<http://example.org/test#A_node>
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
<http://www.w3.org/2002/07/owl#Class> <http://example.org/test/> .


% cat tiny.query
PREFIX  rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?subclass ?superclass
*FROM <http://example.org/test/> *
WHERE {
     { SELECT DISTINCT  ?subclass ?superclass
       WHERE  {
                  ?subclass rdfs:subClassOf ?superclass
              }
     }
}


% cat tiny.query1
PREFIX  rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?subclass ?superclass
*FROM NAMED <http://example.org/test/> *
WHERE {
     { SELECT DISTINCT  ?subclass ?superclass
       WHERE  {
                  GRAPH ?g { ?subclass rdfs:subClassOf
?superclass }
              }
     }
}


% cat MyTest.java
import java.util.*;
import java.io.*;
import org.apache.jena.riot.Lang;
import org.apache.jena.riot.RDFDataMgr;
import com.hp.hpl.jena.query.*;
import com.hp.hpl.jena.sparql.core.*;
import com.hp.hpl.jena.graph.*;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.util.FileManager;
import com.hp.hpl.jena.util.iterator.*;
import com.hp.hpl.jena.sparql.core.DatasetImpl;

public class MyTest
{
   static final boolean ms_bDebug = !
"false".equals(System.getProperty("debug"));
   public static void debug(String s)
   {
     if (ms_bDebug) {
       System.err.println(s);
     }
   }

   public static void main(String[] szArgs) throws Exception
   {
     String szFile = szArgs[0];
     String szQuery = readFileIntoString(szArgs[1]);

     DatasetGraph ds  = RDFDataMgr.loadDatasetGraph(szFile,
Lang.NQUADS);
     debug("DatasetGraph ds " + ds.getClass().getName());
     Query query = QueryFactory.create(szQuery, Syntax.syntaxARQ);
     QueryExecution qexec = QueryExecutionFactory.create(query,
DatasetImpl.wrap(ds));
     ResultSet results = qexec.execSelect();
     ResultSetFormatter.out(System.out, results);
   }

   public static String readFileIntoString(String filename)
     throws Exception
   {
     InputStream is = new BufferedInputStream(
         new FileInputStream(filename));
     BufferedReader br = new BufferedReader(new
InputStreamReader(is));
     StringBuffer sb = new StringBuffer();

     try {
       String line = null;
       while ( (line = br.readLine()) != null) {
         sb.append(" ").append(line);
       }
     }
     finally {
       if (br != null) br.close();
     }

     return sb.toString();
   }
}


% java -cp ./lib/'*':./ MyTest tiny.nquads tiny.query
DatasetGraph ds com.hp.hpl.jena.sparql.core.DatasetGraphMaker
-------------------------
| subclass | superclass |
=========================
-------------------------


% java -cp ./lib/'*':./ MyTest tiny.nquads tiny.query1
DatasetGraph ds com.hp.hpl.jena.sparql.core.DatasetGraphMaker
---------------------------------------------------------------------------------





| subclass                                |
superclass                          |
=================================================================================





| <http://example.org/test#Something>     |
<http://example.org/test#Something> |
| <http://www.w3.org/2002/07/owl#Nothing> |
<http://example.org/test#A_node>    |
| <http://example.org/test#A_node>        |
<http://example.org/test#Property>  |
---------------------------------------------------------------------------------
















Reply via email to