2
votes

I'm trying to create a new ontology and after some actions save it. It's been created well and I have no problem in dealing with classes and other things but when I try to save it to a local file gives me an error! My code is:

//create a new ontology
SOURCE = "http://www.w3.org/2002/07/owl#";
NS = SOURCE + "#";
ontology = ModelFactory.createOntologyModel();
ontology.read( SOURCE, "RDF/XML" );
///////some actions
//save the ontology
try {
        File file= new File("Log.owl");
        ontology.write(new FileOutputStream(file));

    } 
    catch (IOException e) {
        e.printStackTrace();
    }

And the error is:

Exception in thread "main" com.hp.hpl.jena.shared.BadURIException: Only well-formed absolute URIrefs can be included in RDF/XML output: <d> Code: 57/REQUIRED_COMPONENT_MISSING in SCHEME: A component that is required by the scheme is missing.
at com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter.checkURI(BaseXMLWriter.java:829)
at com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter.xmlnsDecl(BaseXMLWriter.java:348)
at com.hp.hpl.jena.xmloutput.impl.Basic.writeRDFHeader(Basic.java:56)
at com.hp.hpl.jena.xmloutput.impl.Basic.writeBody(Basic.java:39)
at com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter.writeXMLBody(BaseXMLWriter.java:500)
at com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter.write(BaseXMLWriter.java:472)
at com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter.write(BaseXMLWriter.java:458)
at com.hp.hpl.jena.rdf.model.impl.ModelCom.write(ModelCom.java:271)
at com.hp.hpl.jena.ontology.impl.OntModelImpl.write(OntModelImpl.java:2552)

I know that the format of "http://www.w3.org/2002/07/owl#" is TURTLE but I'd like to have the ontology in RDF/XML and I don't know what to write instead of that link.I tried different links but each time it gave me another error. Should SOURCE be a real link?

Thaks for any reply !

3

3 Answers

2
votes

Finally, I managed to find the solution! And it was easier than I thought!My problem was in creating the classes. My code was:

ontology.createClass(word);

I had to write:

ontology.createClass(NS+word);

A piece of cake!

1
votes

Try reading as Turtle - the output will be RDF/XML (but you want to use RDF/XML-ABBREV which is neater. Internally it is held as triples, not in some concrete syntax as read.

0
votes

You need to read the ontology using format "TURTLE", not "RDF/XML". You can select a different format when writing, see the Jena Model javadoc for the different versions of the write() method. Choose one where you can specify the output format (lang) and use "RDF/XML-ABBREV" as AndyS says.

The exception is because you used a simple string (apparently "d") in a location where only full absolute URIs are allowed (such as "http://example.com/mydata#d"). Perhaps in a call to createResource()?