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

时间:2012-06-13 10:42:52

标签: jena ontology

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

这是java 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 个答案:

答案 0 :(得分:4)

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

您应该能够从protege输出OWL RDF,或使用this online tool进行转换。