我在 Java 中使用 TopBraid 作为 IDE 和 Jena。对于同一个 SPARQL 查询和同一个文件,我得到两个不同的结果集。本体可以在这里找到,https://dl.dropboxusercontent.com/u/108022472/ontology.owl
SPARQL 是:
select ?individual ?type ?label where {
?individual rdf:type ?type .
?individual rdfs:label ?label
filter (?type in (wo:Kingdom))
}
我的 Java 代码:
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;
}
}
耶拿代码有问题吗?使用 topbraid,结果很好,而使用 Jena,结果是错误的。
结果应该是:
| wo:王国 | 《动物》 | | | wo:王国 | “动物”
但是对于耶拿,它返回一组类型不正确的结果