File file = folder.newFile("owlapiexamples_saving.owl");
manager.saveOntology(pizzaOntology, IRI.create(file.toURI()));
// By default ontologies are saved in the format from which they were
// loaded. In this case the ontology was loaded from an rdf/xml file We
// can get information about the format of an ontology from its manager
OWLDocumentFormat format = manager.getOntologyFormat(pizzaOntology);
// We can save the ontology in a different format Lets save the ontology
// in owl/xml format
OWLXMLDocumentFormat owlxmlFormat = new OWLXMLDocumentFormat();
// Some ontology formats support prefix names and prefix IRIs. In our
// case we loaded the pizza ontology from an rdf/xml format, which
// supports prefixes. When we save the ontology in the new format we
// will copy the prefixes over so that we have nicely abbreviated IRIs
// in the new ontology document
if (format.isPrefixOWLOntologyFormat()) {
owlxmlFormat.copyPrefixesFrom(format.asPrefixOWLOntologyFormat());
}
manager.saveOntology(pizzaOntology, owlxmlFormat,
IRI.create(file.toURI()));
// We can also dump an ontology to System.out by specifying a different
// OWLOntologyOutputTarget Note that we can write an ontology to a
// stream in a similar way using the StreamOutputTarget class
// OWLOntologyDocumentTarget documentTarget = new
// SystemOutDocumentTarget();
// Try another format - The Manchester OWL Syntax
ManchesterSyntaxDocumentFormat manSyntaxFormat = new ManchesterSyntaxDocumentFormat();
if (format.isPrefixOWLOntologyFormat()) {
manSyntaxFormat
.copyPrefixesFrom(format.asPrefixOWLOntologyFormat());
}
manager.saveOntology(pizzaOntology, manSyntaxFormat,
new StreamDocumentTarget(new ByteArrayOutputStream()));
}