OWL2Parser.java revision ebe1b5c42cea5468e66f088648362125cb3c2818
d25c69509848853b0b15b93e3cc180cab81047acChristian Maederimport org.coode.owlapi.owlxml.renderer.OWLXMLRenderer;
d25c69509848853b0b15b93e3cc180cab81047acChristian Maederimport org.coode.owlapi.rdf.rdfxml.RDFXMLRenderer;
2578a6d217296401d347302c9104fee179bd0470Francisc Nicolae Bungiuimport org.semanticweb.owlapi.apibinding.OWLManager;
d25c69509848853b0b15b93e3cc180cab81047acChristian Maederimport org.semanticweb.owlapi.io.OWLRendererException;
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiuimport org.semanticweb.owlapi.util.OWLOntologyMerger;
2578a6d217296401d347302c9104fee179bd0470Francisc Nicolae Bungiuimport uk.ac.manchester.cs.owl.owlapi.mansyntaxrenderer.ManchesterOWLSyntaxRenderer;
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder private static enum OPTION {OWL_XML, MANCHESTER, RDF_XML}
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder private static final List<OWLOntology> loadedImportsList = new ArrayList<OWLOntology>();
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder private static final ArrayList<IRI> importsIRI = new ArrayList<IRI>();
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder private static final Map<OWLOntology, List<OWLOntology>> m = new HashMap<OWLOntology, List<OWLOntology>>();
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder private static final Set<OWLOntology> s = new HashSet<OWLOntology>();
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder private static final Set<OWLOntology> expanded = new HashSet<OWLOntology>();
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder System.out.println("Usage: processor <URI> [FILENAME] <OPTION>");
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder // A simple example of how to load and save an ontology
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder // args[0]: IRI
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder // args[1]: name of output file
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder // args[2]: type of output file: xml, rdf, or otherwise assume Manchester syntax
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder out = new BufferedWriter(new FileWriter(filename));
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder // args[0]: IRI
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder // args[1]: type of output (or output file for Manchester syntax)
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder // xml (OWL XML),
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder // or otherwise use argument as file name for Manchester syntax
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder // for xml and rdf output goes to standard output, i.e. System.out
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder out = new BufferedWriter(new FileWriter(filename));
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder /* Load an ontology from a physical IRI */
ebe1b5c42cea5468e66f088648362125cb3c2818Christian Maeder URLConnection con = physicalUrl.openConnection();
ebe1b5c42cea5468e66f088648362125cb3c2818Christian Maeder con.addRequestProperty("Accept", "text/plain");
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder // System.out.println("IRI: " + physicalIRI + "\n");
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder // Now do the loading
ebe1b5c42cea5468e66f088648362125cb3c2818Christian Maeder OWLOntology ontology = manager.loadOntologyFromOntologyDocument(con.getInputStream());
7418589cbad1760b60beb07909f97e207a71abefChristian Maeder IRI ontIri = ontology.getOntologyID().getOntologyIRI();
7418589cbad1760b60beb07909f97e207a71abefChristian Maeder importsIRI.remove(importsIRI.lastIndexOf(ontIri));
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder if (loadedImportsList.contains(ontology)) {
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder OWLOntologyMerger merger = new OWLOntologyMerger(manager);
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder String str = ontology.getOntologyID().getOntologyIRI().toQuotedString();
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder notag = notag.replaceAll("Ontology\\(", "");
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder loadedImportsList.remove(loadedImportsList.indexOf(ontology));
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder Object aux[] = loadedImportsList.toArray();
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder // System.out.println("NAME: " + merged_name + "\n");
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder IRI mergedOntologyIRI = IRI.create(merged_name);
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder // System.out.println("MERGED_IRI " + mergedOntologyIRI + "\n");
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder OWLOntology merged = merger.createMergedOntology(manager, mergedOntologyIRI);
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder System.err.println("OWL parse error: " + ex.getMessage());
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder private static void getImportsList(OWLOntology ontology, OWLOntologyManager om) {
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder List<OWLOntology> l = new ArrayList<OWLOntology>();
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder ArrayList<OWLOntology> unSavedImports = new ArrayList<OWLOntology>();
7418589cbad1760b60beb07909f97e207a71abefChristian Maeder for (OWLOntology imported : om.getDirectImports(ontology)) {
7418589cbad1760b60beb07909f97e207a71abefChristian Maeder IRI importIri = imported.getOntologyID().getOntologyIRI();
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder System.err.println("Error getImportsList!");
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder private static void parseZeroImports(BufferedWriter out, OWLOntology ontology) {
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder private static void parseImports(BufferedWriter out, OWLOntology ontology) {
54c93d1b5798be42cd4f9b2457b99d36ee8c0b56Christian Maeder for (Map.Entry<OWLOntology, List<OWLOntology>> pairs : m.entrySet()) {
54c93d1b5798be42cd4f9b2457b99d36ee8c0b56Christian Maeder Set<OWLOntology> values = cnvrt(pairs.getValue());
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder if (onto.getOntologyID().toString().equals(ontology.getOntologyID().toString()))
54c93d1b5798be42cd4f9b2457b99d36ee8c0b56Christian Maeder private static Set<OWLOntology> cnvrt(List<OWLOntology> lst) {
54c93d1b5798be42cd4f9b2457b99d36ee8c0b56Christian Maeder Set<OWLOntology> st = new HashSet<OWLOntology>();
54c93d1b5798be42cd4f9b2457b99d36ee8c0b56Christian Maeder private static Boolean checkset(Collection<OWLOntology> it) {
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder Set<OWLOntology> aux = new HashSet<OWLOntology>();
7418589cbad1760b60beb07909f97e207a71abefChristian Maeder private static Boolean equalcollections(Set<OWLOntology> l1) {
7418589cbad1760b60beb07909f97e207a71abefChristian Maeder if (l1.isEmpty() || OWL2Parser.s.isEmpty())
54c93d1b5798be42cd4f9b2457b99d36ee8c0b56Christian Maeder private static List<OWLOntology> getKeysByValue() {
54c93d1b5798be42cd4f9b2457b99d36ee8c0b56Christian Maeder List<OWLOntology> keys = new ArrayList<OWLOntology>();
54c93d1b5798be42cd4f9b2457b99d36ee8c0b56Christian Maeder for (Map.Entry<OWLOntology, List<OWLOntology>> pairs : m.entrySet()) {
72612745c4e86f3395a88b435d26830d8f7f70b3Christian Maeder private static void parsing_option(OWLOntology onto, BufferedWriter out) {
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder private static void parse(OWLOntology onto, BufferedWriter out) {
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder ManchesterOWLSyntaxRenderer rendi = new ManchesterOWLSyntaxRenderer(onto.getOWLOntologyManager());
d25c69509848853b0b15b93e3cc180cab81047acChristian Maeder System.err.println("Error by ManchesterParser!");
72612745c4e86f3395a88b435d26830d8f7f70b3Christian Maeder private static void parse2xml(OWLOntology onto, BufferedWriter out) {
b9a7827caf331ae5b7eb491455d7e647c83f1345Christian Maeder OWLOntologyManager mngr = onto.getOWLOntologyManager();
b9a7827caf331ae5b7eb491455d7e647c83f1345Christian Maeder OWLXMLRenderer ren = new OWLXMLRenderer(mngr);
b9a7827caf331ae5b7eb491455d7e647c83f1345Christian Maeder out.append("<Loaded name=\"" + mngr.getOntologyDocumentIRI(onto)
ebe1b5c42cea5468e66f088648362125cb3c2818Christian Maeder + "\" ontiri=\"" + onto.getOntologyID().getOntologyIRI() + "\"/>\n");
72612745c4e86f3395a88b435d26830d8f7f70b3Christian Maeder private static void parse2rdf(OWLOntology onto, BufferedWriter out) {