//用的是protege 里面的people demo
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
public class myOntology {
public static void main(String[] args) {
// String owlpath = "F:\\Ontology1385473236444.owl";
// 创建一个本体模型,这里使用的是前一段时间设计的IIPO本体,附带实例。
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
model.read("file:F:\\Ontology1385473236444.owl");
// 创建一个查询语句
String prefix="PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>"+
"PREFIX xsd:<http://www.w3.org/2000/10/XMLSchema#>"+
"PREFIX owl:<http://www.w3.org/2002/07/owl#>"+
"PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>"+
"PREFIX base:<http://www.project.com/d2o_owl>"+
"PREFIX iqas:<http://owl.man.ac.uk/2006/07/sssw/people#>";
String strquery="ASK {iqas:Mick iqas:drives iqas:Q123_ABC }";
//" WHERE { iqas:Com1 rdf:type ?subject}";
Query query=QueryFactory.create(prefix+strquery);
// 创建一个查询
// 执行查询,获得结果
QueryExecution qe = QueryExecutionFactory.create(query, model);
//ResultSet results = qe.execSelect();//select 类型
boolean results = qe.execAsk() ;//ASK类型
// 向控制台输出结果s
//ResultSetFormatter.out(System.out, results, query);//select
System.out.println(results);//ask
// 释放资源
qe.close();
}
}
jena 简单查询(不带推理,直接读取owl文件)
最新推荐文章于 2024-05-18 09:30:14 发布