OWL2Parser.java revision 478b7abe044f6dcc5bb0db7cd9155ddc1730ed1b
2578a6d217296401d347302c9104fee179bd0470Francisc Nicolae Bungiuimport org.semanticweb.owlapi.apibinding.OWLManager;
2578a6d217296401d347302c9104fee179bd0470Francisc Nicolae Bungiuimport org.semanticweb.owlapi.model.OWLException;
2578a6d217296401d347302c9104fee179bd0470Francisc Nicolae Bungiuimport org.semanticweb.owlapi.model.OWLOntology;
2578a6d217296401d347302c9104fee179bd0470Francisc Nicolae Bungiuimport org.semanticweb.owlapi.model.OWLOntologyManager;
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiuimport org.semanticweb.owlapi.util.OWLOntologyMerger;
2578a6d217296401d347302c9104fee179bd0470Francisc Nicolae Bungiuimport org.semanticweb.owlapi.model.IRI;
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiuimport org.semanticweb.owlapi.model.OWLAxiom;
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiuimport org.semanticweb.owlapi.io.OWLRendererException;
2578a6d217296401d347302c9104fee179bd0470Francisc Nicolae Bungiuimport uk.ac.manchester.cs.owl.owlapi.mansyntaxrenderer.ManchesterOWLSyntaxRenderer;
2578a6d217296401d347302c9104fee179bd0470Francisc Nicolae Bungiuimport uk.ac.manchester.cs.owl.owlapi.mansyntaxrenderer.ManchesterOWLSyntaxObjectRenderer;
2578a6d217296401d347302c9104fee179bd0470Francisc Nicolae Bungiu private static ArrayList<OWLOntology> loadedImportsList = new ArrayList<OWLOntology>();
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu private static ArrayList<IRI> importsIRI = new ArrayList<IRI>();
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu private static ArrayList<OWLOntology> haveImportsList = new ArrayList<OWLOntology>();
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu private static Map m = new HashMap();
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu private static Set s = new HashSet();
2578a6d217296401d347302c9104fee179bd0470Francisc Nicolae Bungiu public static void main(String[] args) {
2578a6d217296401d347302c9104fee179bd0470Francisc Nicolae Bungiu System.out.println("Usage: processor <URI> [FILENAME]");
2578a6d217296401d347302c9104fee179bd0470Francisc Nicolae Bungiu // A simple example of how to load and save an ontology
2578a6d217296401d347302c9104fee179bd0470Francisc Nicolae Bungiu OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
2578a6d217296401d347302c9104fee179bd0470Francisc Nicolae Bungiu out = new BufferedWriter(new FileWriter(filename));
2578a6d217296401d347302c9104fee179bd0470Francisc Nicolae Bungiu out = new BufferedWriter(openForFile(null));
2578a6d217296401d347302c9104fee179bd0470Francisc Nicolae Bungiu /* Load an ontology from a physical IRI */
2578a6d217296401d347302c9104fee179bd0470Francisc Nicolae Bungiu IRI physicalIRI = IRI.create(args[0]);
2578a6d217296401d347302c9104fee179bd0470Francisc Nicolae Bungiu // Now do the loading
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu OWLOntology ontology = manager.loadOntologyFromOntologyDocument(physicalIRI);
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu if(importsIRI.contains(ontology.getOntologyID().getOntologyIRI())) {
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu importsIRI.remove(importsIRI.lastIndexOf(ontology.getOntologyID().getOntologyIRI()));
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu if(loadedImportsList.contains(ontology))
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu Iterator<OWLOntology> itr_onto = loadedImportsList.iterator();
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu Iterator<IRI> itr_iri = importsIRI.iterator();
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu OWLOntologyManager mng = OWLManager.createOWLOntologyManager();
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu OWLOntologyMerger merger = new OWLOntologyMerger(manager);
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu String str = ontology.getOntologyID().getOntologyIRI().toQuotedString();
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu String notag = str.replaceAll("\\<","");
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu notag = notag.replaceAll("http:/","");
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu notag = notag.replaceAll("\\/.*?/","");;
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu notag = notag.replaceAll(".*?/","");;
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu Object aux[] = loadedImportsList.toArray();
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu mrg = mrg.replaceAll("Ontology\\(","");
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu IRI mergedOntologyIRI = IRI.create(merged_name);
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu OWLOntology merged = merger.createMergedOntology(manager, mergedOntologyIRI);
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu ManchesterOWLSyntaxRenderer rendi = new ManchesterOWLSyntaxRenderer (manager);
2578a6d217296401d347302c9104fee179bd0470Francisc Nicolae Bungiu System.err.println("Error: can not build file: " + filename);
2578a6d217296401d347302c9104fee179bd0470Francisc Nicolae Bungiu System.err.println("OWL parse error: " + ex.getMessage());
2578a6d217296401d347302c9104fee179bd0470Francisc Nicolae Bungiu private static void getImportsList(OWLOntology ontology,
2578a6d217296401d347302c9104fee179bd0470Francisc Nicolae Bungiu ArrayList<OWLOntology> unSavedImports = new ArrayList<OWLOntology>();
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu if (om.getImports(ontology).isEmpty()) {
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu for (OWLOntology imported : om.getImports(ontology)) {
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu if (!importsIRI.contains(imported.getOntologyID().getOntologyIRI())) {
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu importsIRI.add(imported.getOntologyID().getOntologyIRI());
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu if(!loadedImportsList.contains(ontology)) {
2578a6d217296401d347302c9104fee179bd0470Francisc Nicolae Bungiu for (OWLOntology onto : unSavedImports) {
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu System.err.println("Error getImportsList!");
2578a6d217296401d347302c9104fee179bd0470Francisc Nicolae Bungiu private static Writer openForFile(String fileName)
2578a6d217296401d347302c9104fee179bd0470Francisc Nicolae Bungiu return new OutputStreamWriter(System.out);
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu private static void parseZeroImports(BufferedWriter out)
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu OWLOntology onto = (OWLOntology)it.next();
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu public static void parseImports(BufferedWriter out)
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu Iterator iter = m.entrySet().iterator();
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu Map.Entry pairs = (Map.Entry)iter.next();
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu OWLOntology onto = (OWLOntology)pairs.getKey();
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu public static Boolean checkset(Object it) {
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu public static Set getKeysByValue(int value) {
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu Iterator it = m.entrySet().iterator();
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu Map.Entry pairs = (Map.Entry)it.next();
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu if(pairs.getValue().equals(value)) {
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu public static void parse(OWLOntology onto, BufferedWriter out) {
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu ManchesterOWLSyntaxRenderer rendi = new ManchesterOWLSyntaxRenderer (onto.getOWLOntologyManager());
478b7abe044f6dcc5bb0db7cd9155ddc1730ed1bFrancisc Nicolae Bungiu System.err.println("Error by parse!");