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

用Jena读取Protege本体文件时如何处理错误?

萧明贤
2023-03-14

我正在尝试阅读一个在Protege4上手动设计的本体,以便在Eclipse中用Jena更新它。现在简单地说,我只想从文件中读取本体,并将内容打印回控制台。

package soctrace;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.InputStreamReader;

import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.ProfileRegistry;
import com.hp.hpl.jena.rdf.model.ModelFactory;

public class Intology {

    static String xmlbase = "http://www.soctrace.org/ontologies/#";
    static String ontopath = "./ontologies/tima.owl";

    public static void main(String[] args) throws FileNotFoundException {

        manageOntologies();
    }

    public static void manageOntologies() throws FileNotFoundException{
        OntModel domainModel =ModelFactory.createOntologyModel(ProfileRegistry.OWL_DL_LANG);
        domainModel.read((new FileInputStream(ontopath)), null);        
    model.write(System.out);
    }   
}

本体文件如下所示:

<?xml version="1.0"?>
<!DOCTYPE Ontology [
    <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
    <!ENTITY xml "http://www.w3.org/XML/1998/namespace" >
    <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
    <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
]>
<Ontology xmlns="http://www.w3.org/2002/07/owl#"
     xml:base="http://www.soctrace.org/ontologies/tima.owl"
 xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 xmlns:xml="http://www.w3.org/XML/1998/namespace"
 ontologyIRI="http://www.soctrace.org/ontologies/tima.owl">
<Prefix name="xsd" IRI="http://www.w3.org/2001/XMLSchema#"/>
<Prefix name="owl" IRI="http://www.w3.org/2002/07/owl#"/>
<Prefix name="" IRI="http://www.w3.org/2002/07/owl#"/>
<Prefix name="rdf" IRI="http://www.w3.org/1999/02/22-rdf-syntax-ns#"/>
<Prefix name="rdfs" IRI="http://www.w3.org/2000/01/rdf-schema#"/>
<Annotation>
    <AnnotationProperty abbreviatedIRI=":versionInfo"/>
    <Literal datatypeIRI="&xsd;string">cette version est la promiere</Literal>
</Annotation>
<Annotation>
    <AnnotationProperty abbreviatedIRI="rdfs:comment"/>
    <Literal datatypeIRI="&xsd;string">Cette ontologie est construite pour gerer les traces de TIMA. dans un premier temps nous allons seulement considerer que les evenements sont les elements les plus interessants a regarder, puis nous allons fournir l&#39;ontologie au gré des attentes.</Literal>
</Annotation>
<Declaration>
    <Class IRI="#Event"/>
</Declaration>
<Declaration>
    <Class IRI="#EventDuration"/>
</Declaration>
<Declaration>
    <Class IRI="#EventType"/>
</Declaration>
<Declaration>
    <Class IRI="#ValuePartition"/>
</Declaration>
<SubClassOf>
    <Class IRI="#Event"/>
    <Class abbreviatedIRI=":Thing"/>
</SubClassOf>
<SubClassOf>
    <Class IRI="#EventDuration"/>
    <Class IRI="#ValuePartition"/>
</SubClassOf>
<SubClassOf>
    <Class IRI="#EventType"/>
    <Class IRI="#ValuePartition"/>
</SubClassOf>

