我正在尝试阅读在 Protege 4 上手动设计的本体,以使用 Jena 在 Eclipse 中对其进行更新。现在做简单,我只想从文件中读取本体并将内容打印回控制台。
这是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'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>
如果有人知道这里缺少什么,那就太好了。
感谢您的回复!