当前位置: 首页 > 知识库问答 >
问题:

由Jena创建的OWL文件在Protege中不打开

任元青
2023-03-14
import java.io.*;
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.*;

public class Create_Ontology extends Object{ 
      public static void main (String args[]) {

         String NS = "http://localhost/new/";
         OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
         String tempst=NS+"#";
         m.setNsPrefix("new", tempst);

        String a= "Information";
        String b= "Book Information";
        String c= "Food Information";

         // Create a new class named "Information"
              OntClass Info = m.createClass(NS + a); 

        // Create a new class named "Book Information" 
              OntClass BookInfo = m.createClass(NS+b); 

        // Create a new class named "Food Information"
              OntClass FoodInfo = m.createClass(NS + c); 

           Info.addSubClass(BookInfo);
           Info.addSubClass(FoodInfo);

         m.write(System.out);
        try {
              m.write(new FileWriter("C:/wamp/www/new/onto1.owl"),"RDF/XML");
              m.write(new FileWriter("C:/wamp/www/new/onto2.owl"), "N3");         
              } catch (IOException e) {
              e.printStackTrace();
              }

      }
}
<?xml version="1.0" encoding="windows-1252"?>
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:new="http://localhost/new/#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" > 
  <rdf:Description rdf:about="http://localhost/new/Book Information">
    <rdfs:subClassOf rdf:resource="http://localhost/new/Information"/>
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://localhost/new/Food Information">
    <rdfs:subClassOf rdf:resource="http://localhost/new/Information"/>
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://localhost/new/Information">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
  </rdf:Description>
</rdf:RDF>

我试着用protage软件打开它。会打开的。但是,里面没有类可以看到。为了在Protage中查看我生成的本体,我需要在这段代码中更改哪些内容?

共有1个答案

祁刚毅
2023-03-14

您的文件没有本体声明。

添加后:

m.createOntology(NS + "ontology"); // I made up the IRI. It can be any valid IRI

本体现在应该是可读的。我已经用OWL API解析并保存了它(Protege使用的库相同),它看起来如下所示:

Prefix(:=<http://localhost/new/ontology#>)
Prefix(new:=<http://localhost/new/#>)
Prefix(owl:=<http://www.w3.org/2002/07/owl#>)
Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)
Prefix(xml:=<http://www.w3.org/XML/1998/namespace>)
Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)
Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)
Ontology(<http://localhost/new/ontology>
Declaration(Class(<http://localhost/new/Information>))
Declaration(Class(<http://localhost/new/Book%20Information>))
Declaration(Class(<http://localhost/new/Food%20Information>))
SubClassOf(<http://localhost/new/Book%20Information> <http://localhost/new/Information>)
SubClassOf(<http://localhost/new/Food%20Information> <http://localhost/new/Information>)
)
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:new="http://localhost/new/#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#" > 
  <rdf:Description rdf:about="http://localhost/new/Information">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://localhost/new/Food Information">
    <rdfs:subClassOf rdf:resource="http://localhost/new/Information"/>
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://localhost/new/ontology">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Ontology"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://localhost/new/Book Information">
    <rdfs:subClassOf rdf:resource="http://localhost/new/Information"/>
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
  </rdf:Description>
</rdf:RDF>
<?xml version="1.0"?>
<rdf:RDF xmlns="http://localhost/new/ontology#"
     xml:base="http://localhost/new/ontology"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:owl="http://www.w3.org/2002/07/owl#"
     xmlns:xml="http://www.w3.org/XML/1998/namespace"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
    <owl:Ontology rdf:about="http://localhost/new/ontology"/>
    <owl:Class rdf:about="http://localhost/new/Information"/>
    <owl:Class rdf:about="http://localhost/new/Book%20Information">
        <rdfs:subClassOf rdf:resource="http://localhost/new/Information"/>
    </owl:Class>
    <owl:Class rdf:about="http://localhost/new/Food%20Information">
        <rdfs:subClassOf rdf:resource="http://localhost/new/Information"/>
    </owl:Class>
</rdf:RDF>
 类似资料:
  • 我在PHP中使用fputcsv创建了一个CSV文件。文件创建成功,我可以在MacOS中打开文件,没有问题。(我在MacOS中使用数字)。问题是在微软的Excel中,它将所有行显示为合并的一列。 我在代码中将分隔符设置为“;”。 当我按照Microsoft文档中的说明检查语言和区域设置时,分隔符也是“;”。 我还应该检查什么?非常感谢。

  • GreatNewUpperOntology正确导入,但显示的名称如下: Untitle-Ontology-93(http://www.semanticweb.org/myname/ontologies/2014/9/Untitle-Ontology-93) 问题:有没有一种方法让我把我的本体保存到SemanticWeb.org站点,使用我在自己的计算机上给文件起的描述性名称,例如“GreatNew

  • 我使用Protégé“Open from URL”下载了dron本体。在它的.owl文件中只是一系列URL,Protégé使用这些URL从Internet加载它们。我正在保存这个项目,但是唯一保存的是原始文件(包含URL的文件),而且每次我都应该从互联网上获取所有的数据。我应该怎么做才能将完整的文件保存到我的计算机磁盘上呢?

  • 在 Dreamweaver 中创建、打开、编辑、保存和恢复文件。创建模板并打开相关的文件。 Dreamweaver 为处理各种 Web 文档提供灵活的环境。除了 HTML 文档以外,您还可以创建和打开各种基于文本的文档 - 如 JavaScript、PHP 和层叠样式表 (CSS)。 Dreamweaver 为创建新文档提供了几种选项。您可以创建以下任意文档: 新的空白文档或模板 基于 Dream

  • 我使用的是Protege OWL API 4.3(OWL API 3.4.2)。它安装了HermiT Reasoner插件。 我的问题是,无论我对推理器有什么查询,都没有输出,它没有提供任何实例。 这就是我的本体的样子: 干杯,S。