-1

我有使用 Protege 创建的本体文件。对于我的 java 应用程序,我需要检索类及其属性。我尝试了以下代码,但它只检索三元组。我是 Jena Api 和 Ontology 的新手,所以请帮忙

   String URI = "http://www.semanticweb.org/ontologies/2012/0/SBIRS.owl";
   String inputFileName = "D:\\SBIRS.owl";
   System.out.println("File Name" + inputFileName);
   OntModel model = ModelFactory.createOntologyModel();
   StmtIterator si=model.listStatements();
   ResIterator iter=model.listSubjects();
   while(iter.hasNext())
   {
       Resource res=iter.nextResource();
       System.out.println("Property==>" + res.getProperty(null).toString());
       System.out.println("Resource URI==>" + res.getURI());

   }
4

1 回答 1

2

要列出 中的类OntModel,请使用listClasses方法。从该方法返回的每个结果都将是 Java 类的一个实例OntClass,它提供了对定义该类的底层模型的三元组的方便访问。

当您说您需要检索“类及其属性”时,您可能意味着两件事:表示类的 RDF 资源的 RDF 属性,或者通常与类实例一起使用的属性。在第一种情况下,您可以通过 API 获得这些OntClass(及其 Java 超类,例如Resource)。在第二种情况下,您需要阅读此操作指南

于 2012-01-27T08:58:54.713 回答