我有一个我在TopBraid中加载的RDF文件,我还从网上导入了一些RDF文件。最后,我保存了基本文件并检查其代码以确保它包含import语句。
<owl:Ontology rdf:about="">
<owl:imports rdf:resource="http://www.bbc.co.uk/nature/life/Bird"/>
<owl:imports rdf:resource="http://www.bbc.co.uk/nature/life/Animal"/>
<owl:imports rdf:resource="http://www.bbc.co.uk/nature/life/Chordate"/>
<owl:imports rdf:resource="http://www.bbc.co.uk/nature/kingdom"/>
</owl:Ontology>
那么,那个文件,当我执行下面的sparql时,我得到了结果:
PREFIX wo:<http://purl.org/ontology/wo/>
SELECT *
WHERE {
?subject wo:kingdom ?object .
}
然而,当我和Jena使用相同的文件时,我没有得到任何结果,似乎Jena没有考虑进口:
// Open the bloggers RDF graph from the filesystem
InputStream in = new FileInputStream(new File("/home/noor/TBCMEWorkspace/bbc/index.rdf"));
// Create an empty in-memory model and populate it from the graph
Model model = ModelFactory.createMemModelMaker().createFreshModel();
model.read(in,null); // null base URI, since model URIs are absolute
in.close();
// Create a new query
String queryString = "PREFIX wo:<http://purl.org/ontology/wo/>" +
" SELECT * " +
" WHERE { " +
" ?subject ?x ?object . " +
" } ";
Query query = QueryFactory.create(queryString);
// Execute the query and obtain results
QueryExecution qe = QueryExecutionFactory.create(query, model);
ResultSet results = qe.execSelect();
// Output query results
ResultSetFormatter.out(System.out, results, query);
// Important - free up resources used running the query
qe.close();
有没有办法让Jena考虑进口?
答案 0 :(得分:2)
普通的Jena模型不会加载导入的OWL模型,但会加载OntModel。基本的Jena模型用于处理RDF(即包括OWL,但也包括RDF的其他用途),而本体API中的OntModel
专门用于处理OWL和其他本体。