但在运行时,我遇到了以下错误:

 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 18 column 64): {W136} Relative URIs are not permitted in RDF: specifically <ontologyIRI>
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 18 column 64): {W102} Unqualified property attributes are not allowed. Property treated as a relative URI.
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 19 column 65): {W136} Relative URIs are not permitted in RDF: specifically <name>
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 19 column 65): {W102} Unqualified property attributes are not allowed. Property treated as a relative URI.
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 19 column 65): {W136} Relative URIs are not permitted in RDF: specifically <IRI>
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 19 column 65): {W102} Unqualified property attributes are not allowed. Property treated as a relative URI.
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 20 column 62): {W136} Relative URIs are not permitted in RDF: specifically <name>
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 20 column 62): {W102} Unqualified property attributes are not allowed. Property treated as a relative URI.
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 20 column 62): {W136} Relative URIs are not permitted in RDF: specifically <IRI>
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 20 column 62): {W102} Unqualified property attributes are not allowed. Property treated as a relative URI.
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 21 column 59): {W136} Relative URIs are not permitted in RDF: specifically <name>
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 21 column 59): {W102} Unqualified property attributes are not allowed. Property treated as a relative URI.
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 21 column 59): {W136} Relative URIs are not permitted in RDF: specifically <IRI>
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 21 column 59): {W102} Unqualified property attributes are not allowed. Property treated as a relative URI.
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 22 column 75): {W136} Relative URIs are not permitted in RDF: specifically <name>
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 22 column 75): {W102} Unqualified property attributes are not allowed. Property treated as a relative URI.
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 22 column 75): {W136} Relative URIs are not permitted in RDF: specifically <IRI>
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 22 column 75): {W102} Unqualified property attributes are not allowed. Property treated as a relative URI.
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 23 column 70): {W136} Relative URIs are not permitted in RDF: specifically <name>
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 23 column 70): {W102} Unqualified property attributes are not allowed. Property treated as a relative URI.
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 23 column 70): {W136} Relative URIs are not permitted in RDF: specifically <IRI>
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 23 column 70): {W102} Unqualified property attributes are not allowed. Property treated as a relative URI.
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 25 column 60): {W136} Relative URIs are not permitted in RDF: specifically <abbreviatedIRI>
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 25 column 60): {W102} Unqualified property attributes are not allowed. Property treated as a relative URI.
ERROR [main] (RDFDefaultErrorHandler.java:40) - (line 26 column 44): {E201} Multiple children of property element
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 26 column 44): {W136} Relative URIs are not permitted in RDF: specifically <datatypeIRI>
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 26 column 44): {W102} Unqualified property attributes are not allowed. Property treated as a relative URI.
ERROR [main] (RDFDefaultErrorHandler.java:40) - (line 26 column 73): {E202} Expecting XML start or end element(s). String data "cette version est la promiere" not allowed. Maybe there should be an rdf:parseType='Literal' for embedding mixed XML content in RDF. Maybe a striping error.
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 29 column 60): {W136} Relative URIs are not permitted in RDF: specifically <abbreviatedIRI>
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 29 column 60): {W102} Unqualified property attributes are not allowed. Property treated as a relative URI.
 ERROR [main] (RDFDefaultErrorHandler.java:40) - (line 30 column 44): {E201} Multiple children of property element
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 30 column 44): {W136} Relative URIs are not permitted in RDF: specifically <datatypeIRI>
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 30 column 44): {W102} Unqualified property attributes are not allowed. Property treated as a relative URI.
 ERROR [main] (RDFDefaultErrorHandler.java:40) - (line 30 column 258): {E202} Expecting XML start or end element(s). String data "Cette ontologie est construite pour gerer les traces de TIMA. dans un premier temps nous allons seulement considerer que les evenements sont les elements les plus interessants a regarder, puis nous allons fournir l" not allowed. Maybe there should be an rdf:parseType='Literal' for embedding mixed XML content in RDF. Maybe a striping error.
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 33 column 30): {W136} Relative URIs are not permitted in RDF: specifically <IRI>
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 33 column 30): {W102} Unqualified property attributes are not allowed. Property treated as a relative URI.
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 36 column 38): {W136} Relative URIs are not permitted in RDF: specifically <IRI>
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 36 column 38): {W102} Unqualified property attributes are not allowed. Property treated as a relative URI.
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 39 column 34): {W136} Relative URIs are not permitted in RDF: specifically <IRI>
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 39 column 34): {W102} Unqualified property attributes are not allowed. Property treated as a relative URI.
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 42 column 39): {W136} Relative URIs are not permitted in RDF: specifically <IRI>
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 42 column 39): {W102} Unqualified property attributes are not allowed. Property treated as a relative URI.
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 45 column 30): {W136} Relative URIs are not permitted in RDF: specifically <IRI>
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 45 column 30): {W102} Unqualified property attributes are not allowed. Property treated as a relative URI.
 ERROR [main] (RDFDefaultErrorHandler.java:40) - (line 46 column 41): {E201} Multiple children of property element
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 46 column 41): {W136} Relative URIs are not permitted in RDF: specifically <abbreviatedIRI>
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 46 column 41): {W102} Unqualified property attributes are not allowed. Property treated as a relative URI.
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 49 column 38): {W136} Relative URIs are not permitted in RDF: specifically <IRI>
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 49 column 38): {W102} Unqualified property attributes are not allowed. Property treated as a relative URI.
ERROR [main] (RDFDefaultErrorHandler.java:40) - (line 50 column 39): {E201} Multiple children of property element
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 50 column 39): {W136} Relative URIs are not permitted in RDF: specifically <IRI>
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 50 column 39): {W102} Unqualified property attributes are not allowed. Property treated as a relative URI.
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 53 column 34): {W136} Relative URIs are not permitted in RDF: specifically <IRI>
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 53 column 34): {W102} Unqualified property attributes are not allowed. Property treated as a relative URI.
 ERROR [main] (RDFDefaultErrorHandler.java:40) - (line 54 column 39): {E201} Multiple children of property element
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 54 column 39): {W136} Relative URIs are not permitted in RDF: specifically <IRI>
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 54 column 39): {W102} Unqualified     property attributes are not allowed. Property treated as a relative URI.

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" > 
</rdf:RDF>

