OWL2Parser.java revision c50adef8a083be353c6f07af011359ed16a98d15
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartreimport org.coode.owlapi.owlxml.renderer.OWLXMLRenderer;
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartreimport org.coode.owlapi.rdf.rdfxml.RDFXMLRenderer;
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartreimport org.semanticweb.owlapi.apibinding.OWLManager;
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartreimport org.semanticweb.owlapi.io.OWLRendererException;
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartreimport org.semanticweb.owlapi.io.StreamDocumentSource;
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartreimport org.semanticweb.owlapi.util.OWLOntologyMerger;
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartreimport uk.ac.manchester.cs.owl.owlapi.mansyntaxrenderer.ManchesterOWLSyntaxRenderer;
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre private static enum OPTION {OWL_XML, MANCHESTER, RDF_XML}
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre private static Set<OWLOntology> ontologies;
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre private static final Set<OWLOntology> exported = new HashSet<OWLOntology>();
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre private static final OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre System.out.println("Usage: processor <URI> [FILENAME] <OPTION>");
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre // A simple example of how to load and save an ontology
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre // args[0]: IRI
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre // args[1]: name of output file
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre // args[2]: type of output file: xml, rdf, or otherwise assume Manchester syntax
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre out = new BufferedWriter(new FileWriter(filename));
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre // args[0]: IRI
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre // args[1]: type of output (or output file for Manchester syntax)
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre // xml (OWL XML),
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre // or otherwise use argument as file name for Manchester syntax
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre // for xml and rdf output goes to standard output, i.e. System.out
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre out = new BufferedWriter(new FileWriter(filename));
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre /* Load an ontology from a physical IRI */
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre URLConnection con = physicalUrl.openConnection();
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre con.addRequestProperty("Accept", "text/plain");
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre StreamDocumentSource sds = new StreamDocumentSource(con.getInputStream());
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre OWLOntologyLoaderConfiguration config = new OWLOntologyLoaderConfiguration();
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre config = config.setMissingImportHandlingStrategy(MissingImportHandlingStrategy.SILENT);
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre OWLOntology ontology = manager.loadOntologyFromOntologyDocument(sds, config);
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre ontologies = getImports(ontology, new HashSet<OWLOntology>());
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre OWLOntologyMerger merger = new OWLOntologyMerger(manager);
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre String str = ontology.getOntologyID().getOntologyIRI().toString();
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre String mrg = aux_ont.getOntologyID().getOntologyIRI().toString();
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre // System.out.println("NAME: " + merged_name + "\n");
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre IRI mergedOntologyIRI = IRI.create(merged_name);
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre // System.out.println("MERGED_IRI " + mergedOntologyIRI + "\n");
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre OWLOntology merged = merger.createMergedOntology(manager, mergedOntologyIRI);
s.addAll(i);
changed = false;
} while (changed);
switch (op) {
case OWL_XML:
case MANCHESTER:
case RDF_XML: