public static void addIRIMapper(OWLOntologyManager manager) { URL metaprojectURL = MetaprojectVocabulary.class.getClassLoader().getResource("metaproject.owl"); if (metaprojectURL != null) { IRI metaprojectIRI; try { metaprojectIRI = IRI.create(metaprojectURL.toURI()); } catch (URISyntaxException use) { throw new RuntimeException("Unexpected class loader exception", use); } manager.addIRIMapper(new SimpleIRIMapper(IRI.create(NS), metaprojectIRI)); } }
public static void addIRIMappers(OWLOntologyManager manager) { manager.addIRIMapper(new SimpleIRIMapper(IRI.create("http://jamesnaish.wordpress.com/ROREKnowledgeModel.owl"), IRI.create(new File(ONTOLOGY_ROOT, FEB_PATH + File.separator + "ROREKnowledgeModel.owl")))); manager.addIRIMapper(new SimpleIRIMapper(IRI.create("http://jamesnaish.wordpress.com/Model/AutopilotSourceModel.owl"), IRI.create(new File(ONTOLOGY_ROOT, FEB_PATH + File.separator + "AutopilotSourceModel.owl")))); } }
private static void addSWRLAPIOntologies(@NonNull OWLOntology ontology) { List<SimpleIRIMapper> iriMappers = new ArrayList<>(); iriMappers .add(new SimpleIRIMapper(IRI.create("http://www.w3.org/2003/11/swrl#"), resourcePath2IRI("owl/swrl.owl"))); iriMappers .add(new SimpleIRIMapper(IRI.create("http://www.w3.org/2003/11/swrlb#"), resourcePath2IRI("owl/swrlb.owl"))); iriMappers.add(new SimpleIRIMapper(IRI.create("http://swrl.stanford.edu/ontologies/3.3/swrla.owl"), resourcePath2IRI("owl/swrla.owl"))); iriMappers.add(new SimpleIRIMapper(IRI.create("http://swrl.stanford.edu/ontologies/built-ins/3.4/swrlm.owl"), resourcePath2IRI("owl/swrlm.owl"))); iriMappers.add(new SimpleIRIMapper(IRI.create("http://swrl.stanford.edu/ontologies/built-ins/3.3/swrlx.owl"), resourcePath2IRI("owl/swrlx.owl"))); iriMappers.add(new SimpleIRIMapper(IRI.create("http://swrl.stanford.edu/ontologies/built-ins/3.3/temporal.owl"), resourcePath2IRI("owl/temporal.owl"))); iriMappers.add(new SimpleIRIMapper(IRI.create("http://sqwrl.stanford.edu/ontologies/built-ins/3.4/sqwrl.owl"), resourcePath2IRI("owl/sqwrl.owl"))); for (SimpleIRIMapper iriMapper : iriMappers) ontology.getOWLOntologyManager().getIRIMappers().add(iriMapper); }
public OWLOntology createNewOntology(OWLOntologyID ontologyID, URI physicalURI) throws OWLOntologyCreationException { manager.addIRIMapper(new SimpleIRIMapper(ontologyID.getDefaultDocumentIRI(), IRI.create(physicalURI))); OWLOntology ont = manager.createOntology(ontologyID); dirtyOntologies.add(ont); setActiveOntology(ont); if (physicalURI != null) { try { File containingDirectory = new File(physicalURI).getParentFile(); if (containingDirectory.exists()) { getOntologyCatalogManager().addFolder(containingDirectory); } } catch (IllegalArgumentException iae) { logger.info("Cannot generate ontology catalog for ontology at " + physicalURI); } } fireEvent(EventType.ONTOLOGY_CREATED); return ont; }
private OWLOntology createFreshProjectOntology(OWLOntologyManager manager) throws OWLOntologyCreationException, OWLOntologyStorageException { logger.info("Creating a fresh project with an Id of {}", projectId); File parentDirectory = rootOntologyDocument.getParentFile(); parentDirectory.mkdirs(); IRI ontologyIRI = createUniqueOntologyIRI(); IRI documentIRI = IRI.create(rootOntologyDocument); SimpleIRIMapper mapper = new SimpleIRIMapper(ontologyIRI, documentIRI); manager.getIRIMappers().add(mapper); OWLOntology ontology = manager.createOntology(ontologyIRI); manager.getIRIMappers().remove(mapper); writeNewProject(manager, ontology); return ontology; }
public OWLOntology createNewOntology(OWLOntologyID ontologyID, URI physicalURI) throws OWLOntologyCreationException { if(physicalURI != null && ontologyID.getDefaultDocumentIRI().isPresent()) { manager .getIRIMappers() .add(new SimpleIRIMapper(ontologyID.getDefaultDocumentIRI().get(), IRI.create(physicalURI))); } OWLOntology ont = manager.createOntology(ontologyID); setActiveOntology(ont); if(physicalURI != null) { try { File containingDirectory = new File(physicalURI).getParentFile(); if(containingDirectory.exists()) { getOntologyCatalogManager().addFolder(containingDirectory); } } catch(IllegalArgumentException iae) { logger.info("Cannot generate ontology catalog for ontology at {}. {}", physicalURI, iae.getMessage()); } } fireEvent(EventType.ONTOLOGY_CREATED); return ont; }
public OWLOntology createNewOntology(OWLOntologyID ontologyID, URI physicalURI) throws OWLOntologyCreationException { if (physicalURI != null && ontologyID.getDefaultDocumentIRI().isPresent()) { manager.getIRIMappers().add(new SimpleIRIMapper(ontologyID.getDefaultDocumentIRI().get(), IRI.create(physicalURI))); } OWLOntology ont = manager.createOntology(ontologyID); setActiveOntology(ont); if (physicalURI != null) { try { File containingDirectory = new File(physicalURI).getParentFile(); if (containingDirectory.exists()) { getOntologyCatalogManager().addFolder(containingDirectory); } } catch (IllegalArgumentException iae) { logger.warn("Cannot generate ontology catalog for ontology at " + physicalURI); } } fireEvent(EventType.ONTOLOGY_CREATED); return ont; }
public OWLAPIOntologyCollector(String ontologyIRI, String physicalIRI){ this.ontologyIRI = IRI.create(ontologyIRI); this.physicalIRI = IRI.create(new File(physicalIRI)); SimpleIRIMapper mapper = new SimpleIRIMapper(this.ontologyIRI, this.physicalIRI); this.manager.getIRIMappers().add(mapper); try{ this.currentOntology = manager.createOntology(this.ontologyIRI); }catch(OWLOntologyCreationException e){ logger.error("FATAL failed to create Ontology " + this.ontologyIRI); e.printStackTrace(); } this.factory = manager.getOWLDataFactory(); }
public OWLOntology createNewOntology(OWLOntologyID ontologyID, URI physicalURI) throws OWLOntologyCreationException { if (physicalURI != null) { manager.addIRIMapper(new SimpleIRIMapper(ontologyID.getDefaultDocumentIRI(), IRI.create(physicalURI))); } OWLOntology ont = manager.createOntology(ontologyID); setActiveOntology(ont); if (physicalURI != null) { try { File containingDirectory = new File(physicalURI).getParentFile(); if (containingDirectory.exists()) { getOntologyCatalogManager().addFolder(containingDirectory); } } catch (IllegalArgumentException iae) { logger.info("Cannot generate ontology catalog for ontology at " + physicalURI); } } fireEvent(EventType.ONTOLOGY_CREATED); return ont; }
/** * A convenience method that loads an ontology from a file * The location of the file is specified by the URI argument. */ public boolean loadOntologyFromPhysicalURI(URI uri) { if (uri.getScheme() != null && uri.getScheme().equals("file")) { // Load the URIs of other ontologies that are contained in the same folder. addRootFolder(new File(uri).getParentFile()); } OWLOntology ontology = null; try { ontology = manager.loadOntologyFromOntologyDocument(IRI.create(uri)); setActiveOntology(ontology); fireEvent(EventType.ONTOLOGY_LOADED); OWLOntologyID id = ontology.getOntologyID(); if (!id.isAnonymous()) { manager.addIRIMapper(new SimpleIRIMapper(id.getDefaultDocumentIRI(), IRI.create(uri))); } } catch (OWLOntologyCreationException ooce) { ; // will be handled by the loadErrorHandler, so ignore } return ontology != null; }
private void addImportMapping(OWLOntology ontology, IRI importLocation, IRI physicalLocation) { OWLOntologyManager manager = ontology.getOWLOntologyManager(); manager.getIRIMappers().add(new SimpleIRIMapper(importLocation, physicalLocation)); IRI importersDocumentLocation = manager.getOntologyDocumentIRI(ontology); if (UIUtil.isLocalFile(importersDocumentLocation.toURI())) { File f = new File(importersDocumentLocation.toURI()); XMLCatalog catalog = editorKit.getModelManager().addRootFolder(f.getParentFile()); URI physicalUri = CatalogUtilities.relativize(physicalLocation.toURI(), catalog); catalog.addEntry(0, new UriEntry("Imports Wizard Entry", catalog, importLocation.toURI().toString(), physicalUri, null)); try { CatalogUtilities.save(catalog, OntologyCatalogManager.getCatalogFile(f.getParentFile())); } catch (IOException e) { logger.warn("An error occurred whilst saving the catalog file: {}", e); } } }
private void addImportMapping(OWLOntology ontology, IRI importLocation, IRI physicalLocation) { OWLOntologyManager manager = ontology.getOWLOntologyManager(); manager.getIRIMappers().add(new SimpleIRIMapper(importLocation, physicalLocation)); IRI importersDocumentLocation = manager.getOntologyDocumentIRI(ontology); if (UIUtil.isLocalFile(importersDocumentLocation.toURI())) { File f = new File(importersDocumentLocation.toURI()); XMLCatalog catalog = editorKit.getModelManager().addRootFolder(f.getParentFile()); URI physicalUri = CatalogUtilities.relativize(physicalLocation.toURI(), catalog); catalog.addEntry(0, new UriEntry("Imports Wizard Entry", catalog, importLocation.toURI().toString(), physicalUri, null)); try { CatalogUtilities.save(catalog, OntologyCatalogManager.getCatalogFile(f.getParentFile())); } catch (IOException e) { logger.warn("An error occurred whilst saving the catalog file: {}", e); } } }
/** * A convenience method that loads an ontology from a file * The location of the file is specified by the URI argument. */ public boolean loadOntologyFromPhysicalURI(URI uri) { if (UIUtil.isLocalFile(uri)) { // Load the URIs of other ontologies that are contained in the same folder. File parentFile = new File(uri).getParentFile(); logger.info("Adding root folder: " + parentFile + " ..."); addRootFolder(parentFile); logger.info("\t...done"); } OWLOntology ontology = null; try { ontology = manager.loadOntologyFromOntologyDocument(IRI.create(uri)); setActiveOntology(ontology); fireEvent(EventType.ONTOLOGY_LOADED); OWLOntologyID id = ontology.getOntologyID(); if (!id.isAnonymous()) { manager.addIRIMapper(new SimpleIRIMapper(id.getDefaultDocumentIRI(), IRI.create(uri))); } } catch (OWLOntologyCreationException ooce) { ; // will be handled by the loadErrorHandler, so ignore } return ontology != null; }
private void addImportMapping(OWLOntology ontology, IRI importLocation, IRI physicalLocation) { OWLOntologyManager manager = ontology.getOWLOntologyManager(); manager.addIRIMapper(new SimpleIRIMapper(importLocation, physicalLocation)); try { IRI importersDocumentLocation = manager.getOntologyDocumentIRI(ontology); if (importersDocumentLocation.getScheme().equals("file")) { File f = new File(importersDocumentLocation.toURI()); XMLCatalog catalog = eKit.getModelManager().addRootFolder(f.getParentFile()); URI physicalUri = CatalogUtilities.relativize(physicalLocation.toURI(), catalog); catalog.addEntry(0, new UriEntry("Imports Wizard Entry", catalog, importLocation.toURI().toString(), physicalUri, null)); CatalogUtilities.save(catalog, OntologyCatalogManager.getCatalogFile(f.getParentFile())); } } catch (Throwable t) { ProtegeApplication.getErrorLog().logError(t); } }
private void createDebuggingOntology() throws OWLException { //System.out.println("Debugging ontology: " + ontologyCounter); if (debuggingOntology != null) { owlOntologyManager.removeOntology(debuggingOntology); } IRI iri = createIRI(); SimpleIRIMapper mapper = new SimpleIRIMapper(iri, iri); owlOntologyManager.addIRIMapper(mapper); debuggingOntology = owlOntologyManager.createOntology(iri); owlOntologyManager.removeIRIMapper(mapper); List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>(); for (OWLAxiom ax : debuggingAxioms) { changes.add(new AddAxiom(debuggingOntology, ax)); } for (OWLAxiom ax : temporaryAxioms) { changes.add(new AddAxiom(debuggingOntology, ax)); } // Ensure the ontology contains the signature of the class which is being debugged OWLDataFactory factory = owlOntologyManager.getOWLDataFactory(); OWLAxiom ax = factory.getOWLSubClassOfAxiom(currentClass, factory.getOWLThing()); changes.add(new AddAxiom(debuggingOntology, ax)); owlOntologyManager.applyChanges(changes); }
protected void doInitialization() throws OWLOntologyCreationException { // init owl fields this.manager = OWLManager.createOWLOntologyManager(); if (getOntologyResource() != null) { getLog().info("Mapping ontology IRI from {} to {}", getOntologyIRI(), getOntologyResource()); this.manager.addIRIMapper(new SimpleIRIMapper(getOntologyIRI(), IRI.create(getOntologyResource()))); } if (getOntologyImportMappings() != null) { for (IRI from : getOntologyImportMappings().keySet()) { IRI to = getOntologyImportMappings().get(from); getLog().info("Mapping imported ontology IRI from " + from + " to " + to); this.manager.addIRIMapper(new SimpleIRIMapper(from, to)); } } this.factory = manager.getOWLDataFactory(); // collect things we want to ignore form OWL vocab owlVocabulary.add(factory.getOWLThing().getIRI()); owlVocabulary.add(factory.getOWLNothing().getIRI()); owlVocabulary.add(factory.getOWLTopObjectProperty().getIRI()); owlVocabulary.add(factory.getOWLBottomObjectProperty().getIRI()); // load the ontology this.ontology = loadOntology(); }
private void createDebuggingOntology() { if (debuggingOntology != null) { man.removeOntology(verifyNotNull(debuggingOntology)); } IRI iri = createIRI(); SimpleIRIMapper mapper = new SimpleIRIMapper(iri, iri); man.getIRIMappers().add(mapper); try { debuggingOntology = man.createOntology(iri); } catch (OWLOntologyCreationException e) { throw new OWLRuntimeException(e); } man.getIRIMappers().remove(mapper); List<AddAxiom> changes = new ArrayList<>(); debuggingAxioms.forEach(ax -> changes.add(new AddAxiom(getDebuggingOntology(), ax))); temporaryAxioms.forEach(ax -> changes.add(new AddAxiom(getDebuggingOntology(), ax))); // Ensure the ontology contains the signature of the class which is // being debugged OWLAxiom ax = df.getOWLSubClassOfAxiom(verifyNotNull(currentClass), df.getOWLThing()); changes.add(new AddAxiom(getDebuggingOntology(), ax)); man.applyChanges(changes); }
private void createDebuggingOntology() { if (debuggingOntology != null) { man.removeOntology(verifyNotNull(debuggingOntology)); } IRI iri = createIRI(); SimpleIRIMapper mapper = new SimpleIRIMapper(iri, iri); man.getIRIMappers().add(mapper); try { debuggingOntology = man.createOntology(iri); } catch (OWLOntologyCreationException e) { throw new OWLRuntimeException(e); } man.getIRIMappers().remove(mapper); List<AddAxiom> changes = new ArrayList<>(); debuggingAxioms.forEach(ax -> changes.add(new AddAxiom(getDebuggingOntology(), ax))); temporaryAxioms.forEach(ax -> changes.add(new AddAxiom(getDebuggingOntology(), ax))); // Ensure the ontology contains the signature of the class which is // being debugged OWLAxiom ax = df.getOWLSubClassOfAxiom(verifyNotNull(currentClass), df.getOWLThing()); changes.add(new AddAxiom(getDebuggingOntology(), ax)); man.applyChanges(changes); }
private void createDebuggingOntology() { if (debuggingOntology != null) { man.removeOntology(verifyNotNull(debuggingOntology)); } IRI iri = createIRI(); SimpleIRIMapper mapper = new SimpleIRIMapper(iri, iri); man.getIRIMappers().add(mapper); try { debuggingOntology = man.createOntology(iri); } catch (OWLOntologyCreationException e) { throw new OWLRuntimeException(e); } man.getIRIMappers().remove(mapper); List<AddAxiom> changes = new ArrayList<>(); debuggingAxioms.forEach(ax -> changes.add(new AddAxiom(getDebuggingOntology(), ax))); temporaryAxioms.forEach(ax -> changes.add(new AddAxiom(getDebuggingOntology(), ax))); // Ensure the ontology contains the signature of the class which is // being debugged OWLAxiom ax = df.getOWLSubClassOfAxiom(verifyNotNull(currentClass), df.getOWLThing()); changes.add(new AddAxiom(getDebuggingOntology(), ax)); man.applyChanges(changes); }
private void createDebuggingOntology() { if (debuggingOntology != null) { man.removeOntology(verifyNotNull(debuggingOntology)); } IRI iri = createIRI(); SimpleIRIMapper mapper = new SimpleIRIMapper(iri, iri); man.getIRIMappers().add(mapper); try { debuggingOntology = man.createOntology(iri); } catch (OWLOntologyCreationException e) { throw new OWLRuntimeException(e); } man.getIRIMappers().remove(mapper); List<AddAxiom> changes = new ArrayList<>(); debuggingAxioms.forEach(ax -> changes.add(new AddAxiom(getDebuggingOntology(), ax))); temporaryAxioms.forEach(ax -> changes.add(new AddAxiom(getDebuggingOntology(), ax))); // Ensure the ontology contains the signature of the class which is // being debugged OWLAxiom ax = df.getOWLSubClassOfAxiom(verifyNotNull(currentClass), df.getOWLThing()); changes.add(new AddAxiom(getDebuggingOntology(), ax)); man.applyChanges(changes); }