以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 Semantic Web(语义Web)/描述逻辑/本体 』  (http://bbs.xml.org.cn/list.asp?boardid=2)
----  关于sparql查询的问题  (http://bbs.xml.org.cn/dispbbs.asp?boardid=2&rootid=&id=90297)


--  作者:ehuangjiazi
--  发布时间:4/11/2011 11:29:00 AM

--  关于sparql查询的问题

把代码改了一下
import com.hp.hpl.jena.rdf.model.*;
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;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.ResultSetFormatter;
import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.reasoner.*;
public class Animal{
  public static void main(String[] args) {
    OntModel text_ontmodel = ModelFactory.createOntologyModel();
       OntDocumentManager dm = text_ontmodel.getDocumentManager();
       dm.addAltEntry("http://www.owl-ontologies.com/Ontology1299637864.owl#","file:" + "Animal.owl");
       text_ontmodel.read("file:E:/Program Files/Protege_3.4.4/Animal.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 xsd:<http://www.w3.org/2001/XMLSchema#string>"+
                    "PREFIX eg:<http://www.owl-ontologies.com/Carnivore.owl#>"
                    ;
       String slect =  "SELECT ?x ";
       String where =   "WHERE {"+
       "?x rdfs:subClassOf eg:Carnivore"+
       "}";

       Query query = QueryFactory.create(prefix + slect + where);
       Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
       InfModel inf = ModelFactory.createInfModel(reasoner, text_ontmodel);
       QueryExecution qe = QueryExecutionFactory.create(query,inf);
       ResultSet results = qe.execSelect();
       ResultSetFormatter.out(System.out,results,query);
       qe.close();
  }
}
然后显示的是


-----
| x |
=====
-----



我想问一下,为什么出来的不是Carnivore类下面的子类呢?只显示字段名称。。

还有一个问题想问一下,就是可以附加图吗?就是在owl文件里面可以有图吗?查询的时候可以查出来的。


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
62.500ms