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> |
---------------------------------------------------------------------------------