共有1个答案

帅锦
2023-03-14

那不是OWL RDF文件。我认为语法是OWL2 XML,这是Jena不支持的。

您应该能够从protege输出一个OWL RDF,或者使用这个在线工具进行转换。

 类似资料:
  • 我试图在Protege3.5中加载一个OWL2.0本体。然而,每次我尝试的时候,它都会给出一个错误。 本体很好,因为当我从Java代码运行它们时,Hermit Reasoner和Pellet Reasoner在它上面工作得很好。你能告诉我为什么会出现错误信息以及如何修复它吗。

  • 这些天来我一直在读关于OWL本体和RDF文件的文章。我还是不能理解这一点。 假设我使用Protege创建了一个简单的本体。它有一个称为Review的类,具有两个数据属性,即comment和rating。 后面的行返回NULL。 这里面有什么问题?

  • 问题内容: 我需要使用Java来读取和处理一些较大的文件,并且我想知道,是否有某种明智的方法来保护文件,使其在我读取和处理文件时不会被其他进程覆盖? 也就是说,可以通过某种方式将其设为只读,使其保持“打开”状态或类似的方式。 这将在Windows环境中完成。 br,Touko 问题答案: 你想要一个FileLock: 为了简单起见,我省略了一个try / finally块,但您不应该在生产代码中使

  • 我试图通过创建一个函数来编写一个简单的文本文件阅读器,该函数接受文件的路径并将每行文本转换为char数组,但它不起作用。 这里出了什么问题? 从以前的修订版更改了一点代码后,这似乎仍然不起作用,现在它给我一个异常101。 我在Firefox上测试过这个功能,它可以工作,但在Google Chrome上它就是不工作,它一直给我一个异常101。我如何让它不仅适用于Firefox,还适用于其他浏览器(尤

  • 问题内容: 我想读取一个包含空格分隔值的文本文件。值是整数。如何读取并将其放入数组列表? 这是文本文件内容的示例: 我想将它包含在arraylist中。如何用Java做到这一点? 问题答案: 你可以用来将文本文件的所有行都放入。 教程:基本文件读取,写入和创建文本文件 你可以用来基于正则表达式拆分部分。 教程:数字和字符串>字符串>操纵字符串中的字符 你可以使用将转换为。 教程:数字和字符串>字符

  • 我是Spring框架的新手,我正在使用Spring做一个简单的项目,但介于两者之间。在我的项目中,我使用Spring Poller从目录中读取文件。然后通过各种通道处理该文件并将其发送到队列。但问题是“file-inbing-channel-适配器”(我正在使用)一次只读取一个文件。所以我需要一个一次读取和处理多个文件的解决方案。有没有办法在Spring集成中实现多线程。谢谢你。