forked from ease-crc/soma
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Throwing now an explicit exception when trying to load an online onto…
…logy
- Loading branch information
Showing
2 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
scripts/java/src/main/java/main/GuardingXmlCatalogIriMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main; | ||
|
||
import org.protege.xmlcatalog.CatalogUtilities; | ||
import org.protege.xmlcatalog.XMLCatalog; | ||
import org.protege.xmlcatalog.entry.Entry; | ||
import org.protege.xmlcatalog.redirect.UriRedirectVisitor; | ||
import org.semanticweb.owlapi.model.IRI; | ||
import org.semanticweb.owlapi.model.OWLOntologyIRIMapper; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.MalformedURLException; | ||
import java.net.URI; | ||
import java.util.Iterator; | ||
|
||
public class GuardingXmlCatalogIriMapper implements OWLOntologyIRIMapper { | ||
private XMLCatalog catalog; | ||
|
||
public GuardingXmlCatalogIriMapper(File f) throws MalformedURLException, IOException { | ||
this(CatalogUtilities.parseDocument(f.toURI().toURL())); | ||
} | ||
|
||
public GuardingXmlCatalogIriMapper(XMLCatalog catalog) { | ||
this.catalog = catalog; | ||
} | ||
|
||
public IRI getDocumentIRI(IRI original) { | ||
UriRedirectVisitor visitor = new UriRedirectVisitor(original.toURI()); | ||
|
||
for (Entry subEntry : catalog.getEntries()) { | ||
subEntry.accept(visitor); | ||
if (visitor.getRedirect() != null) { | ||
return IRI.create(visitor.getRedirect()); | ||
} | ||
} | ||
throw new RuntimeException("You are trying to load an ontology from an online source, but we decided to self-host them, e.g, DUL. The ontology you are trying to load is: " + original); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters