以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 Semantic Web(语义Web)/描述逻辑/本体 』  (http://bbs.xml.org.cn/list.asp?boardid=2)
----  本体中添加子类后jena中查询没结果  (http://bbs.xml.org.cn/dispbbs.asp?boardid=2&rootid=&id=121524)


--  作者:2010JLJ
--  发布时间:9/14/2011 3:20:00 PM

--  本体中添加子类后jena中查询没结果
public void test2(){
 OntModel student_ontModel1 = ModelFactory.createOntologyModel();
 OntDocumentManager dm1 = student_ontModel1.getDocumentManager();
 dm1.addAltEntry("http://www.owl-ontologies.com/OntologyStudent.owl", "file:"+"2011.9.5.rdf-xml.owl");
 student_ontModel1.read("file:D:/Program Files/Protege_3.4.5/2011.9.5.rdf-xml.owl");
 
 String prefix = "PREFIX owl:<http://www.w3.org/2002/07/owl#>"+
 "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>"+
 "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>"+
 "PREFIX base:<http://www.owl-ontologies.com/OntologyStudent.owl#>";
 String select = "select ?sub ";
 String where = " where{?sub base:subClassOf base:Student"  +
   "}";//原来的本体中有Student类,其个体也可查   询,但是添加子类及子类的个体以后,这里就查不出来了,也没有错误提示,但在protege中直接用Sparql查询却可以得到想要的结果。请大家指点 Query query1=QueryFactory.create(prefix + select + where);
 QueryExecution qe1 = QueryExecutionFactory.create(query1, student_ontModel1);
 ResultSet results1 = qe1.execSelect();
 System.out.print(prefix+select+where+"\n");
    while(results1.hasNext()){
     QuerySolution qs = results1.nextSolution();
                System.out.print(qs.get("sub").toString());
     System.out.print("\t");
     System.out.print("Student");
                System.out.print("\n");
        }
    qe1.close();
}
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms