jena 简单查询(不带推理,直接读取owl文件)

 //用的是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();
              
        }  
  
    }  

  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值