问题
I'm using TopBraid as IDE and Jena in Java. For the same SPARQL query and same file, I'm getting two different result sets. The ontology can be found here, https://dl.dropboxusercontent.com/u/108022472/ontology.owl
The SPARQL is:
select ?individual ?type ?label where {
?individual rdf:type ?type .
?individual rdfs:label ?label
filter (?type in (wo:Kingdom))
}
My Java Code:
public class ExeSparql {
static String prefix = "PREFIX owl: <http://www.w3.org/2002/07/owl#> " +
"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> " +
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> " +
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " +
"PREFIX dbpedia-owl: <http://dbpedia.org/ontology/> " +
"PREFIX : <http://dbpedia.org/resource/> " +
"PREFIX dbpedia2: <http://dbpedia.org/property/> " +
"PREFIX wo:<http://purl.org/ontology/wo/>" +
"PREFIX dbpedia: <http://dbpedia.org/> ";
public static ResultSet execute(String queryString){
queryString = prefix + queryString;
Model model = null;
try {
InputStream in = new FileInputStream(new File("/home/noor/TBCMEWorkspace/recreate/index.rdf"));
// Create an empty in-memory model and populate it from the graph
model = ModelFactory.createOntologyModel();
model.read(in,null); // null base URI, since model URIs are absolute
in.close();
} catch (IOException e) {
e.printStackTrace();
}
Query query = QueryFactory.create(queryString);
// Execute the query and obtain results
QueryExecution qe = QueryExecutionFactory.create(query, model);
ResultSet results = qe.execSelect();
ResultSetFormatter.out(System.out, results, query);
//qe = QueryExecutionFactory.create(query, model);
//results = qe.execSelect();
return results;
}
}
Is there any problem with the Jena code? Using topbraid, the results is fine, while with Jena, the result is wrong.
The result should have been:
| wo:Kingdom | "Animals" | | | wo:Kingdom | "animalia"
But with Jena, its returning a set of results with incorrect types
回答1:
I've tried this query with the data that you provided (I had to add the prefixes):
prefix wo: <http://purl.org/ontology/wo/>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
select ?individual ?type ?label where {
?individual rdf:type ?type .
?individual rdfs:label ?label
filter (?type in (wo:Kingdom))
}
I ran the query using Jena's command line arq with the following results:
$ arq --query query.sparql --data ontology.owl
-------------------------------------------------------------------
| individual | type | label |
===================================================================
| <file:/nature/life/Animal#kingdom> | wo:Kingdom | "Animals" |
| <file:/nature/kingdom/Animal#kingdom> | wo:Kingdom | "animalia" |
-------------------------------------------------------------------
The version of Jena (2.10.0) and ARQ (2.10.0) are as follows:
$ arq --version
Jena: VERSION: 2.10.0
Jena: BUILD_DATE: 2013-02-20T12:04:26+0000
ARQ: VERSION: 2.10.0
ARQ: BUILD_DATE: 2013-02-20T12:04:26+0000
来源:https://stackoverflow.com/questions/16990478/same-sparql-with-different-result-using-different-programs