@Override public OWLOntologyIRIMapper getOntologyIRIMapper() { return new AutoIRIMapper(baseDirectory, true); }
public static List<OWLOntologyIRIMapper> getMappers(IRI[] dirs) { List<OWLOntologyIRIMapper> mappers = new ArrayList<OWLOntologyIRIMapper>(); if (dirs != null) { for (IRI path : dirs) { File dir = null; try { dir = new File(path.toURI()); } catch (Exception e) { // Keep dir null } if (dir != null) { if (dir.isDirectory()) mappers.add(new AutoIRIMapper(dir, true)); // We might want to construct other IRI mappers for regular files in the future... } } } return mappers; }
/** * Given a URI of an owl file returns the * translated OWLOntology object * @param tboxFile - the URI of the file * @return the translated OWLOntology * @throws Exception */ private OWLOntology getOntologyFromFile(URI tboxFile) throws Exception{ //get owl ontology from file OWLOntologyIRIMapper iriMapper = new AutoIRIMapper(new File(tboxFile).getParentFile(), false); man.addIRIMapper(iriMapper); OWLOntology owlontology = man.loadOntologyFromOntologyDocument(new File(tboxFile)); return owlontology; }
private Ontology readOntology(String tboxFile) throws Exception { File f = new File(tboxFile); OWLOntologyIRIMapper iriMapper = new AutoIRIMapper(f.getParentFile(), false); man.addIRIMapper(iriMapper); OWLOntology owlontology = null; if (tboxFile.contains("file:")) { owlontology = man.loadOntologyFromOntologyDocument(new URL(tboxFile).openStream()); } else { owlontology = man.loadOntologyFromOntologyDocument(new File(tboxFile)); } closure = man.getImportsClosure(owlontology); return OWLAPITranslatorUtility.mergeTranslateOntologies(closure); }
public static OWLOntology loadOntology(String fileName) { AutoIRIMapper mapper = new AutoIRIMapper(new File(fileName.substring(0, fileName.lastIndexOf('/'))), false); OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); manager.addIRIMapper(mapper); //System.out.println(mapper.getDocumentIRI(IRI.create("http://semantics.crl.ibm.com/univ-bench-dl.owl"))); OWLOntology ontology = null; try { ontology = manager.loadOntologyFromOntologyDocument(new File(fileName)); } catch (OWLOntologyCreationException e) { e.printStackTrace(); } // manager.removeIRIMapper(mapper); return ontology; }
/** * Load OWL files from given directory and in its subdirectories, using a prefix * mapper to resolve URLs internally and deriving ontology names from the relative * paths. This uses the resolver passed at initialization only to create the * namespace. It's only meant for core knowledge not seen by users. * * @param kdir * @throws KlabIOException */ public void load(File kdir) throws KlabException { AutoIRIMapper imap = new AutoIRIMapper(kdir, true); manager.addIRIMapper(imap); File[] files = kdir.listFiles(); // null in error if (files != null) { for (File fl : files) { loadInternal(fl, "", null); } } else { throw new KlabIOException("Errors reading core ontologies: system will be nonfunctional. Check server distribution."); } }
/** * Creates a new parent path ontology input source. If the developer wishes to recycle an * {@link OWLOntologyManager} (e.g. in order to keep the active IRI mappers attached to it), they can do * so by passing it to the method. Please note that recycling ontology managers will increase the * likelihood of {@link OWLOntologyAlreadyExistsException}s being thrown. * * @param rootFile * the root ontology file. Must not be a directory. * @param mgr * the ontology manager to recycle. Note that an {@link AutoIRIMapper} will be added to it. * @throws OWLOntologyCreationException * if <code>rootFile</code> does not exist, is not an ontology or one of its imports failed to * load. */ public ParentPathInputSource(File rootFile, OWLOntologyManager mgr) throws OWLOntologyCreationException { // Directories are not allowed if (rootFile.isDirectory()) throw new IllegalArgumentException( "Could not determine root ontology : file " + rootFile + " is a directory. Only regular files are allowed."); AutoIRIMapper mapper = new AutoIRIMapper(rootFile.getParentFile(), true); mgr.addIRIMapper(mapper); bindRootOntology(mgr.loadOntologyFromOntologyDocument(rootFile)); // TODO : do we really want this to happen? bindPhysicalIri(IRI.create(rootFile)); bindTriplesProvider(mgr); }
new AutoIRIMapper( ontFilePath.getParent().toAbsolutePath().normalize().toFile(), true
/** * Creates a new parent path ontology input source. If the developer wishes to recycle an * {@link OWLOntologyManager} (e.g. in order to keep the active IRI mappers attached to it), they can do * so by passing it to the method. Please note that recycling ontology managers will increase the * likelihood of {@link OWLOntologyAlreadyExistsException}s being thrown. * * @param rootFile * the root ontology file. Must not be a directory. * @param mgr * the ontology manager to recycle. Note that an {@link AutoIRIMapper} will be added to it. * @throws OWLOntologyCreationException * if <code>rootFile</code> does not exist, is not an ontology or one of its imports failed to * load. */ public ParentPathInputSource(File rootFile, OWLOntologyManager mgr) throws OWLOntologyCreationException { // Directories are not allowed if (rootFile.isDirectory()) throw new IllegalArgumentException( "Could not determine root ontology : file " + rootFile + " is a directory. Only regular files are allowed."); AutoIRIMapper mapper = new AutoIRIMapper(rootFile.getParentFile(), true); mgr.addIRIMapper(mapper); bindRootOntology(mgr.loadOntologyFromOntologyDocument(rootFile)); // TODO : do we really want this to happen? bindPhysicalOrigin(Origin.create(IRI.create(rootFile))); }
/** * Creates a new parent path ontology input source. If the developer wishes to recycle an * {@link OWLOntologyManager} (e.g. in order to keep the active IRI mappers attached to it), they can do * so by passing it to the method. Please note that recycling ontology managers will increase the * likelihood of {@link OWLOntologyAlreadyExistsException}s being thrown. * * @param rootFile * the root ontology file. Must not be a directory. * @param mgr * the ontology manager to recycle. Note that an {@link AutoIRIMapper} will be added to it. * @throws OWLOntologyCreationException * if <code>rootFile</code> does not exist, is not an ontology or one of its imports failed to * load. */ public ParentPathInputSource(File rootFile, OWLOntologyManager mgr) throws OWLOntologyCreationException { // Directories are not allowed if (rootFile.isDirectory()) throw new IllegalArgumentException( "Could not determine root ontology : file " + rootFile + " is a directory. Only regular files are allowed."); AutoIRIMapper mapper = new AutoIRIMapper(rootFile.getParentFile(), true); mgr.addIRIMapper(mapper); bindRootOntology(mgr.loadOntologyFromOntologyDocument(rootFile)); // TODO : do we really want this to happen? bindPhysicalOrigin(Origin.create(IRI.create(rootFile))); }
File file=new File(URI.create(ont.getNamespace())); if (file.isDirectory()) { OWLOntologyIRIMapper mapper=new AutoIRIMapper(file, false); ontologyManager.getIRIMappers().add(mapper);