我使用 Apache Jena 库在 Java 中创建了一个本体模型,然后我输入了披萨本体。我正在尝试进行 sparql 查询,但表格打印为空白,尽管我的查询通常有答案。难道我做错了什么...?这是代码:
OntModel model = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_MICRO_RULE_INF);
String inputFileName="pizza.owl";
InputStream in = FileManager.get().open( inputFileName );
if (in == null) {
throw new IllegalArgumentException(
"File: " + inputFileName + " not found");
}
model.read(in, null);
String queryString =
"prefix pizza: <www.co-ode.org/ontologies/pizza/pizza.owl#Pizza> "+
"prefix rdfs: <" + RDFS.getURI() + "> " +
"prefix owl: <" + OWL.getURI() + "> " +
"select ?pizza where {?pizza a owl:Class ; " +
"rdfs:subClassOf ?restriction. " +
"?restriction owl:onProperty pizza:hasTopping ;" +
"owl:someValuesFrom pizza:PeperoniSausageTopping" +
"}";
Query query = QueryFactory.create(queryString);
QueryExecution qe = QueryExecutionFactory.create(query, model);
com.hp.hpl.jena.query.ResultSet results = qe.execSelect();
ResultSetFormatter.out(System.out, results, query);
qe.close();