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